How to assign data to the line when the chart is initialized

Hi,

In the webApi method to achieve chart initialization, I can not load the data when assigning a set of list data to each point in the series. Some of the data in the chart may be obtained in real time as part of the data is already existing data.
Is the data format I defined correct? Should the data be assigned to that series-points or series-datasource?
thanks
linsee

3 Replies

BP Baby Palanidurai Syncfusion Team June 29, 2018 03:48 AM UTC

Hi Linsee,
 
Thanks for using syncfusion products,
 
We have analyzed your query and as per your requirement we have prepared a sample.On initial rendering, we have assigned data to the chart through dataSource property in series. Now we are changing the data for initialized chart through button click, by assigning the new JSON data again to the dataSource property. Please find the code snippet for changing data for chart after the initial render. Please find the below code snippet to achieve this requirement,
 
$("#container").ejChart(
{
series:
[{             // here binding the data to data source
dataSource: dataManger,
xName: "xValue",
yName: "yValue",
query: query
}],
});    
function addData() {
   var chart = $('#container').ejChart('instance');
   var data = [
       {xValue: 4, yValue: 30},
   {xValue: 5, yValue: 40},
   {xValue: 6, yValue: 35},
   {xValue: 7, yValue: 25 },
   {xValue: 8, yValue: 60 },
   {xValue: 9, yValue: 38 },
   {xValue: 10, yValue: 40}
   ]; 
// here bind the new data in series data source
 
   chart.model.series[0].dataSource = data;
   chart.redraw();
   count++;
 }
 
S.No
Query
Response
1.
Should the data be assigned to that series-points or series-datasource?
When the chart is initialized through dataSource, we have to refresh the data through series.dataSource only, else you can assign it to series.points.
 
2.
Is the data format I defined correct?
We have to assign simple JSON data(List Collection) to series.points or series.dataSource property. If it is bind to dataSource in series, we have to map the fields in the list to the xName and yName property.
 
 
Screenshot: 
Before add the new data:
Inline image OWAPstImg208907
 
After add the new data:
Inline image OWAPstImg437736
 
Sample for your reference can be find from below link,
 
Kindly revert us, if you have any queries.
 
Thanks,
Baby.



LI linsee June 29, 2018 01:33 PM UTC

Hi Baby,
thank you for your help

linsee 


BP Baby Palanidurai Syncfusion Team July 2, 2018 05:07 AM UTC

Hi Linsee,
 
Thanks for your update,
 
   Please let us know if you need any further assistance on this.
 
 
Thanks,
Baby.


Loader.
Up arrow icon