|
How to include marks outside of the axis range |
Posted by Jonathan on Aug-04-2011 05:25 |
|
Hi,
I have a contour chart and have a custom mark (y=5). (I attached a sample chart to illustrate this). If user sets the mark with position which is outside of the axis range, the mark won't get displayed on the chart. For example. y=20 and/or y=-10 in the chart attached. Is there a way to reset the axis range such that the mark outside of data range can be included in the contour chart?
|
Re: How to include marks outside of the axis range |
Posted by Peter Kwan on Aug-04-2011 17:02 |
|
Hi Jonathan,
By default, ChartDirector will auto scale the axis to include all "data points". The mark on the axis is not consider as a "data point", so it is not considered when scaling the axis.
To achieve what you need, you may add a transparent data point on the chart using your mark value. For example:
c.addScatterLayer(new double[] { myContourXData[0] }, new double[] { myMarkValue }, "", Chart.SquareSymbol, 1, Chart.Transparent, Chart.Transparent);
The above code has no visible effect, as the symbol is transparent. It's only effect is ensure that myMarkValue is considered when choosing the y-axis scale. For the x-coordinate, it just choose an existing x-coordinate in your chart (any existing x-coordinate will do) to prevent the transparent point from extending the x-axis scale.
Hope this can help.
Regards
Peter Kwan |
Re: How to include marks outside of the axis range |
Posted by Jonathan on Aug-05-2011 02:40 |
|
Hi Peter,
Once I add a transparent scatterlayer after adding contourlayer as you suggested, my contour chart becomes a bit different though. I attach two charts: one without scatterlayer and the other with scatterlayer. Please see the area where 2<x<3 and 2<y<6. Any suggestions of how to fix this?
Thanks,
Jonathan
|
Re: How to include marks outside of the axis range |
Posted by Peter Kwan on Aug-06-2011 01:06 |
|
Hi Jonathan,
First, I see that the axis scale is changed. To avoid the axis scale from changing, please add the scatter layer first, followed by the contour layer.
By default, a scatter layer will try to extend the axis scale so as to maintain around 5% margin between the data points and the edge of the plot area. It is because the scatter symbol has finite size. If it is too close to the edge of the plot area, part of the symbol may go outside the plot area.
On the other hand, the contour layer will not extend the axis scale.
If both layers are used, whether the axis scale will be extended depends on which layer is added last. If the contour layer is added last, the axis scale will not be extended. (Another alternative is to use Axis.setAutoScale to explicitly configure axis scale extension.)
For the difference in the contour charts, the difference is due to the difference aspect ratio of the contour regions. For your particular case, as the axis scales are extended, the vertical direction is compressed more than the horizontal direction, thereby changing the aspect ratio. If you are plotting scatter data points with smooth interpolation, it is normal that the chart will change if the aspect ratio is different.
In a contour chart, the input is the z values at some scattered points. ChartDirector must determine the z-value of the entire region based on these points. Most standard algorithms for doing this depends on the distance among points. Consider a point X in the region. Its z-value depends on the data points near it. A data point near X will affect its z-value more than a data point far away. But what is "near" and "far" depends on the aspect ratio. If you compress the y-axis scale, a point that is vertically far away will become closer. That's why the z-value of the region depends on the aspect ratio.
Hope this can help.
Regards
Peter Kwan |
Re: How to include marks outside of the axis range |
Posted by Jonathan on Aug-12-2011 22:07 |
|
Hi Peter,
Adding the scatter layer first, followed by the contour layer works for my case.
Thanks for your help.
Jonathan |
|