1

I'm creating one application, which use to determine the raw data and those raw data values are imported in datagridview. Now I need to produce that raw data values in graphical representation. I have datgridview with multiple columns and I want to plot graph/chart with datagridview column values in C#.

This is what I tried.

    private void button1_Click(object sender, EventArgs e)
    {
        
        try
        {
            chart1.Visible = true;
            this.chart1.Series["0"].Points.DataBindY((DataView)dataGridView1.DataSource, "SAMPLE1");
            this.chart1.Series["1"].Points.DataBindY((DataView)dataGridView1.DataSource, "SAMPLE2");
            this.chart1.Series["2"].Points.DataBindY((DataView)dataGridView1.DataSource, "SAMPLE3");
            this.chart1.Series["3"].Points.DataBindY((DataView)dataGridView1.DataSource, "SAMPLE4");
            this.chart1.Series["4"].Points.DataBindY((DataView)dataGridView1.DataSource, "SAMPLE5");
            this.chart1.Series["5"].Points.DataBindY((DataView)dataGridView1.DataSource, "SAMPLE6");
            this.chart1.Series["6"].Points.DataBindY((DataView)dataGridView1.DataSource, "SAMPLE7");
            this.chart1.Series["7"].Points.DataBindY((DataView)dataGridView1.DataSource, "SAMPLE8");
            this.chart1.Series["8"].Points.DataBindY((DataView)dataGridView1.DataSource, "SAMPLE9");
            this.chart1.Series["9"].Points.DataBindY((DataView)dataGridView1.DataSource, "SAMPLE10");

        }
        catch
        {
        }
    }

But no use. Is there any other way or method to plot the chart using datagridview column values directly?

Thanks in advance.

1 Answer 1

1

Use below code for chart through DataGridview

foreach (DataGridViewRow row in datagridview.Rows)
            {

                //chartBpComplaince.Series.Clear();
                Series S = chartBpComplaince.Series.Add(row.Cells[2].Value.ToString());

                 S.Points.AddXY(row.Cells[4].Value.ToString(), row.Cells[3].Value.ToString());
                 S.ChartType = SeriesChartType.Column;
                 S.IsValueShownAsLabel = true;
}
Sign up to request clarification or add additional context in comments.

1 Comment

The question was really about the use of data binding rather than manually updating the value in the view on each update.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.