javascript - HighChart Line Graph not Showing -
i using data csv file generate line graph using highchart. here code:
/* define initial , basic options */ var options = { chart: { type: 'line', renderto: 'graph_container' }, title: { text: 'fanniemaeacquisition cash flow' }, yaxis: { title: { text: 'amount($)' } }, series: [] }; /* parse csv file */ $.get('{% static "data/fanniemaeacquisitions.csv" %}', function(csv) { var lines = csv.split('\n'); var series = { name: '', data: [] }; $.each(lines, function (lineno, line) { var items = line.split(','); $.each(items, function (itemno, item) { if(itemno == 1){ if (lineno == 0){ series.name = item; } else { series.data.push(parsefloat(item)); } } }); }); options.series.push(series); console.log(options.series); }); // create chart var chart = new highcharts.chart(options);
however isn't working. tried testing manually inputting data so:
series: [{ name: 'installation', data: [43934, 52503, 57177, 69658, 97031, 119931, 137133, 154175] },
and works fine. took @ variables being passed series
. 1 works(manual input):
the 1 doesn't work(from csv):
any ideas?
edit: okay. weird going on here. highchart isn't showing on webpage showing when download png. weirder part shows on webpage if manually add in number values when extract values form csv graph disappears... when download png shows graph...any ideas??
second edit: okay, when do: console.log(json.stringify(options.series[0].data));
nothing shows up. mean values parsed csv file appear after graph generated. how fix this? lol
the problem due javascript's asynchronous issues. wrapped function in $.when
, worked!
Comments
Post a Comment