TeeChart for Java (NetBeans, Eclipse, Android Studio, etc)
-
cdn
- Newbie
- Posts: 29
- Joined: Wed Sep 19, 2007 12:00 am
Post
by cdn » Tue Oct 23, 2007 8:56 am
Hi:
We are noticing that zoomin and zoomout do not get us to the same point. For example when we zoomin (once) and zoomout (once) we do not get to the same point on the chart. Is this expected behavior. I will give you the brief code snippets below.
Code: Select all
...........
zoomin = 95;
tChart2.getZoom().zoomPercent(zoomin);
...........
............
zoomout = 105;
tChart2.getZoom().zoomPercent(zoomout);
............
We can never get back to the same point on the chart. Please let us know what is the expected behavior with the above code. Thanks.
best regards,
-
Narcís
- Site Admin
- Posts: 14730
- Joined: Mon Jun 09, 2003 4:00 am
- Location: Banyoles, Catalonia
-
Contact:
Post
by Narcís » Tue Oct 23, 2007 9:42 am
Hi cdn,
This is because with the second statement you zoom the chart a 105% from the 95% you had before, which is not the same as going back to the original view. To achieve this you could use:
Hope this helps!
-
cdn
- Newbie
- Posts: 29
- Joined: Wed Sep 19, 2007 12:00 am
Post
by cdn » Tue Oct 23, 2007 11:19 am
Thanks, Narcis.
The code you sent us - we are using for Clearing Zoom. But that doesn't help in our current setup. What we have is a separate control for ZoomIn and ZoomOut. So, for example if we do 5 ZoomIn's and 5 ZoomOut's; we should be back at where we started. That is waht we are trying to achieve.
The code example we showed was -
- we are zomming in 95%
- and, we are zooming out 105% (once we zoom in we are at 100%, correct. That is why we are using 105%) That was the logic we used.
I hope the above explanation clears up any misunderstanding about what we are trying to implement.
best regards,
-
Narcís
- Site Admin
- Posts: 14730
- Joined: Mon Jun 09, 2003 4:00 am
- Location: Banyoles, Catalonia
-
Contact:
Post
by Narcís » Tue Oct 23, 2007 1:05 pm
Hi cdn,
I'm afraid the logic you used is wrong, that's what I tried to explain. For example, if you have 95% of something and you add a 5% to this you don't get 100%, you get 99.75%. What I mean is that it is not the same 5% of 100 (which certainly is 5) than 5% of 95 (which is 4.75).
To achieve what you request you should calculate the necessary ratio you want to apply at zoomPercent.
Hope this helps!
-
cdn
- Newbie
- Posts: 29
- Joined: Wed Sep 19, 2007 12:00 am
Post
by cdn » Wed Oct 24, 2007 11:24 am
Well .... we tried that way also.
Let us assume that we zoomed in 95%. Then the ratio turns out to be 5.26% (in your logic). Then we zoomout 105.26% to get back to original chart. Even this value does not bring us back to the original chart location (we lose about 2 data points).
Is there a different way to achieve what we are trying to do. Thanks.
best regards,
-
Narcís
- Site Admin
- Posts: 14730
- Joined: Mon Jun 09, 2003 4:00 am
- Location: Banyoles, Catalonia
-
Contact:
Post
by Narcís » Wed Oct 24, 2007 1:35 pm
Hello,
What about doing something like the code below for a more precise ratio?
Code: Select all
double zoomin = 95;
tChart.getZoom().zoomPercent(zoomin);
double zoomout = (double)100+((double)500/(double)95);
tChart.getZoom().zoomPercent(zoomout);
-
cdn
- Newbie
- Posts: 29
- Joined: Wed Sep 19, 2007 12:00 am
Post
by cdn » Thu Oct 25, 2007 3:32 am
We have uploaded the images for your reference. We are using the ratio as mentioned in your code snippet. We ran as it is and the output was as displayed in the images (as you can see we are losing a datapoint for the single zoom .... if we do multiple times we lose quite a few). Please advise. Thank you.
best regards,
-
Marc
- Site Admin
- Posts: 1274
- Joined: Thu Oct 16, 2003 4:00 am
- Location: Girona
-
Contact:
Post
by Marc » Thu Oct 25, 2007 2:53 pm
Hello,
Working with percentages in this way presents difficulties. Probably better to save the Axis Mininums and Maximums to an array and then restore the saved co-ordinates when stepping back through zooms.
eg. saving co-ords:
Code: Select all
double[][] oldZooms ={{tChart.getAxes().getLeft().getMinimum(),tChart.getAxes().getLeft().getMaximum()},
{tChart.getAxes().getTop().getMinimum(),tChart.getAxes().getTop().getMaximum()},
{tChart.getAxes().getRight().getMinimum(),tChart.getAxes().getRight().getMaximum()},
{tChart.getAxes().getBottom().getMinimum(),tChart.getAxes().getBottom().getMaximum()}};
you could then save a list of oldZooms accordingly and restore them as required.
in this case
eg.
Code: Select all
tChart.getAxes().getLeft().setMinMax(oldZooms[0][0],oldZooms[0][1]);
tChart.getAxes().getTop().setMinMax(oldZooms[1][0],oldZooms[1][1]);
tChart.getAxes().getRight().setMinMax(oldZooms[2][0],oldZooms[2][1]);
tChart.getAxes().getBottom().setMinMax(oldZooms[3][0],oldZooms[3][1]);
The last step back should use tChart.getZoom().undo() if the Axes were automatic to restore 'auto' scaling.
Regards,
Marc Meumann
Steema Support