|
Sync multiple axes |
Posted by Lofi on Jul-04-2013 23:09 |
|
I have an undetermined number of axes which will be added via addAxis. For the scrolling and zooming I have to sync them via syncLinearAxisWithViewPort.
syncLinearAxisWithViewPort requests an id. Which id? How is it determined? From the examples I took guesses and put all axes into a list and invoke the sync method this way:
for( int i=0; i < customAxisList.size(); i++) {
viewer.syncLinearAxisWithViewPort( "y"+(2+i), customAxisList.get( i));
}
This is plain ugly. What's the proper way to do this?
Thank you very much for the help! |
Re: Sync multiple axes |
Posted by Peter Kwan on Jul-05-2013 00:20 |
|
Hi Lofi,
The "id" is just an arbitrary name so your code and ChartDirector can keep track of which axis is using which scale.
For example, in some applications, the user may be allowed to add an additional axis (eg. add a dummy axis not used by any data, but is just set to 0 - 100% at full scale, so that user can see the position of the view port) or delete an axis, or change the ordering of the axis, etc.. So there must be some way to keep track of which axis is using which scale.
The "id" is used to identify the scale, which the axis object is used to represent the axis. The syncLinearAxisWithViewPort is used to tell ChartDirector that a certain axis should be using a certain scale.
For your case, may be you can use a HashMap to give names to your axes, and in this case the syncLinearAxisWithViewPort can be used to associate the names with the axis object. If the user cannot add or delete axis or rearrange their order, you can also use an ArrayList like in your current code if, in which case the name can be just derived from the array index.
Hope this can help.
Regards
Peter Kwan |
Re: Sync multiple axes |
Posted by Lofi on Jul-05-2013 02:14 |
|
Hello Peter,
thank you very much for your quick reply. I understand now. The id is something unique that I can create. I had the impression that because of "y" and "y2" in the examples it would be something that CharDirector creates internally and I'd have to reuse it.
So if I understand you correctly, I can as well use "a", "b", "c", ... it's just an id that I can create myself, not something that ChartDirector creates.
In that matter - just to be sure - I have a question regarding the examples:
viewer.syncDateAxisWithViewPort("x", chart.xAxis());
viewer.syncLinearAxisWithViewPort("y", chart.yAxis());
So this could as well be:
viewer.syncDateAxisWithViewPort( "someaxis1", chart.xAxis());
viewer.syncLinearAxisWithViewPort( "someaxis2", chart.yAxis());
So it isn't related to "x" and "y". That wasn't clear in the documentation for me, now it is
Thank you very much!
Best regards
Lofi |
Re: Sync multiple axes |
Posted by Peter Kwan on Jul-05-2013 22:35 |
|
Hi Lofi,
Yes. You can use any name you like.
Consider the sample code "Zooming and Scrolling with Track Line 1 (Windows)". In this sample code, there are two lines of code that configures the scale of the x-axis. During initialization, the following line is used to define the full scale:
viewer.setFullRange("x", timeStamps[0], timeStamps[timeStamps.length - 1]);
and in drawing the chart, the following line is used to define the visible axis range:
viewer.syncDateAxisWithViewPort("x", c.xAxis());
In the above code, the "x" is just an arbitrary name. You can change it with "someAxis" if you like.
Hope this can help.
Regards
Peter Kwan |
|