|
How to get color of scatter layer |
Posted by Stephan Bielmann on Sep-09-2014 17:15 |
|
Hello all,
I am using CD 5.1, C++, and adding a scatter layer like this:
chart->addScatterLayer(xData,yData,name,symbol,size,color,color);
Later in the code, when I do no longer have access to the color variables,
I would like to retrieve the color that I used here, I have only access to the
chart, hence also it's layers and data sets. However the function:
dataSet->getDataColor();
for that layer simply gives me Chart::Transparent back ?
Is there another way to get the color used for the scatter layer? The color
of the symbols in that case.
Thanks for any help,
Stephan |
Re: How to get color of scatter layer |
Posted by Peter Kwan on Sep-09-2014 23:49 |
|
Hi Stephan,
The ScatterLayer is actually a specially configured LineLayer, with the line being
transparent and the line width being 0. (This is briefly mentioned in the addScatterLayer
documentation). The color retrieved from dataSet->getDataColor() is actually the line color,
which is transparent. There is no guarantee that the symbol can have any definite color
(eg. the symbol can be an imported image).
For your case, one method is to set the data color for the hidden line in the scatter layer.
The line should still be invisible because its line width is 0, but then you can use
getDataColor to obtain the color.
ScatterLayer *layer =
chart->addScatterLayer(xData,yData,name,symbol,size,color,color);
layer->getDataSet(0)->setDataColor(color);
Then later you can use the following code to retrieve the color:
int myColor = layer->getDataSet(0)->getDataColor();
Hope this can help.
Regards
Peter Kwan |
Re: How to get color of scatter layer |
Posted by Stephan Bielmann on Sep-10-2014 16:27 |
|
Hello Peter,
yes you are right this would work. However, I forgot to mention that I use symbols which are sometimes filled, and sometimes not. When not filled this approach will fail, because
layer->getDataSet(0)->setDataColor(color);
will also set the fill color, and then my symbols would be drawn filled instead.
Kind regards,
Stephan |
Re: How to get color of scatter layer |
Posted by Peter Kwan on Sep-10-2014 20:01 |
|
Hi Stephan,
Sorry for the misinformation. I have just checked. If you add the scatter layer using
addScatterLayer, the fill colors of the invisible line and the symbol will be the same color,
and getDataColor will return the fill color of the symbols. This is consistent with the
behaviour of getDataColor in all other layers. For example, in a bar layer, the getDataColor
returns the fill color of the bar (not the border color), and it is the same for an area chart,
etc.. So if the symbol fill color is transparent, it is normal getDataColor returns the
transparent color.
For your case, do you want getDataColor to return the border color instead?
You may consider the following code, which should work for your case:
// Do not specify any symbol in addScatterLayer
ScatterLayer layer = c.addScatterLayer(dataX, dataY, "ABC");
// use setDataSymbol to set the symbol
layer.getDataSet(0).setDataSymbol(Chart.CircleShape, 15, Chart.Transparent, 0xff0000);
// use setDataColor to set the color that you want to retrieve using getDataColor
layer.getDataSet(0).setDataColor(0xff0000);
Hope this can help.
Regards
Peter Kwan |
Re: How to get color of scatter layer |
Posted by Stephan Bielmann on Sep-10-2014 21:47 |
|
Hello Peter,
it was my error to not tell you about filling and transparency. Using this new approach
works in my case. Thank you very much for your help !
Kind regards, Stephan |
|