I have a problem with google line chart, my system delivers data interactively and I need to update google chart interactively upon change. In order to do so, I call chart.draw(...)
during every data upload. Unfortunately making such call resets visual state of the component.
Consider the following jsfiddle http://jsfiddle.net/1besonf5/83/
If you zoom component it will get reset in a second. Due to
setInterval(() => chart.draw(data, chartOptions), 3000);
How do you deal with this problem?
following is a rough example of how to re-draw the chart at the same zoom level
1. it boils down to finding the current min / max values of each axis
using the various chart methods available, including...
(see
getCoords
below)once you have the coordinates, you can set the min / max values on the axis options
(see
setRange
below)2. see the following working snippet...
the "Redraw Chart" button demonstrates redrawing the chart with the same zoom level as found in the currently displayed chart
to test, "
dragToZoom
" the chart, then click "Redraw Chart"the "Reset Chart" button is used to reset the chart to the original zoom level
-- which is normally right-click but is lost due to redraw and could be added back with an event listener
might also want to round the axis values or provide custom ticks, which isn't provided here