javascript - highcharts dynamic categories not working -
i using below method populate categories in highcharts dynamically not working me
var weeklyindicators; var cats = ''; $.when( $.getjson('weeklyindicators', function(data) { weeklyindicators = data; }) ).then(function() { $.each(weeklyindicators, function(i, item) { if (cats.indexof(item.indicatortimestamp) == -1){ cats += "'" + item.indicatortimestamp + "'" + ','; } }); cats = cats.substring(0, cats.length - 1); console.log(cats); // here output: '2016-01-30','2016-01-31','2016-02-01','2016-02-02','2016-02-03','2016-02-04','2016-02-05' $('#container').highcharts({ chart: { type: 'column' }, title: { text: 'monthly average rainfall' }, subtitle: { text: 'source: worldclimate.com' }, xaxis: { categories: [cats], crosshair: true }, yaxis: { min: 0, title: { text: 'rainfall (mm)' } }, tooltip: { headerformat: '<span style="font-size:10px">{point.key}</span><table>', pointformat: '<tr><td style="color:{series.color};padding:0">{series.name}: </td>' + '<td style="padding:0"><b>{point.y:.1f} mm</b></td></tr>', footerformat: '</table>', shared: true, usehtml: true }, plotoptions: { column: { pointpadding: 0.2, borderwidth: 0 } }, series: [{ name: 'tokyo', data: [49.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6] }, { name: 'new york', data: [83.6, 78.8, 98.5, 93.4, 106.0, 84.5, 105.0] }, { name: 'london', data: [48.9, 38.8, 39.3, 41.4, 47.0, 48.3, 59.0] }, { name: 'berlin', data: [42.4, 33.2, 34.5, 39.7, 52.6, 75.5, 57.4] }] }); });
if copy/paste output console.log, working fine, help?
below screenshot
also, need series dynamic, appreciated.
use
var cats =[] $.each(weeklyindicators, function(i, item) { if (cats.indexof(item.indicatortimestamp) == -1){ cats.push(item.indicatortimestamp); } });
and use cats array in categories directly
categories = cats //not in []
Comments
Post a Comment