javascript - jqPlot: possible to dynamically add a new series? -
is possible dynamically add new series existing jqplot object?
i have jqplot object uses ajax data renderer retrieve 2 series. part works works fine.
based on user input (and several parameters), able dynamically add or remove additional series chart (while keeping 2 original).
is possible? possible without having retrieve unchanged data original 2 lines again?
alternatively, if not possible, there recommendations different charting library can this?
yes is, found out how this, , found question, , there no answer, provide mine. now, not elegant way it, works.
$(document).ready( function () { dataseriestoplot = [[[x1_1,y1_1],[x1_2,y1_2]],[[x2_1,y2_1],[x2_2,y2_2]], [[x3_1,y3_1], [x3_2,y3_2]]]; axesoptions = { xaxis: {min: xmin, max: xmax}, yaxis: {min: ymin} }; plottitle = 'plottitle', plotseriesdefaults = { showmarker: false, shadow: false, rendereroptions: { smooth: true } }; plotlegend = { show: true, labels: ['label1','label2','label3'] }; plotseriesoptions = [ { linepattern: 'dashed', color: '#f80202', }, { linepattern: 'dashed', color: '#f80202', }, { color: '#f80202', } ]; plotvar = $.jqplot('plotdiv', dataseriestoplot, { axes: axesoptions, title: plottitle, seriesdefaults: plotseriesdefaults, series: plotseriesoptions, legend: plotlegend }); addtoplot(); }); function addtoplot(){ $("plotdiv").empty(); dataseriestoplot.push([[x4_1,y4_1],[x4_2,y4_2]]); plotlegend.labels.push('label4'); plotseriesoptions.push({ linepattern: 'dashed', color: '#ff6600', }); plotvar = $.jqplot('plotdiv', dataseriestoplot, { axes: axesoptions, title: plottitle, seriesdefaults: plotseriesdefaults, series: plotseriesoptions, legend: plotlegend }); }
Comments
Post a Comment