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

Message ListMessage List     Post MessagePost Message

  Label color is displayed incorrectly.
Posted by choynsg on Mar-12-2023 19:58
Hello, Peter

int color = 16711680; // 0xff0000;
std::ostringstream tmp;
tmp << std::hex << color;
label << "<*font,bgColor=" << tmp.str().c_str() << "*> "
<< c->formatValue(dataSet->getValue(xIndex), "{value|P4}") << " <*font*>";

tmp << std::hex << color;
The expected result here is tmp is ff0000.

However, incorrect results are obtained with "," (comma) inserted to separate thousands, such as tmp is ff0,000.

What is the fixed code to get the correct result?

Regards
Cho

  Re: Label color is displayed incorrectly.
Posted by Peter Kwan on Mar-13-2023 01:01
Hi Cho,

I believe all C/C++ programs would use the "C" locale by default. (The "C" locale means the number are expressed in the C language syntax, which is without thousand separators.) For your case, the default locale may have changed to some other region.

You may try to set the locale to "C" explicitly to see if it can solve the problem.

tmp.imbue(std::locale("C"));
tmp << std::hex << color;

Please kindly let me know if this works for your case.

Best Regards
Peter Kwan

  Re: Label color is displayed incorrectly.
Posted by choynsg on Mar-13-2023 09:07
Hello, Peter

int color = 16711680; // 0xff0000;
std::ostringstream tmp;

1st try :

tmp.imbue(std::locale("C"));
tmp << std::hex << color;

This result is tmp is ff0000ff0000. // data repeated


2nd try :

tmp.imbue(std::locale("c"));  // lowercase c
tmp << std::hex << color;

This result is tmp is ff0000ff0,000. // inserted thousand separator

Sorry but not resolved yet.

Regards
Cho

  Re: Label color is displayed incorrectly.
Posted by Peter Kwan on Mar-13-2023 14:20
Hi choynsg,

Is it possible to run the following test code. (Please change the filename at the last line to a directory in your computer.)


XYChart* c = new XYChart(300, 300);

int color = 16711680; // 0xff0000;
std::ostringstream tmp;
tmp.imbue(std::locale("C"));
tmp << std::hex << color;

c->addTitle(tmp.str().c_str());
c->makeChart("c:/path/to/aaa.png");


The code above should display the color in hex in the chart title. The chart should be saved in "aaa.png". Please look at the "aaa.png" to verify what is the color.

Also, please kindly let me know which operating system and development tools you are using (eg. windows/visual studio or linux/Qt Creator, etc), and how do you know the output is ff0000ff0000 (is it by looking at the debugger or print it out somewhere)? For the STL, are you using the STL that comes with the development environment, or is it a third party STL?

The problem is not related to ChartDirector, but to the STL that is not working as expected. There is also an alternative method to create hex strings without using C++ (just pure C code). It is:

char tmp[20];
snprintf(tmp, 20, "%x", color);


Best Regards
Peter Kwan