Update Am4charts.xychart Data
Solution 1:
am4core.create
is for creating the chart, not updating, which is why you're getting an error when calling it again on the same div. The library is telling you to delete the old chart first using the dispose
method.
Rather than calling create again, if you want to update the chart data, simply update the chart's data
array. If you're replacing the array or adding data to it, the chart will automatically update itself:
chart.data = /* new array */// or using addData
chart.addData([/* each element you want to add */])
If you're modifying the data in place, call the chart's invalidateData
or invalidateRawData
method after you make your changes, e.g. chart.invalidateData()
Ideally you'd want to have the chart variable accessible outside of am4core.ready
, so creating the variable outside of the function and assigning it inside the ready function is probably your best bet:
var chart;
am4core.ready(function() {
// ...
chart = am4core.create(...); //assign to global variable// ...
}));
//update chart using global variable
You can find more information on how you can update the chart here.
Post a Comment for "Update Am4charts.xychart Data"