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
556 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 

Author Comment

by:Karen Wilson
Comment Utility
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
Comment Utility
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
Comment Utility
I figured out the import rows and the solution for my chart.
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

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…
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…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

743 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now