|
Stepline Area layers |
Posted by L on Sep-15-2011 06:41 |
|
Hello,
I'm wondering what is the right way to do a stepline area chart. I want the chart to look as
close as possible to a standard area layer, but I can't figure out how to do it right.
There is no stepline area layer, so it seems using a markline and an interline layer is the only
option. Unfortunately, my data is not always baselined at 0, so generating the markline
isn't trivial. A standard area layer of the same data would fill in below the y axis min
(assuming it is baselined at 0) but not affect the y axis autoscaling. That looks perfect.
Anything I do to mimic that behavior with a stepline seems to throw off my y axis
autoscaling. It's possible that some combination of laying out the axes and then creating
the markline at yAxis().minValue() might work, but the layout methods are problematic for
me at this point in the chart creation. I can continue to investigate if that is my only
option, but I figured I would ask.
If it is a matter of having to use the y axis min, which can only be called after an axes
layout, what is allowed after layout is called? Is it ok to continue adding data to a chart
after (the markline would not be on at this point)? Can I format the x axis after? I am
confused about what is allowable. If I do an axes layout and then add the markline at the y
axis min, won't that affect my autoscaling? Is there a way to flag that a layer should be
ignored by the axis scaling?
thanks!
L |
Re: Stepline Area layers |
Posted by Peter Kwan on Sep-15-2011 23:26 |
|
Hi L wrote,
You can add the mark line at y = 0 or y = -999999999, depending on exact what you want. (To reproduce the same behaviour of the area layer, you should use y = 0.)
ChartDirector auto-scaling will only consider the data in the layers. So the position of the mark line will not affect auto-scaling. The y-axis scale will be determined based on your data only. This also means the mark line can be outside the y-axis scale and may not be actually drawn.
When you fill between the data line and the mark line, ChartDirector will fill the region between the data line and the mark line. If the mark line is outside the plot area and not actually drawn, ChartDirector will still fill until it reaches the border of the plot area.
In a true area layer, the baseline by default is 0. Like the mark line, the base line is not considered in auto-scaling, so it is possible the baseline can lie outside the plot area. In this case, ChartDirector will fill until it reaches the border of the plot area. So using a y = 0 mark should reproduce the same behaviour as the area layer.
Hope this can help.
Regards
Peter Kwan |
Re: Stepline Area layers |
Posted by L on Sep-16-2011 02:25 |
|
Hi Peter,
Thanks so much for your response. That makes sense. So the reason I am seeing the y
axis autoscale is because sometimes I am using a data layer for the mark line instead of an
actual markline, and drawing the interline layer between the two data layers. I'm doing this
primarily in instances where I don't have data across the whole x axis, so I don't want the
markline extending visibly across the whole chart. To me, it's deceiving to have the
markline across the entire x range if there is no data there (and that's not how the
comparable area chart would look). So what I will have to do is zero affinity test the y
range to determine if 0 is visible, in which case it should be safe to use a data layer as the
marker, but otherwise I can generate a markline at 0. Unless, of course there is a way to
generate a markline over only a particular x range, but that seems unlikely.
thanks again,
L |
Re: Stepline Area layers |
Posted by L on Sep-16-2011 03:29 |
|
Hi again,
I was able to make the changes I described and the markline is working great in all cases
now. One other quick question. I'm using a dark color for the data set and a lighter color
to fill the area. In cases where the data does not fill the entire x range, the area layer will
bound the data in the darker color. The stepline's interline layer, however, will not do so --
it will fill with the lighter color but will not create a vertical line in the darker color at the
xmin and xmax the way the area layer does. It's not a huge problem, but it becomes
obvious when bursts are drawn on top of each other. Is there any way to force the
interline layer to bound the area in the darker color? I thought border color might do it but
it doesn't seem to.
thanks!
L |
Re: Stepline Area layers |
Posted by Peter Kwan on Sep-17-2011 00:47 |
|
Hi L,
I see that sometimes your code need to use a data layer as the baseline, instead of a mark line, and you are worry that the data layer can affect the auto-scaling. There are two methods to use add a data layer without affecting auto-scaling:
(a) Call "c.layoutAxes()", then add the baseline layer and the interline layer. The "c.layoutAxes" auto-scales the axis, and it can only use data in layers that are added before the axis is auto-scaled. So the baseline layer and the interline layer will not affect auto-scaling if they are added after "layoutAxes".
(b) Call "c.yAxis().setLinearScale(lowerLimit, upperLimit)". You may obtain the lowerLimit and the upperLimit by computing them from your real stepline data. In this case, ChartDirector will use lowerLimit, upperLimit to auto-scale the axis.
However, in your second message, you mention that you want to "bound the area in the darker color" like a real area layer. Considering this requirement, and the effort to create the baseline above, I think it is easier to just use a real area layer. You just need to modify your data so that the data line contains steps.
For example, suppose your original data are:
dataY = {10, 20, 40, 80}
dataX = {1, 2, 3, 4}
You can create another series:
adjustedDataY = {10, 10, 20, 20, 40, 40, 80}
adjustedDataX = {1, 2, 2, 3, 3, 4, 4}
You can then use it to create your area layer (eg. in C#/Java):
AreaLayer layer = c.addAreaLayer(adjustedDataY, ....);
layer.setXData(adjustedDataX);
If you are not using dataX or setXData in your original code, then you may consider the original x-coordinates to be the array index 0, 1, 2 ,3, .... So if your original dataY is:
dataY = {10, 20, 40, 80}
Then the adjusted data are:
adjustedDataY = {10, 10, 20, 20, 40, 40, 80}
adjustedDataX = {0, 1, 1, 2, 2, 3, 3}
Hope this can help.
Regards
Peter Kwan |
|