Hello, I'm new to JavaScript and seeking assistance. My goal is to create a chart with real-time data from my MCU, but I'm unsure about pushing a string into an array. Currently, the Array (chart.dataProvider) in this code remains undefined.
var chart = AmCharts.makeChart("chartdiv",{
...
"dataProvider":[],
});
function f() {
var req = new XMLHttpRequest();
req.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
var value = this.responseText;
// value= {cat: 1, c1: 2, c2: 3};
alert(value); //output: {cat: 1, c1: 2, c2: 3}
chart.dataProvider.push(value);
chart.validateData();
}};
req.open("GET", "http://", true);
req.send();
}
This method also works:
chart.dataProvider.push({ cat: 1, c1: 2, c2: 3 });
However, how can I push data using XMLHttpRequest?