?
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
?
562 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: 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!

 

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

719 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