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
558 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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

832 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