|
Use whole yAxis? |
Posted by Chris on Dec-20-2010 18:54 |
|
Hi there, it's me again
I got a Stacked-Bar-Chart with a maximum y-value of 119734770. But Chartdirector draws
the y-Axis to 200000000, although it does not use this space. It seems to me like a waste
of PlotArea (see attachment).
How can I make ChartDirector use the whole yAxis, i.e. use a maximum of 120000000 (for
example)?
Thanks,
Chris
|
Re: Use whole yAxis? |
Posted by Peter Kwan on Dec-21-2010 02:49 |
|
Hi Chris,
If the axis is auto-scaled by ChartDirector, it will use the following method:
(a) ChartDirector will determine the label spacing in data units (configurable using Axis.setTickDensity). For example, it may decide that there should be one label per 100000000 units. Note that ChartDirector will only use "nice" number for labels. For example, it will not choose one label per 103957180.903 units, as this number is not "nice".
(b) ChartDirector will then label the axis with the minimum amount of labels, so that it contains all the data. For example, if the maximum data value is 123456789, it may use (0, 100000000, 200000000) as the labels. Note that ChartDirector will not terminate the axis at a non-labelled position (eg. it will not terminate the axis at 123456789 or 130000000, as they are not labelled position). This is configurable using Axis.setRounding.
For your case, have you configured ChartDirector to use wider label spacing, or set the axis scale yourself using setLinearScale? I would think by default, ChartDirector should put more labels on the axis. It seems instead ChartDirector decides the label spacing should be 200000000. In this case, only one label (other than 0) is enough for the whole axis, so you get an axis (0, 200000000).
ChartDirector will not choose 120000000 as the label spacing, because it means the labels (in case more than 1 label is needed for the axis) would be 120000000, 240000000, 360000000, ...., which is not "nice". So 120000000 is not considered as a "nice" number of label spacing purpose. ChartDirector may use 120000000 as one of the labels if the label spacing is 20000000, in which case the axis labels will be (0, 20000000, 400000000, .... 120000000), but your axis may not be long enough for so many labels.
For your case, some suggestions are:
(a) Use default label spacing. I speculate ChartDirector will choose 50000000 as the label spacing, in which case your axis will be (0, 50000000, 100000000, 150000000).
(b) You may set the axis scale with your own code, like:
c.yAxis().setLinearScale(0, 120000000, 120000000)
Of course, in your real code, you need to compute the maximum value based on your data (instead of hard coding it).
Hope this can help.
Regards
Peter Kwan |
Re: Use whole yAxis? |
Posted by Chris on Dec-21-2010 15:40 |
|
Thanks for your help. I set the scaling manually via "setLinearScale". The y-Maximum is
now a "non-nice-number", put that's perfectly ok with me. At least no more waste of
space...
Peter Kwan wrote:
For your case, have you configured ChartDirector to use wider label spacing, or set the
axis scale yourself using setLinearScale?
Nothing of this i think. Here's the code:
my $actual_chart = new XYChart($style->{width}, $style->{height}, $style->{bgcolor},
$style->{bordercolor}, $style->{border3D});
$actual_chart->setRoundedFrame();
$actual_chart->getPlotArea()->setBackground($style->{plot_area_bgcolor}, $style->
{plot_area_alt_bgcolor}, $style->{plot_area_edge_color});
$actual_chart->getPlotArea()->setGridColor($style->
{plot_area_horizontal_gridlines_color}, $style->{plot_area_vertical_gridlines_color});
$actual_chart->addTitle($execution_result->format_value(), $style->{title_font_name},
$style->{title_font_size})->setBackground($style->{title_bgcolor},
$style->title_bgcolor2}, $style->{title_effect});
$actual_chart->addLegend($style->{legend_x}, $style->{legend_y},
$style->{legend_layout}, $style->{legend_font_name}, $style->{legend_font_size})
->setBackground($style->{legend_bg});
$actual_chart->xAxis()->setLabels($chart_x_labels);
Afterwards, I added data via $layer->addDataSet()
Best Regards,
Chris |
Re: Use whole yAxis? |
Posted by Peter Kwan on Dec-21-2010 16:06 |
|
Hi Chris,
In your code, there does not seem to be a line that sets the plot area size.
ChartDirector needs the plot area size to determine the axis scale, because which label spacing to use depends on how many labels can be fit onto the axis.
Are you are using "packPlotArea" to "adjust" the plot area size? In this case, the following happens:
To pack the plot area, ChartDirector needs to know the labels on the axis. As explained above, to know the labels on the axis, ChartDirector needs to know the plot area size first. If the plot area size is not specified, ChartDirector may assume a small default height, and decides that there is only sufficient space for 2 labels. After it determines the labels, it "adjusts" the plot area size based on the labels.
That's why in our sample code, even if we use packPlotArea to "adjust" the plot area size, we must still provide an initial estimate of the plot area size, so ChartDirector can determine the labels. This may explain why there are only two labels in your current case.
Anyway, if having two labels and using a non-nice-number is acceptable for your case, you may use:
$c->yAxis()->setLinearScale(0, $maxValue, $maxValue);
Hope this can help.
Regards
Peter Kwan |
|