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

Message ListMessage List     Post MessagePost Message

  full number format support
Posted by Nara Bayarsaikhan on Oct-02-2013 05:41
Hi,

I can format numbers with different decimal, thousand marks. It would be good if I can get the full number format support in our charts. 3-digit group is used for most cultures including english (United States). However, there is 2-digit group is used for Hindu except the hundreds. For example: 89,66,150.00. Are we able to do it via Chart director api? Also, negative sign can be placed differently depending on the culture. For example, -35 or 35-

Regards,
Nara

  Re: full number format support
Posted by Peter Kwan on Oct-02-2013 21:02
Hi Nara,

Whereas there is no built-in support for all the possible formatting in the world, there are methods for custom formatting. The exact details depend on what types of labels you are referring to and whether the labels are specified by your code or are automatically generated by ChartDirector.

For example, consider the y-axis labels on an auto-scaled axis, of which the labels are automatically generated by ChartDirector. In PHP, the code structure may be like:

.... create the chart as usual ....

# Ask ChartDirector to auto-scale the axis by laying out the chart
$c->layout();

# Now you can ask ChartDirector what are the label positions on the y-axis
$ticks = $c->yAxis->getTicks();

for ($i = 0; $i < count($ticks); ++$i)
   $c->yAxis->addLabel($ticks[$i], myFormattingFunction($ticks[$i]));

In the above, the myFormattingFunction is a function that you write. The function accepts a numeric input, and returns a text string. Your code is free to format the number into a text using any method you like. The above code then adds that text string to become the label on the axis.

Hope this can help.

Regards
Peter Kwan

  Re: full number format support
Posted by Nara Bayarsaikhan on Oct-04-2013 03:02
Hi Peter,

Thanks for the quick reply. It is all numbers in the labels including X,Y Axis, bar label, area label, Image Map label etc.

I am using formatString used as an input for formatValue() and setLabelFormat(). For example: {value|0.,} to substitute the decimal and the thousand separators.

So you mean, as you example, I can use my custom function that returns a string label for the automatically generated labels instead of using formatString.

- Nara

  Re: full number format support
Posted by Peter Kwan on Oct-04-2013 23:46
Hi Nara,

ChartDirector has API that allows you to specify the labels to use. You can ask ChartDirector to automatically generate the labels, but if the format is not suitable for your case, you can always ask ChartDirector to use the labels you specified.

For example, consider the bar labels of a simple bar chart. You can ask ChartDirector to automatically put a label on top of the bar, in which the label is the data value formatting in a certain way. An example is:

$layer->setDataLabelFormat("{value|0.,}");

However, if none of the formatting options are suitable for your case, you can also supply the list of labels you want to use. An example is:

$barLabels = array("high", "medium", "high", "low", "one hundred", "134");

$layer->addExtraField($labels);
$layer->setDataLabelFormat("{field0}"); #use the extra field as the label

You are free to generate the bar labels using any methods you like. For example, you can use your own formatting function to format the data values to create the labels.

Similarly, you can ask ChartDirector to the extra field as in the image map by specifying {field0}.

Note that ChartDirector never calls or use the custom function. It is the user's code that calls the custom function to generate the labels. ChartDirector receives the labels and include them in the chart.

Hope this can help.

Regards
Peter Kwan