jquery - Highcharts matching specific series points (yaxis) with xaxis? -
i have xml contains "dates" in xaxis , data-points spline series. xaxis : contains last 1 year date current date,(only market days) 250 days year. series : 250 points each dates
new : (where removed <samples>
0) dates
, sample
uneven in numbers. able plot data?
my xml : <categories> <dates>2014-10-10</dates> ......... <dates>2015-10-10</dates> </categories> <series> <name>apples</name> <data> <sample>67</sample> .... </data> </series> <series> <name>mangoes</name> <data> <sample>10</sample> <sample>67</sample> .... </data> </series>
old :
my xml : <categories> <dates>2014-10-10</dates> ......... <dates>2015-10-10</dates> </categories> <series> <name>apples</name> <data> <sample>0</sample> <sample>0</sample> <sample>67</sample> .... </data> </series> <series> <name>mangoes</name> <data> <sample>10</sample> <sample>0</sample > <sample>67</sample> .... </data> </series>
my jquery :
$xml.find("dates").each (function(i,cat){ options.xaxis.categories.push($(cat).text()); }); $xml.find('series').each (function(i,series){ var s = { name : $ (series).find('name').text(), data: [] } $(series).find('data sample').each (function(i,sample){ s.data.push($(sample).text()); }); }); options.series.push(s);
separated each sample separate series, first sample of each series match first
date. have collect non-zero values 'sample' series, plot
against corresponding date. possible? please guide me. in advance.
you can after setting series (in options object).
at beginning should iterate on categories have i.e $.each() function.
$.each(options.xaxis.categories, function(i, cat){}
inside function make container sum of series data have index of actual category index. iterate on series each() , add every data value on actual index.
$.each(options.xaxis.categories, function(i, cat){ sum=0; $.each(options.series, function(j,data){ sum+=data.data[i]; });
check if sum equal 0. on true remove category on actual index using splice(index, 1), index mean index starting splicing , 1 means number of spliced cells. iterate on series each() , remove every data cell on index splice(index,1).
if(x===0){ options.xaxis.categories.splice(i,1); $.each(options.series, function(j,data){ data.data.splice(i,1); }); }
all code looks below:
var x; $.each(options.xaxis.categories, function(i, cat){ x=0; $.each(options.series, function(j,data){ x+=data.data[i]; }); if(x===0){ options.xaxis.categories.splice(i,1); $.each(options.series, function(j,data){ data.data.splice(i,1); }); } });
Comments
Post a Comment