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

Message ListMessage List     Post MessagePost Message

  Number formatting and character encoding
Posted by Serge on Feb-21-2012 13:19
Hi Peter,

According to CD help, text strings should be passed in UTF-8 encoding. This doesn't seem to work with setLabelFormat method to specify a custom number formatting.

For example, let's say I want a bullet (?) symbol (ASCII code 149) to be used as a thousand separator. UTF-8 encoding for this character is E2 80 A2 (hex).

   yaxis->setLabelFormat( "{value|2\\xE2\\x80\\xA2}" );

It looks like CD interprets this call as if E2 is the thousand separator, 80 - decimal point character, and A2 - negative sign character.

Is it a bug or am I missing something?

  Re: Number formatting and character encoding
Posted by Peter Kwan on Feb-23-2012 00:21
Hi Serge,

Unluckily, this is caused by a limitation in ChartDirector. For ChartDirector for C++, the character for the thousand separator, decimal separator and the sign character must be of type "char" (which means it must be one byte).

If you need to use a character that cannot be represented as one byte, the only method is by using "custom formatting" of the label. In custom formatting, you would need to use your own code to format the number, and it can format it in anyway you like. The result of the formatting should be a text string in UTF8.

In custom formatting, the code structure should be like:

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

//auto-scale the axis
c->layoutAxes();

//get the tick position on the y-axis
DoubleArray ticks = c->yAxis()->getTicks();

for (int i = 0; i < ticks.len; ++i)
    c->yAxis()->addLabel(ticks.data[i], myFormatFunction(ticks.data[i]));

In the above example, myFormatFunction should be declared as "const char *myFormatFunction(double v);". It outputs a UTF8 text string as the formatted representation of the input value v.

Regards
Peter Kwan