简体   繁体   中英

VB - displaying chart from datagridview

I am willing to show a Line chart that is based from datagridview, but I would like to be able to show not only all the x values, but showing only each 5 or 10 values, for example I had record of temperature in my room every hour in 10 days, so I got 24x10 = 240 data, but I would like to be able to show only the value in each every 3 hour showed on the chart. another ex. I have data from 1-100 I want to show chart only from each data 5,10,15,20,... how is it possibly done ?

   Chart1.Series(0).ChartType = DataVisualization.Charting.SeriesChartType.Line
    Chart1.Series(0).Points.Clear()
    For Count As Integer = 0 To dataGridView1.Rows.Count - 1
        Chart1.Series(0).Points.AddXY(dataGridView1.Item(0, Count).Value, dataGridView1.Item(2, Count).Value)
    Next

the code above has successfully showed the normal line chart.

Skip the points you don't want to plot in the loop using Mod in vb.net

Dim divisor = 3
Chart1.Series(0).ChartType = DataVisualization.Charting.SeriesChartType.Line
Chart1.Series(0).Points.Clear()
For count As Integer = 0 To DataGridView1.Rows.Count - 1
    If (DataGridView1.Item(0, count).Value Mod divisor = 0) Then
        Chart1.Series(0).Points.AddXY(DataGridView1.Item(0, count).Value, DataGridView1.Item(2, count).Value)
    End If
Next count

This skips all x values into which 3 does not divide without a remainder. You can change Dim divisor = 3 to Dim divisor = 5 to skip all x values into which 5 does not divide without a remainder, etc.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM