|
addLabel and addMark don't format values |
Posted by Lofi on Apr-09-2011 12:29 |
|
my task is the following:
* x-axis has some double values
* y-axis has values from 0 to 100
* i'm supposed to display the minimum label, the maximum label and the label in the middle explicitly, the other labels are ticks inbetween
problem #1: the formatting in the labels doesn't work.
neither for:
double median = dataX[dataX.length / 2];
c.xAxis().addMark( median, 0xFF0000, "{value}\\nMiddle");
nor for
double min = dataX[ 0];
c.xAxis().addLabel( min, "{xLabel}\\nMinimum");
nor for
double max = dataX[ dataX.length-1];
c.xAxis().addLabel( max, "{x}\\nMaximum");
i don't want to give the number directly as a label, because i figured that negative numbers are a problem because of the "-" formatter prefix
problem #2: the axis should be scaled precisely, auto-scaling is not wanted
i figured that i would have to set:
c.xAxis().setLinearScale( dataX[0], dataX[dataX.length - 1], Chart.NoValue);
to get precise scaling. however, with Chart.NoValue i have no ticks at all, which isn't good either
it would be great if you could help me! attached is a sample code and a picture of how it currently looks like.
thank you very much for your help!
|
Re: addLabel and addMark don't format values |
Posted by Lofi on Apr-11-2011 16:42 |
|
Hello,
before I search any longer, could you please let me know whether it's a bug in ChartDirector or if it it's a bug in my code?
Thank you very much! |
Re: addLabel and addMark don't format values |
Posted by Peter Kwan on Apr-11-2011 23:49 |
|
Hi Lofi,
The formatting template is only for the API setLabelFormat or setLabels2. In general, it is only used if you do not know what are the values to format (eg. the values may be picked by ChartDirector auto-scaling), or if you need to format multiple values. If you just need to format one value your code already know, your code can always format it.
For example, instead of using:
c.xAxis().addLabel( max, "{x}\\nMaximum");
you can use:
c.xAxis().addLabel( max, "" + max + "\\nMaximum");
The same applies to addMark.
Hope this can help.
Regards
Peter Kwan |
Re: addLabel and addMark don't format values |
Posted by Lofi on Apr-12-2011 00:36 |
|
Hello Peter,
thank you very much for your reply. By the way, I already tried your suggestion, but ran into troubles with:
c.xAxis().addLabel( max, "" + max + "\\nMaximum");
The "-" got deleted for negative numbers. After digging through the help file I figured it's because "-" is a special character. I guess I'll have to use a special check for that. I wanted to avoid that and hoped for a cleaner solution.
Thanks & Best regards
Lofi |
Re: addLabel and addMark don't format values |
Posted by Peter Kwan on Apr-12-2011 17:36 |
|
Hi Lofi,
I see. May be you can try:
c.xAxis().addLabel( max, "<*font*>" + max + "\\nMaximum");
The CDML tag <*font*> should have no effect, and its purpose is to make sure the first character is not "-".
Hope this can help.
Regards
Peter Kwan |
Re: addLabel and addMark don't format values |
Posted by Lofi on Apr-13-2011 00:45 |
|
Hello Peter,
thank you very much, that's a good workaround.
Best regards
Lofi |
|