Click here to Skip to main content
15,891,184 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello, How can I show values from datagridview columns to chart?
I would like to show on x axis column "Datum a čas" and on y axis column "Plnění normy". I did it for textboxes but I dont known how can I do it for datagridview.

here is a datagridview: Imgur: The magic of the Internet[^]

What I have tried:

With Me.Chart3
            .Legends.Clear()
            .Series.Clear()
            .ChartAreas.Clear()
            .Titles.Clear()
        End With

        Dim areas1 As ChartArea = Me.Chart3.ChartAreas.Add("Areas1")
        With areas1
        End With

        Dim series1 As Series = Me.Chart3.Series.Add("Series1")
        Chart3.ChartAreas("Areas1").Area3DStyle.Enable3D = True
        Chart3.ChartAreas(0).BackColor = Color.Transparent
        With series1
            .ChartArea = areas1.Name
            .ChartType = SeriesChartType.Line
                       
            .Points.AddXY("Splněno", TextBox11.Text.Substring(0, TextBox11.Text.Length - 1))
            .Points.AddXY("Nesplněno", dopocet.Substring(0, 2))
            Chart3.Series("Series1").Points(0).Color = System.Drawing.Color.LimeGreen
            Chart3.Series("Series1").Points(1).Color = System.Drawing.Color.Red
            Chart3.Series("Series1").Font = New System.Drawing.Font("Times New Roman", 15.0F, System.Drawing.FontStyle.Bold)
        End With

        Dim T As Title = Chart3.Titles.Add("Plnění normy poslední evidence [%]")
        With T
            .ForeColor = Color.Black
            .BackColor = Color.LightBlue
            .Font = New System.Drawing.Font("Times New Roman", 15.0F, System.Drawing.FontStyle.Bold)
            .BorderColor = Color.Black
        End With
        Chart3.Series(0).LabelFormat = "{#'%'}"
        Chart3.Series("Series1").IsValueShownAsLabel = True
        'graf_posledni_evidence.Legends(1).Enabled = False
        Chart3.Series("Series1").Color = Color.Black
        Dim legends1 As Legend = Me.Chart3.Legends.Add("Legends1")
        Chart3.Legends(0).BackColor = Color.Transparent
        Chart3.Legends(0).Font = New System.Drawing.Font("Times New Roman", 15.0F, System.Drawing.FontStyle.Bold)
    End Sub
Posted
Updated 3-Jan-19 4:50am

 
Share this answer
 
Dim dtPieChartData = New DataTable()
       dtPieChartData.Columns.Add("Datum a čas")
       dtPieChartData.Columns.Add("Plnění normy")
       For Each row As DataGridViewRow In DataGridView1.Rows

           Dim indexCategoryColumn As Integer = 0
           Dim indexTotalColumn As Integer = 12
           dtPieChartData.Rows.Add(row.Cells(indexCategoryColumn).Value, row.Cells(indexTotalColumn).Value)

       Next

       Chart3.DataSource = dtPieChartData
       Chart3.Series("Series1").XValueMember = "Datum a čas"
       Chart3.Series("Series1").YValueMembers = "Plnění normy"
       Chart3.Titles.Add("Category Title")
       Chart3.Series("Series1").ChartType = SeriesChartType.Line
       Chart3.Series("Series1").IsValueShownAsLabel = True
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900