Access ChartControl from name (string)

Good day,

I am attempting to create a new chart in code during one event (I.e. ChartControl chart = new ChartControl) and then wanting to access that new control in a different event in order to update the data.

With windows controls you can find them by specifying: this.Controls.Find("name"). However if I do that for a ChartControl it says that it cannot cast the windows control as a syncfusion control. So, how can I access the chartcontrol to modify the series from the name of the newly created chart since the chart does not exist at design time?

thanks!

1 Reply

SK Sanjith Kesavan Syncfusion Team February 26, 2018 09:29 AM UTC

Hi Travis, 

Thanks for contacting Syncfusion support. We have analyzed your query and tried to replicate the reported scenario at our end. But using this.controls.find() method, we can find the Syncfusion chart component and modify it since the chart does not exist at the design time. Please find the below code example.  

[C#] 
ChartControl chart = new ChartControl(); 
chart.Name = "chartControl1"; 
ChartSeries series = new ChartSeries(); 
series.Points.Add(1, 20); 
series.Points.Add(2, 10); 
series.Points.Add(3, 30); 
series.Points.Add(4, 15); 
chart.Series.Add(series); 
chart.Skins = Skins.Metro; 
this.Controls.Add(chart);             
InitializeComponent(); 
Control[] controls = this.Controls.Find("chartControl1", false); 
ChartControl chart1 = controls[0] as ChartControl; 
chart1.Series[0].Points[3].X = 5; 
chart1.Series[0].Points[3].YValues[0] = 20; 

In the above code, we have created the chart control with name “chartControl1” and added it to the forms. After adding the chart component, we have find the chart using this.Controls.find() and changed the X and Y values of the last point in the chart. Now the chart will render like below.  

In the below link, we have attached sample for your reference.  
Sample link: chart 

Kindly check the sample and let us know if you have any concern. 

Thanks, 
Sanjith. 


Loader.
Up arrow icon