Reputation: 1457
My need is to draw a basic x-axis, y-axis plot of several lines, with the lines becoming known in sequence as the user enters data. jqPlot appears to have the ability (unlike flot, at least as I understand it) to add to an existing plot. My experimentation thus far is:
$.jqplot('dpCum',[ld.fCumPairFwd[0]],{axes:{xaxis:{min:0,max:2500},yaxis:{min:0,max:200000}}});
$.jqplot('dpCum',[ld.fCumPairAft[0]],{axes:{xaxis:{min:0,max:2500},yaxis:{min:0,max:200000}}});
which produces two lines as I want them, except the background of the 2nd obscures the the 1st line. In practice, the data for the 2nd line won't be known until the user responds to the 1st line, and then they're going to want to see both at once.
I've made a couple of passes at the jqplot documentation (it's capabilities are obviously impressive) but how to keep existing lines visible as new lines are added escapes me. I'm thinking there may be some kind of z-axis opacity, but haven't been able to understand it yet.
Upvotes: 1
Views: 309
Reputation: 7943
The answer to your problem, I believe, is to use the replot()
method and paint a new plot with the modified data set.
This approach is presented in the following sample. Please notice I made only the series with index 0 responsive to clicks. On click on the series' data points another is painted.
EDIT: The reason I went for replot()
was that I couldn't figure out how to draw just a single series. I tried the approach presented by @Mark here with no success. He might know better though. I am rather fresh to jqPlot
myself. Also taking into account that when we add a new series some points might reach outside the current scale, therefore, since redraw()
doesn't rescale as mentioned here by the jqPlot author - though in my case it will work since we reinitialize the graph. Thus, I think if you also will not manage to apply single series draw you might try using the redraw()
method instead, taking from the doc I think it is less expensive to call.
Maybe actually in this case you will not use replot()
or redraw()
, as in the sample I am making a new plot each time. Therefore, it seems to me to be more appropriate to call destroy()
on the previous graph before we paint the new one. This is what currently is in the code sample.
Upvotes: 1