Draw multiple line in jqplot using json Data -
iam trying draw multiple line in jqplot using json data have doubt on jqplot, using json data plot chart in jqplot.i have 2 sets of json data this
var jsondata1 = {"priceticks": [{"price":5.5,"tickdate":"jan"}, {"price":6.8,"tickdate":"mar"}, {"price":1.9,"tickdate":"june"}, {"price":7.1,"tickdate":"dec"}]}; var jsondata2 = {"priceticks": [{"price":1.5,"tickdate":"jan"}, {"price":2.8,"tickdate":"feb"}, {"price":3.9,"tickdate":"apr"}, {"price":9.1,"tickdate":"dec"}]};
suppose have javascript arrays can call
$.jqplot('chartdiv', [cospoints, sinpoints, powpoints1, powpoints2, powpoints3], { title:'line style options', seriesdefaults: { showmarker:false, }, } );
where cospoints,sinepoints etc javascript arrays in similar way have call json data , used following way failed ,please me.
$.jqplot('jsonchartdiv', [jsondata1,jsondata2] { title:'fruits', series:[{showmarker:false}], datarenderer: $.jqplot.ciparser, axes: { xaxis: { renderer:$.jqplot.categoryaxisrenderer, } }, });
i didn't manage ciparser renderer plugin work data format requirement.
in following jsfiddle see working example convert json objects required datastructure needed display line chart.
// array both series arseries = [jsondata1, jsondata2]; // initalizat output array jqplot arjq = []; // each data series (var z = 0; z < arseries.length; z++) { // array prices jqprices = []; var prices = arseries[z].priceticks; (var = 0; < prices.length; i++) { jqprices.push([prices[i].tickdate.tostring(), prices[i].price]); } // result [["jan",1.5],["feb",2.8],["apr",3.9],["dec",9.1]] // add series array arjq.push(jqprices); }
to prevent line going backward should spedify either date more granular or same tickes on each data record.
Comments
Post a Comment