6

I am "animating" diagrams over time by changing the data and redrawing them.

// initialization
var data = ...
var targetPlot = $.jqplot('#diagram', data, diagramOptions);

Now after some time I will change the data in some way and want to update the diagram. The following solution works:

// update Data
targetPlot.data = ...;
// remove old diagram
$('#<%= "diagram" + diagram.id.to_s %>container').empty();
// redraw
targetPlot = $.jqplot('#diagram', data, diagramOptions);

Bit this is a complete redraw. With lots of data and a short intervall jQPlot takes much memory and the diagram is flickering.

How to do this correct?

The solution using the redraw-function for me only draws the old diagram:

// update Data
targetPlot.data = ...;
targetPlot.redraw();
Sandro L
  • 1,140
  • 18
  • 32

1 Answers1

15

This is the way I found after lots of investigation. I am writing this down to help someone reading this question.

The correct place to update the data is in the series property, after updating the data you can redraw the plot:

targetPlot.series[0].data = myData;
targetPlot.redraw();

If your axis changed, then you can rescale them by using replot() instead of redraw():

targetPlot.replot({resetAxes:true});

This is much faster than redrawing a new plot every time.

Sandro L
  • 1,140
  • 18
  • 32
  • 3
    You can also activate [`animateReplot`](http://www.jqplot.com/deploy/dist/examples/barLineAnimated.html) to get a little animation on the replot – Pierre de LESPINAY Feb 02 '12 at 11:41
  • Plus 300 if I could... the comment above is key to reanimating the chart. Thanks. –  Jun 25 '14 at 19:39