Display datagridview data in syncfusion chart
Thanks for contacting Syncfusion Support.
We have analyised your query .It is possible to bind the dataViewGrid to the chart by using the
ChartDataBindModel Property.
Please refer the following help document link for further reference
http://help.syncfusion.com/windowsforms/chart/chart-data#binding-a-dataset-to-the-chart
We have created a sample where the datatable is bind to the DataViewGrid and assigned to the chart.
I am attaching the code snippet for your reference
Code Snippet:
[Form.CS]
ChartDataBindModel model = null;
model = new ChartDataBindModel(table);
model.XName = "Year";
// The columns that contain the Y values.
model.YNames = new string[] { "Population" };
series1.SeriesModel = model;
Screenshot :
We have binded the datatable “People ” containing the values in the dataViewGrid.I have attached the below screenshot which is rendered using the datatable
I have attached the sample for your reference
http://www.syncfusion.com/downloads/support/forum/120553/ze/WindowsForms1529471689
Please let us know if you have any concerns.
Regards,
Deepaa
Sent: Saturday, September 26, 2015 6:37 PM
To: Syncfusion Support <[email protected]>
Subject: Re: Syncfusion support community forum 120553, Display datagridview data in syncfusion chart, has been updated.
Deepaa,
Thanks so much for your response! It's really helpful. I'm facing a problem when I call the chart with a button. Since the code you have says "chart.Series.Add(series1);", every time I click the button to update the chart it adds a series on top of the one I just added. It's essentially the same data being added multiple times. Is there an "update" function rather that "add"?
Kevin Shay
Thanks for the revert.
We have analyised your query and created the sample according to your requirement.
On button click the datasource is bound to the exsisting series, without using the Add Method.
[Form.cs]
model1 = new ChartDataBindModel(table);
model1.XName = "Year";
model1.YNames = new string[] { "Population" };
this.chart.Series[0].SeriesModel = model1;
Screenshot:
Rendered empty chart in datagrid view
On button click, the below chart is displayed
I have attached the sample for your reference
http://www.syncfusion.com/downloads/support/forum/120553/ze/WindowsForm1893745317.
Please let us know if you have any concerns.
Regards,
Deepaa.
Thanks for the revert.
We have analyised your query and created a sample where the DataGridView datasource is bound directly to the chart on button click.
Code Snippet:
I have created the ChartDataBindModel and assigned the dataGridView datasource to it.
ChartDataBindModel model1 = null;
model1 = new ChartDataBindModel(this.dataGridView1.DataSource);
this.chart.Series[0].SeriesModel = model1;
ScreenShot:
Default gridview with datatable
On button Click
We have attached the sample for your reference
http://www.syncfusion.com/downloads/support/forum/120553/ze/dataGridView1670569689
Please let us know if you have any concerns.
Regards,
Deepaa.
- 5 Replies
- 3 Participants
-
KS Kevin Shay
- Sep 24, 2015 10:36 PM UTC
- Sep 29, 2015 07:34 AM UTC