Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How do I request a specific number of rows from a data table for a chart in Visual Studio 2010.

Posted on 2011-02-22
6
Medium Priority
?
563 Views
Last Modified: 2012-05-11
I am trying to build a chart using a data table.  The top 4 rows of the table, I would like to make stacked columns.  The 5th row, I want to make a marker on top of the stacked column and the 6th row, I want to make a line on the chart.

All I seem to be able to do is make all the rows stacked columns!  I can't even seem to figure out how to just pluck out the first four rows.  HELP!

Here is one of the many series of code I have been trying:

Try

            Dim columnCount = dTable.Columns.Count - 1
            Dim rowCount = dTable.Rows.Count - 1

            For dC As Integer = 1 To columnCount - 1

                Dim colHeader As String = dTable.Columns(dC).ColumnName
                Me.chtHealth.Series.Add(colHeader)
                Me.chtHealth.Series(colHeader).XValueType = DataVisualization.Charting.ChartValueType.String
                Me.chtHealth.Series(colHeader).YValueType = DataVisualization.Charting.ChartValueType.Double

                For dR As Integer = 0 To rowCount - 2
                    Me.chtHealth.Series(colHeader).XValueMember = "Well ID" ' I just want the first freaking 4 rows on the chart!!!!!!!  
                    Me.chtHealth.Series(colHeader).YValueMembers = colHeader
                    Me.chtHealth.Series(colHeader).ToolTip = "#VALX:  #VALY{N2}"
                    Me.chtHealth.Series(colHeader).CustomProperties = "DrawingStyle=Emboss"
                    Me.chtHealth.Series(colHeader).ChartType = SeriesChartType.StackedColumn
                Next dR

            Next dC

            Me.chtHealth.Visible = True

        Catch ex As Exception
            MessageBox.Show(ex.Message, ex.GetType.ToString)

        End Try

Good Karma to the person that can solve this mystery!!
Thanks.
0
Comment
Question by:Karen Wilson
  • 4
6 Comments
 
LVL 2

Expert Comment

by:jondow
ID: 34951913
The following will get you the first 4 rows:

Regards

Rick
Dim dt As New System.Data.DataTable

        Dim dr As System.Data.DataRow

        For i As Integer = 0 To 3
            dr = dt.Rows(i)
            'Get the item from the datarow where "1" is the column index
            Dim x As String = dr.Item(1).ToString
        Next

Open in new window

0
 
LVL 10

Expert Comment

by:P1ST0LPETE
ID: 34951940
Separating the data:

        Dim table As New DataTable
        'Populate the data table here...

        Dim fourRows As DataTable
        fourRows = table.Clone() 'Copies the table schema of the source

        'Separate the first 4 rows into a separate table:
        For i As Integer = 0 To 3
            fourRows.Rows.Add(table.Rows(i))
        Next i

        Dim markerRow As DataTable
        markerRow = table.Clone
        markerRow.Rows.Add(table.Rows(4))

        Dim lineRow As DataTable
        lineRow = table.Clone
        lineRow.Rows.Add(table.Rows(5))
0
 

Author Comment

by:Karen Wilson
ID: 34953678
I tried both ways and a variation of both and it won't get past the section of

 For i As Integer = 0 To 3
            fourRows.Rows.Add(table.Rows(i))
        Next i

ERROR MESSAGE:  This row already belongs to another table

or
For i As Integer = 0 To 3
            dr = dt.Rows(i)
            'Get the item from the datarow where "1" is the column index
            Dim x As String = dr.Item(1).ToString
        Next
ERROR MESSAGE:  There is no row at position 0


0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:Karen Wilson
ID: 34953980
Dim fourRows As New DataTable
            fourRows = dTable.Clone

            For i As Integer = 0 To 3
                fourRows.ImportRow(dTable.Rows(i))
            Next i

I searched around the internet and found this and it works!!  It's "importRow"

Now that I have segregated the data, do either of you know how to use segregated data tables for a chart?

0
 

Accepted Solution

by:
Karen Wilson earned 0 total points
ID: 35232648
Dim fourRows As DataTable
        fourRows = dTable.Clone

        For i As Integer = 0 To 3
            fourRows.ImportRow(dTable.Rows(i))
        Next i


        Me.chtHealth.Series.Clear()
        Me.chtHealth.DataSource = fourRows
        Me.chtHealth.DataBind()

        Try
            Dim columnCount = fourRows.Columns.Count - 1
            Me.chtHealth.Series.Clear()
            Me.chtHealth.ChartAreas("ChartArea1").IsSameFontSizeForAllAxes = True


            Dim lastColumn As Integer = fourRows.Columns.Count

            For dC As Integer = 1 To columnCount - 2

                Dim colHeader As String = fourRows.Columns(dC).ColumnName
                Me.chtHealth.Series.Add(colHeader)
                Me.chtHealth.Series(colHeader).ChartType = SeriesChartType.StackedColumn
                Me.chtHealth.Series(colHeader).BorderColor = Color.Black
                Me.chtHealth.Series(colHeader).BorderWidth = 1
                Me.chtHealth.Series(colHeader).XValueType = DataVisualization.Charting.ChartValueType.String
                Me.chtHealth.Series(colHeader).YValueType = DataVisualization.Charting.ChartValueType.Double
                Me.chtHealth.Series(colHeader).XValueMember = "Well Id"
                Me.chtHealth.Series(colHeader).YValueMembers = colHeader
                Me.chtHealth.Series(colHeader).ToolTip = "#VALX:  #VALY{N2}"
                Me.chtHealth.Series(colHeader).CustomProperties = "DrawingStyle=Cylinder"
            Next


            Dim totHeader As String = fourRows.Columns(lastColumn - 2).ColumnName
            Me.chtHealth.Series.Add(totHeader)
            Me.chtHealth.Series(totHeader).ChartType = SeriesChartType.Line
            Me.chtHealth.Series(totHeader).BorderWidth = 0
            Me.chtHealth.Series(totHeader).MarkerStyle = MarkerStyle.Diamond
            Me.chtHealth.Series(totHeader).MarkerColor = Color.Red
            Me.chtHealth.Series(totHeader).MarkerSize = 8
            Me.chtHealth.Series(totHeader).MarkerBorderColor = Color.Black

            Me.chtHealth.Series(totHeader).XValueType = DataVisualization.Charting.ChartValueType.String
            Me.chtHealth.Series(totHeader).YValueType = DataVisualization.Charting.ChartValueType.Double
            Me.chtHealth.Series(totHeader).XValueMember = "Well Id"
            Me.chtHealth.Series(totHeader).YValueMembers = totHeader
            Me.chtHealth.Series(totHeader).ToolTip = "#VALX:  #VALY{N2}"

            Dim cumHeader As String = fourRows.Columns(lastColumn - 1).ColumnName
            Me.chtHealth.Series.Add(cumHeader)
            Me.chtHealth.Series(cumHeader).ChartType = SeriesChartType.Line
            Me.chtHealth.Series(cumHeader).BorderWidth = 4
            Me.chtHealth.Series(cumHeader).MarkerStyle = MarkerStyle.Circle
            Me.chtHealth.Series(cumHeader).MarkerColor = Color.Yellow
            Me.chtHealth.Series(cumHeader).MarkerBorderColor = Color.Black
            Me.chtHealth.Series(cumHeader).XValueType = DataVisualization.Charting.ChartValueType.String
            Me.chtHealth.Series(cumHeader).YValueType = DataVisualization.Charting.ChartValueType.Double
            Me.chtHealth.Series(cumHeader).XValueMember = "Well Id"
            Me.chtHealth.Series(cumHeader).YValueMembers = cumHeader
            Me.chtHealth.Series(cumHeader).ToolTip = "#VALX:  #VALY{N2}"
            Me.chtHealth.Series(cumHeader).Label = "#VALY{N2}"
            Me.chtHealth.Series(cumHeader).LabelForeColor = Color.White


            Me.chtHealth.Titles("Title2").Text = ("Date Range Between: ") & CStr(pckrStartDate.Text) & " and " & CStr(pckrEndDate.Text)
            Me.chtHealth.Visible = True
            Me.chtGalDate.Titles("Title2").Text = ("Date Range Between: ") & CStr(pckrStartDate.Text) & " and " & CStr(pckrEndDate.Text)
            Me.chtGalDate.Visible = True

        Catch ex As Exception
            MessageBox.Show(ex.Message, ex.GetType.ToString)

        End Try
0
 

Author Closing Comment

by:Karen Wilson
ID: 35304251
I figured out the import rows and the solution for my chart.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Integration Management Part 2
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question