ASE Home Page Products Download Purchase Support About ASE
ChartDirector Support
Forum HomeForum Home   SearchSearch

Message ListMessage List     Post MessagePost Message

  Unable to precisely control axes scales with setLinearScale()
Posted by Ben Jones on Oct-11-2011 16:09
Attachments:
Hello, I'm hoping you can help me. I'm using ChartDirector to create scatterplots and having
difficulty forcing the x and y axes to use the same scale. Please see the attached
screenshot to see what I mean.

I am using setLinearScale() to explicitly set the x and y axes to the greatest value of either
x or y coordinates - rounded up to the nearest 10 as so.

$c->setClipping(0);
$max = max(array(max($xs), max($ys)));
$max = ceil($max/10) * 10;
$c->xAxis()->setLinearScale(0,$max);
$c->yAxis()->setLinearScale(0,$max);

However, the axis are not always scaled as I require. I'm guessing that some algorithm is
being applied within the method but I must have complete control over this scaling and it is
essential that x and y axes are scaled the same. I've found that rounding to the nearest 50
tends to ensure the scales are equal but I'd rather have finer control than this.

Is there some other code I can use to ensure the scales are the same?

Kind Regards

Ben
scatterplot example.png

  Re: Unable to precisely control axes scales with setLinearScale()
Posted by Peter Kwan on Oct-12-2011 01:13
Hi Ben,

To completely control the axis scale, you may use one of the following methods:

(a) Specify all 3 parameters in setLinearScale. For example:

$c->xAxis()->setLinearScale(0, $max, 20);
$c->yAxis()->setLinearScale(0, $max, 20);

(b) If you set only two parameters (0 and $max), and letting ChartDirector automatically determine the tick density, ChartDirector by default will auto-adjust the $max to ensure the axis ends at a label position.

For example, suppose you set $max = 130. ChartDirector may decide that it is not sufficient space for a label every 10 units. So it may put a label every 20 units. But then the $max must be adjusted to 140 to ensure it ends at a label position.

By default, for the x-axis, ChartDirector will assume each label needs 50 pixels (called the tick density in ChartDirector), while on the vertical axis the label needs 20 pixels. (Because text flows horizontally, the width of a label is usually larger than its height. So more space per label is required on a horizontal axis.)

To ensure the axis scale is exactly what you set, you can ask ChartDirector not to adjust the $max using Axis.setRounding. In this case, the axis end points may not be at a label position.

$c->yAxis()->setRounding(false, false);
$c->xAxis()->setRounding(false, false);

Alternatively, if both the x-axis and y-axis are of the same length, and you use the same tick density (configurable using Axis.setTickDensity), ChartDirector should adjust them in exactly the same way, and you can get the same scale (though they may not be 0 to $max).

$c->xAxis()->setTickDensity(50);
$c->yAxis()->setTickDensity(50);

Hope this can help.

Regards
Peter Kwan