Reset zoom after changing data via Ajax

807 views
Skip to first unread message

Adrián Ribao

unread,
Nov 16, 2009, 8:35:54 AM11/16/09
to jqplot-users
Hello,

I need to change the series dinamically using Ajax.

I'm using:
graph.series[0].data = new_data;
graph.replot();

but the zoom and the axes are the same as the ones with the previous
data. I need to replot and change the axis and reset the zoom to the
new values.

How can I do this?

Thank you very much.

Chris Leonello

unread,
Nov 16, 2009, 8:57:11 AM11/16/09
to jqplot...@googlegroups.com
Good question!

If you just want to manually reset the zoom on a plot, do this:

graph.resetZoom();

This resets axes scales as well as the cursors "isZoomed" property,
redraws the plot, and calls any "jqplotResetZoom" hooks.

If you are dynamically changing data and want to rescale the axes,
pass an options object to the replot() method setting "resetAxes:true":

graph.replot({resetAxes:true});

If you wanted to rescale only selected axes, you can pass in an array
like:

graph.replot({resetAxes:['xaxis', 'y2axis']})

or pass in an object like:

graph.replot({resetAxes:{xaxis:true, y2axis:true}})

If you are doing both, resetting zoom and replotting b/c data has
changed, you may want to do this:

graph.resetZoom();
graph.replot({resetAxes:true})

or this if you don't want the extra call to redraw() and any
jqplotResetZoom hooks:

graph.plugins.cursor._zoom.isZoomed = false;
graph.replot({resetAxes:true});

Let me know how this works for you.

--
Chris Leonello

Adrián Ribao

unread,
Nov 16, 2009, 9:34:51 AM11/16/09
to jqplot-users
Hello Chris, thank you for your reply.

On 16 nov, 14:57, Chris Leonello <chris.leone...@gmail.com> wrote:
> Good question!
>
> If you just want to manually reset the zoom on a plot, do this:
>
> graph.resetZoom();

It says resetZoom is not a function of graph, where graph = $.jqplot
('graph', data, options);

>
> This resets axes scales as well as the cursors "isZoomed" property,  
> redraws the plot, and calls any "jqplotResetZoom" hooks.
>
> If you are dynamically changing data and want to rescale the axes,  
> pass an options object to the replot() method setting "resetAxes:true":
>
> graph.replot({resetAxes:true});

This is not working for me, I already had tested it.
I cant' make it work.

Regards,

Adrian

Chris Leonello

unread,
Nov 16, 2009, 11:16:53 AM11/16/09
to jqplot...@googlegroups.com
Which distribution are you using?

> It says resetZoom is not a function of graph, where graph = $.jqplot
> ('graph', data, options);

Open any of the zoom examples (zoom1.html, zoom2.html, zoom3.html or
zoomProxy.html) in the examples directory of your distribution. When
you click the "Reset" or "Zoom Out" buttons on those examples, they
call the resetZoom function. Does this work for you?

>>
>> graph.replot({resetAxes:true});
>
> This is not working for me, I already had tested it.

Likewise, open up the "resizablePlot.html" file in the example
directory. That uses the replot() method. Does it work correctly?
You could alter this line in that file:

plot2.replot();

to this:

plot2.replot({resetAxes:true});

to test the resetAxes functionality (on the bottom plot). It works
O.K. for me. You'll see more axes ticks/labels as you grow the plot
and less as you shrink the plot.

If these examples are working correctly, then my guess is it has
something to do with the way you are modifying your data.

--
Chris Leonello

Adrián Ribao

unread,
Nov 16, 2009, 11:36:29 AM11/16/09
to jqplot-users
Yes, all the examples are working, perhaps is something about the way
I manipule the data: graph.series[0].data = new_data;

Anyway, I gave up doing this using ajax, I prefer now read the data
from a hidden table, this is what I always do. I didn't get it to work
using the ajax call.

Regards,

Adrian.

Bhuvan Racham

unread,
Nov 28, 2009, 10:41:29 PM11/28/09
to jqplot...@googlegroups.com
Chris,

resetAxes is working in the example (resizablePlot.html) after the suggested modification.

I think what is not working is if the axis values range itself completely changes prior to replot. I think this could be what Adrian is running into too.

I plotted an OHLC graph with y-axis range 100 - 600 and then I obtained new data for y-axis dynamically with the new range of 20-150. So, after replot({resetAxes:true}};, I see that my y-axis is now has the range 20-600 instead of 20-150. Also, switching back to original y-axis has the same problem, range of 20-600 instead of 100-600.

I can get around this one by emptying the chart out every time and reinitializing it. But replot is more elegant, if the axis range issue works.

Am I missing something? Is there any other option that I need to enable to fix axis range issues?

Thanks.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "jqplot-users" group.
To post to this group, send email to jqplot...@googlegroups.com
To unsubscribe from this group, send email to jqplot-users...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/jqplot-users?hl=en
-~----------~----~----~----~------~----~------~--~---


Reply all
Reply to author
Forward
0 new messages