We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Display datagridview data in syncfusion chart

I'm trying to plot data into a chart from specific columns in datagridview. These are plotted against the date. The windows chart syntax seems quite different than syncfusion.  Below is the example that works with windows chart. There is no .DataSource extension in the syncfusion code, only DataSourceName. Also there is no .Rows or .Columns extension either.

private void Eccentricity_btn_Click(object sender, EventArgs e)
{                     
            if (CK_QA_DataDataGridView.Rows.Count == 0)
            {
                MessageBox.Show("Select Date Range and Show Results Before Graphing");
            }
            else
            {
                chart1.Visible = true;
                InitialChart.Visible = false;

                chart1.DataSource = CK_QA_DataDataGridView.DataSource;
               
                //Tube A Beam Eccentricity Series
                this.chart1.Series["Tube A - Beam"].XValueMember = CK_QA_DataDataGridView.Columns[0].DataPropertyName;

                this.chart1.Series["Tube A - Beam"].YValueMembers = CK_QA_DataDataGridView.Columns[3].DataPropertyName;
                //Tube B Beam Eccentricity Series
                this.chart1.Series["Tube B - Beam"].XValueMember = CK_QA_DataDataGridView.Columns[0].DataPropertyName;

                this.chart1.Series["Tube B - Beam"].YValueMembers = CK_QA_DataDataGridView.Columns[7].DataPropertyName;
                //Tube A Shadow Eccentricity Series
                this.chart1.Series["Tube A - Shadow"].XValueMember = CK_QA_DataDataGridView.Columns[0].DataPropertyName;

                this.chart1.Series["Tube A - Shadow"].YValueMembers = CK_QA_DataDataGridView.Columns[4].DataPropertyName;
                //Tube B Shadow Eccentricity Series
                this.chart1.Series["Tube B - Shadow"].XValueMember = CK_QA_DataDataGridView.Columns[0].DataPropertyName;

                this.chart1.Series["Tube B - Shadow"].YValueMembers = CK_QA_DataDataGridView.Columns[8].DataPropertyName;

                chart1.DataBind();
            }        
        }

5 Replies

DP Deepaa Pragaasam Syncfusion Team September 25, 2015 12:54 PM UTC

Hi Kevin,
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



SG Sakthi G Syncfusion Team September 28, 2015 04:46 AM UTC

From: Kevin Shay
Sent: Saturday, September 26, 2015 6:37 PM
To: Syncfusion Support <support@syncfusion.com>
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



DP Deepaa Pragaasam Syncfusion Team September 28, 2015 12:52 PM UTC

Hi Kevin,
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.



KS Kevin Shay September 28, 2015 09:08 PM UTC

Deepa,

You are making a table and telling the datagridview to pull values from that table. I need to pull values from the datagridviewer due to a date range filter that has already been applied. In other words, I need to pull data into the chart from the dataGridView1.DataSource "directly". Something like chartControl1.Datasource = dataGridView1.DataSource. To pull the data from the table would be unfiltered and not useful. Is there anyway to do this?

Kevin


DP Deepaa Pragaasam Syncfusion Team September 29, 2015 07:34 AM UTC

Hi Kevin,
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.


Loader.
Live Chat Icon For mobile
Up arrow icon