|
Zooming and Scrolling - Minimalistic Code (Java) |
Posted by Lofi on Jun-30-2013 14:29 |
|
I just found out that ChartDirector supports zooming and scrolling now. However, according to the manual there's quite some coding to be done for a feature that the Chart should be capable of by itself after it got all the initializations and all the data.
Is there a minimalistic approach which allows me to use scrolling and zooming? I expected a simple setZoomEnabled() rather than having to determine bounds and scales etc myself.
Thank you very much for the help! |
Re: Zooming and Scrolling - Minimalistic Code (Java) |
Posted by Peter Kwan on Jul-02-2013 00:32 |
|
Hi Lofi,
The "Simple Zooming and Scrolling" sample code is already rather simple. Anyway, I have attached an even simplier code with this message. You can see that the charting code is almost the same as that of a normal chart without zooming and scrolling.
Typically, in any chart supporting zooming and scrolling, apart from the charting code, it may need some code to set up the user interface. In the sample code, most of the code is used to set up the user interface so that the user can select the "mouse mode" (eg. whether the mouse click is for zoom in or zoom out, and whether the mouse drag is for selecting a region to zoom in, or for scrolling).
In the original sample code, there are also code to configure the initial zoom level. For example, if you have a stock chart with 50 years of data, you may want to initially show only the data for the last 90 days, so so code is need to set that up.
Also, in many actual usages with lots of data (such as the stock chart mentioned above), the developer may not want to load all 50 years of data from the database and just show the last 90 days of data, considering most people would not be interested in the 50 years of data. That's why in our examples, there are code to obtain the visible data range that is selected by the user. With the visible range available, the code can load the data on demand, instead of giving all 50 years of data at once regardless of what the user is viewing.
Regards
Peter Kwan
|
Re: Zooming and Scrolling - Minimalistic Code (Java) |
Posted by Lofi on Jul-02-2013 13:08 |
|
Hello Peter,
thank you very much for your help! I ran into a problem with loading different data into the same chart, when the chart was in a zoomed state. Of course I had to reset it. In case someone else needs it, it seems that you have to call this before you call the sync axis method:
viewer.clearAllRanges();
viewer.setViewPortLeft( 0.0);
viewer.setViewPortTop( 0.0);
viewer.setViewPortWidth( 1.0);
viewer.setViewPortHeight( 1.0);
Best regards
Lofi |
|