Get list of data points on canvas after jqplot scaling

I really appreciate if anyone can help me with this. We use Jqplot to build statistics and as a function of scaling.

In particular, we want to use examples in

http://www.jqplot.com/deploy/dist/examples/zoom1.html and

http://www.jqplot.com/deploy/dist/examples/zoomOptions.html

One of the things we need to do is to recalculate some of the values ​​that we display on the page, for example, standard deviation, average value, etc. for points visible on the graph after scaling. To do this, we need to get a list of data points that are (remain) on the chart after we zoom in. Therefore, ideally, we consider a method that returns the current data set that is visible on the graph after an increase.

I looked at the API documentation, but this method is not available. Therefore, I would be very grateful if someone would help with how I should continue this.

Thanks .... Amit

+7
source share
1 answer

Good, therefore, after repeatedly digging the code, there really is no easy way to get this data, but there is a way.

In the solution below, I have a zoomChart jqPLot obj object that acts like a zoom proxy for my main jqPLot called chart . Presumably if you don't have a proxy, this should work just as well if you are attached to the right object.

What I'm doing is binding the custom function to the jqplotZoom event, which is fired after the zoom action completes.

zoomChart.target.bind('jqplotZoom', function(ev, gridpos, datapos, plot, cursor){ var plotData = plot.series[0].data; for (var i=0; i< plotData.length; i++) { if(plotData[i][0] >= chart.axes.xaxis.min && plotData[i][0] <= chart.axes.xaxis.max ) { //this dataset from the original is within the zoomed region //You can save these datapoints in a new array //This new array will contain your zoom dataset //for ex: zoomDataset.push(plotData[i]); } } }); 
It makes sense? In essence, chart.axes.xaxis contains the boundaries of the enlarged area, and plot.series[N].data contains all of your source data in chart format.

Please note that I used chart because I originally created var chart = $.jqplot("chartDiv", ...

You must use any variable name you gave to your plot. Hope this helps!

+6
source

All Articles