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

Message ListMessage List     Post MessagePost Message

  How convert int color to corresponding ARGB ?
Posted by John Vella on Apr-08-2024 04:27
Is it possible to convert the int color returned from an api like DataSet.getDataColor and end up getting that value shown as a string showing #ARGB?

I'm trying to dump the chart textually and want ARGB as it's much easier to understand what the color is than looking at an INT.

Thanks,
-John

  Re: How convert int color to corresponding ARGB ?
Posted by Peter Kwan on Apr-08-2024 15:28
Hi John,

You can convert any integer to ARGB. It is just an integer display in hex format. In C/C++, you can use sprintf to format a number to a text string. For example:


char buffer[1000];
sprintf(buffer, "#%08X", anyInteger);


The integer will then be formatted as a text string #AARRGGBB stored in the buffer.

Best Regards
Peter Kwan

  Re: How convert int color to corresponding ARGB ?
Posted by John Vella on Apr-08-2024 22:01
I'm sorry Peter but I don't think what I'm getting from CD in DataSet.getDataColor is an actual valid color. In my small test chart I have 5 lines, each having colors very close to either primary red, green, or blue. When iterating through the datasets with the following code:

char buf[1000];
sprintf(buf, "#%08X", ds->getDataColor());
qDebug() << "COLOR(INT)" << ds->getDataColor() << "COLOR(AARRGGBB)" << buf;


here's the output I see (I'm expecting AARRGGBB strings holding a color that is clearly red-ish, green-ish or blue-ish):

COLOR(INT) -131071 COLOR(AARRGGBB) #FFFE0001
COLOR(INT) -131070 COLOR(AARRGGBB) #FFFE0002
COLOR(INT) -131069 COLOR(AARRGGBB) #FFFE0003
COLOR(INT) -131068 COLOR(AARRGGBB) #FFFE0004
COLOR(INT) -131067 COLOR(AARRGGBB) #FFFE0005

as you can see, those colors above are NOT what I see in the chart. So are the int values really just some unique id maintained internally by CD?

  Re: How convert int color to corresponding ARGB ?
Posted by John Vella on Apr-08-2024 22:01
I'm sorry Peter but I don't think what I'm getting from CD in DataSet.getDataColor is an actual valid color. In my small test chart I have 5 lines, each having colors very close to either primary red, green, or blue. When iterating through the datasets with the following code:

char buf[1000];
sprintf(buf, "#%08X", ds->getDataColor());
qDebug() << "COLOR(INT)" << ds->getDataColor() << "COLOR(AARRGGBB)" << buf;


here's the output I see (I'm expecting AARRGGBB strings holding a color that is clearly red-ish, green-ish or blue-ish):

COLOR(INT) -131071 COLOR(AARRGGBB) #FFFE0001
COLOR(INT) -131070 COLOR(AARRGGBB) #FFFE0002
COLOR(INT) -131069 COLOR(AARRGGBB) #FFFE0003
COLOR(INT) -131068 COLOR(AARRGGBB) #FFFE0004
COLOR(INT) -131067 COLOR(AARRGGBB) #FFFE0005

as you can see, those colors above are NOT what I see in the chart. So are the int values really just some unique id maintained internally by CD?

  Re: How convert int color to corresponding ARGB ?
Posted by Peter Kwan on Apr-09-2024 01:58
Hi John,

Your color is likely using some kind of positional colors, such as the gradient colors, pattern colors, zone colors, dash line color, etc.. Positional colors are colors that can change depending on which pixel it is used on, so they cannot be represented as ARGB. The #FFFE0001 is a number ChartDirector internally used to keep track of the colors. It means the second positional color defined in your code. (The first is #FFFE0000.)

Unluckily, there is no function to obtain a textual description of the positional color, which can be very complex. (A x-zone color can contain a gradient color with 10 color stops on the left side and a pattern color on the right side, and the pattern color can contain a pattern with 500 x 500 pixels = 250000 ARGB colors...).

Best Regards
Peter Kwan