How to limit the scale?

I would like to limit the scale so that it cannot be increased deeper than a certain value. For instance. my data dates from days / months to 15 minutes, so the smallest value that I would like to show (and therefore give the user the ability to scale only so far) will be like 4-5 values ​​of these 15 minute intercepts.

I found the ticker feature in another thread, but this does not help, because it does not limit the ability to scale. Is there a built-in method that can help me, or in another way, limit the scaling?

+4
source share
3 answers
zoomCallback: function (minDate, maxDate, yRange) { // Calculate the difference between the values var difference = maxDate - minDate; // If difference smaller than 3 hours if ((difference / 1000 / 60 / 60) < 3) { maxDate = new Date(minDate).setMinutes(180); g.updateOptions({ dateWindow: [minDate, maxDate] }); } }, 

This is what I came up with and actually works fine. I will have to change the values ​​a bit, but it works the way I want for the most part. There is only one problem with this solution: When I zoom in, it automatically changes the values, and you can see for a very short time that the old values ​​are displayed and then they change to new ones. It just doesn't feel great for users, but it's not a robber. Is there another event that was triggered earlier?

+2
source

There is no built-in support. But you can define zoomCallback . This can call xAxisRange to determine if a new zoom window is acceptable. If not, you can call updateOptions({dateWindow: ...}) with some acceptable alternative.

+1
source

I found a test file on the dygraphs website called zoom, which limits the scaling to the range between mindate and maxdate. Here is the link. You can create a minimum range, so the user always sees at least 4-5 data points.

0
source

Source: https://habr.com/ru/post/1501432/


All Articles