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

Message ListMessage List     Post MessagePost Message

  '@' character in axis format string not working
Posted by Taylor on Dec-18-2013 07:21
Here is what the documentation says:

"For Axis label formatting, the special character "@" can be used. It means to use a fixed
number of decimal places automatically determined by the Axis object. For example, if the
axis labels are 0, 0.5, 1, 1.5, 2, the Axis object may decide to use 1 decimal place, in
which case the labels will become 0.0, 0.5, 1.0, 1.5, 2.0."

However, this isn't working as expected...

Say I have an axis which would normally have the following values:

0.11
0.1
0.09
0.08
0.07

I would expect that, when using "@", I would see:

0.11
0.10
0.09
0.08
0.07

But instead I get

0
0
0
0
0

Is there any to get what I want? I would set the precision myself, but that would require
knowing how the auto-scale (which I am using) will space the tick marks.

  Re: '@' character in axis format string not working
Posted by Peter Kwan on Dec-19-2013 00:41
Hi Taylor,

The "@" is the default for an auto-scaled axis. So you should not need to set it, but setting it causes no harm.

I have just tested with the following code, and it works normally.

double data[] = {0.85, 1.56, 1.795, 2.11, 1.23};
XYChart *c = new XYChart(250, 250);
c->setPlotArea(30, 20, 200, 200);
c->addLineLayer(DoubleArray(data, (int)(sizeof(data) / sizeof(data[0]))));
c->yAxis()->setLabelFormat("@");
c->makeChart("test.png");

The axis labels produced by the above code is 0.0, 0.5, 1.0, 1.5, 2.0, 2.5. The same labels are produced without the setLabelFormat("@") line.

For your case, is it possible you have another line of code that sets the label format to integers? Does your code call setLabelFormat more than once with different format strings?

If the above still cannot solve the problem, is it possible to create a sample code with hard coded data (you may modify my code if you like) that can demonstrate the problem?

Regards
Peter Kwan

  Re: '@' character in axis format string not working
Posted by Taylor on Dec-19-2013 00:54
Hi Peter,

I guess I should have mentioned, I'm also applying a multiplier to the axis values. I do this
so I can use the same data, but display the axis markers in different metric units (kilo,
mega, giga, etc.). For an minimal example that reproduces my problem, try this:

double data[] = {0.85, 1.56, 1.795, 2.11, 1.23};
XYChart *c = new XYChart(250, 250);
c->setPlotArea(30, 20, 200, 200);
c->addLineLayer(DoubleArray(data, (int)(sizeof(data) / sizeof(data[0]))));
c->yAxis()->setLabelFormat("{={value}*0.1|@}");
c->makeChart("test.png");

When I do this, the markers are:

0.3
0.2
0.2
0.1
0.1
0.0

  Re: '@' character in axis format string not working
Posted by Peter Kwan on Dec-19-2013 23:35
Hi Taylor,

The "@" is determined from the original label value. If you manipulated the values or labels, it would be hard for ChartDirector to take this into account when determining "@".

For example, someone could format the values as "{value}/12" (eg. eg. to change from inches to feet). In this case, it is quite possible for the formatted values to contain an infinite number of decimal places, and it would be hard to know the precision the user expects. On the other hand, the original label values chosen by ChartDirector auto-scaling always contain finite number of decimal places, so "@" can be determined.

For your case, you may use your own formatted function or code to achieve what you need. The method is:

XYChart *c = new XYChart(250, 250);
c->setPlotArea(30, 20, 200, 200);
c->addLineLayer(DoubleArray(data, (int)(sizeof(data) / sizeof(data[0]))));

// after entering all the data, ask ChartDirector to auto-scale axis
c->layoutAxes();

// Obtain the label values chosen by ChartDirector
DoubleArray values = c->yAxis()->getTicks();

// Use addLabel to specify the labels for those values. This will override the labels
// chosen by ChartDirector.
for (int i = 0; i < values.len; ++i)
    c->yAxis()->addLabel(values.data[i], myFormatFunction(values.data[i]));

Hope this can help.

Regards
Peter Kwan

  Re: '@' character in axis format string not working
Posted by Taylor on Dec-20-2013 00:39
Ok, that works!

I had tried doing a similar thing, calling layoutAxes() and then setLabelFormat(), but this
resulted in labels which were the plain, unformatted values. But addLabel() seems to work.

I don't quite understand why; are there certain methods that can't be called after
layoutAxes(), and certain methods that can?

By the way, thank you for your fast and accurate replies to my questions. I'm very
impressed with the ChartDirector support. :)

  Re: '@' character in axis format string not working
Posted by Peter Kwan on Dec-20-2013 03:45
Hi Taylor,

The purpose of layoutAxes is to auto-scale and layout the axis. After layoutAxes, you can know the axis scale, label positions, the label text, axis thickness, etc.. So you can only know the label positions after layoutAxes. This also means ChartDirector must generate all the labels based on the existing label format during layoutAxes. As a result, setLableFormat has no effect after layoutAxes because the labels have already been created.

The Axis.addLabel can be used before or after layoutAxes. However, if the axis scale are later redefined (such as using setLinearScale or during auto-scaling), the previous labels will be wiped way. So if you would like to use Axis.addLabel before layoutAxes, you would need to define the axis scale first, such as using Axis.setLinearScale or Axis.setLinearScale2.

(Normally, axis labels depend on the axis scale. To add axis labels, the developer should have known what the axis scale is. This means the axis scale is either set by the developer (eg. using setLinearScale, setLogScale, etc), or the addLabel is called after layoutAxes, at which time the code can ask ChartDirector for the axis scale.)

Hope this can help.

Regards
Peter Kwan