Karen Wilson
asked on
How do I request a specific number of rows from a data table for a chart in Visual Studio 2010.
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).ColumnN ame
Me.chtHealth.Series.Add(co lHeader)
Me.chtHealth.Series(colHea der).XValu eType = DataVisualization.Charting .ChartValu eType.Stri ng
Me.chtHealth.Series(colHea der).YValu eType = DataVisualization.Charting .ChartValu eType.Doub le
For dR As Integer = 0 To rowCount - 2
Me.chtHealth.Series(colHea der).XValu eMember = "Well ID" ' I just want the first freaking 4 rows on the chart!!!!!!!
Me.chtHealth.Series(colHea der).YValu eMembers = colHeader
Me.chtHealth.Series(colHea der).ToolT ip = "#VALX: #VALY{N2}"
Me.chtHealth.Series(colHea der).Custo mPropertie s = "DrawingStyle=Emboss"
Me.chtHealth.Series(colHea der).Chart Type = SeriesChartType.StackedCol umn
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.
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).ColumnN
Me.chtHealth.Series.Add(co
Me.chtHealth.Series(colHea
Me.chtHealth.Series(colHea
For dR As Integer = 0 To rowCount - 2
Me.chtHealth.Series(colHea
Me.chtHealth.Series(colHea
Me.chtHealth.Series(colHea
Me.chtHealth.Series(colHea
Me.chtHealth.Series(colHea
Next dR
Next dC
Me.chtHealth.Visible = True
Catch ex As Exception
MessageBox.Show(ex.Message
End Try
Good Karma to the person that can solve this mystery!!
Thanks.
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.Ro ws(i))
Next i
Dim markerRow As DataTable
markerRow = table.Clone
markerRow.Rows.Add(table.R ows(4))
Dim lineRow As DataTable
lineRow = table.Clone
lineRow.Rows.Add(table.Row s(5))
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.Ro
Next i
Dim markerRow As DataTable
markerRow = table.Clone
markerRow.Rows.Add(table.R
Dim lineRow As DataTable
lineRow = table.Clone
lineRow.Rows.Add(table.Row
ASKER
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.Ro ws(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
For i As Integer = 0 To 3
fourRows.Rows.Add(table.Ro
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
ASKER
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?
fourRows = dTable.Clone
For i As Integer = 0 To 3
fourRows.ImportRow(dTable.
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?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I figured out the import rows and the solution for my chart.
Regards
Rick
Open in new window