hi i'm noob in javascript , need help. want draw chart real time data mcu. don't know how push string array. in code array (chart.dataprovider) still 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; //get response data string // value= {cat: 1, c1: 2, c2: 3}; //this metod draw chart want rt data... alert(value); //output: {cat: 1, c1: 2, c2: 3} chart.dataprovider.push(value); chart.validatedata(); }}; req.open("get", "http://", true); req.send(); }
also works too:
chart.dataprovider.push({ cat: 1, c1: 2, c2: 3 });
but how push data xmlhttprequest?
you need initialize chart.dataprovider = []
before pushing new values.
if problematic - check if it's undefined, , if - initialize chart.dataprovider = chart.dataprovider? chart.dataprovider : []
lastly, if question regarding ajax operation - try use promises or callback wait push operation.
hope helps
Comments
Post a Comment