|
Bar-like Chart That Is Not Zero-Based On Axis |
Posted by Chris Burriss on May-02-2012 00:29 |
|
I need to center a bar along a horizontal line. I seems if I could set the value from 0.25 and
0.75, for instance, and have the axis run at 0, 0.5, and 1 that it'd do what I need.
However, I haven't had any success with this. Is it possible to pass a value that includes a
starting value and an ending value? Please see the circled area in the attached file for an
example of what I'm trying to do. Thanks!
|
Re: Bar-like Chart That Is Not Zero-Based On Axis |
Posted by Peter Kwan on May-02-2012 23:53 |
|
Hi Chris,
The chart you need is quite similar to the "Binary Data Series" sample code included in ChartDirector. May be you can use it as a reference.
In the "Binary Data Series" sample code, the "blocks" are achieved by using step line layers with interline filling (using InterLineLayer). This allows you to control the position, height and width of individual blocks.
If all the blocks are of the same width, you can also use a bar layer. May be you can use something like (as I am not sure of your programming language, I will use Java in the following example):
//set the axis scale as -3 to 5, with 3 labels (so the labels will be at -3, 1 and 5). Only
//the middle label is non-empty (it is a space character) so as to create a grid line there.
c.yAxis().setLinearScale2(-3, 5, new String[] { "", " ", "" });
//the data values must be either 2 or Chart.NoValue
BarLayer layer = c.addBarLayer(myData, ....);
layer.setBarWidth(myWidth);
The above should work because by default, the bar starts from 0. So the entire bar must be from 0 to 2, and this means the bar centers around the grid line (which is at 1), and the grid line is in the middle of the chart (as the axis scale is -3 to 5).
Hope this can help.
Regards
Peter Kwan |
Re: Bar-like Chart That Is Not Zero-Based On Axis |
Posted by Chris Burriss on May-03-2012 09:27 |
|
That worked beautifully. Thanks a million. |
|