|
Line Multicolor |
Posted by Andrea on Feb-04-2014 22:05 |
|
Hi Peter,
I have a question to paint line multicolor:
Suppose we want to draw the line image.
It consists of 6 points. When the line is flat or 'up' is green, when it is 'down' is red.
I created 2 doublearray, one for green and one for red and I loaded them in the chart:
double Up[] = {10,10,20,15,30,40}
double Down[] = {Chart :: NoValue, Chart :: NoValue, 20,15, Chart :: NoValue, Chart ::
NoValue}
DoubleArray l_daUp DoubleArray = (Up, 6);
DoubleArray l_daDown = DoubleArray (Down 6);
c-> addLineLayer (l_daUp, l_UpColor);
c-> addLineLayer (l_daDown, l_DownColor);
The problem is that both arrays contain the values 20 and 15 in the same position, so the
chart draw the green and the red line one above the other.....
can you help me?
|
Re: Line Multicolor |
Posted by Peter Kwan on Feb-04-2014 23:14 |
|
Hi Andrea,
For your case, instead of using 2 layers, you need 4 layers to make it work. See:
http://www.chartdir.com/forum/download_thread.php?
bn=chartdir_support&thread=1243334180#N1243423236
The example above is written in Python. When translate to C++, I think the code should
be like:
vector<double> redLine[] = { vector<double>(6, Chart::NoValue), vector<double>(6,
Chart::NoValue) };
vector<double> greenLine[] = { vector<double>(6, Chart::NoValue), vector<double>(6,
Chart::NoValue) };
for (int i = 0; i < count; ++i) {
((data[i - 1] >= data[i]) ? redLine : greenLine)[(i % 4) / 2][i - 1] = data[i - 1];
((data[i - 1] >= data[i]) ? redLine : greenLine)[(i % 4) / 2][i] = data[i];
}
LineLayer *layer = c->addLineLayer();
for (int i = 0; i < 2; ++i) {
layer->addDataSet(DoubleArray(&(redLine[i][0]), count), 0xff0000);
layer->addDataSet(DoubleArray(&(greenLine[i][0]), count), 0x008800);
}
(*** NOTE ***: I translated the code but have not tested the translated code.)
Hope this can help.
Regards
Peter Kwan |
Re: Line Multicolor |
Posted by Andrea on Feb-05-2014 00:34 |
|
Works perfectly!
Many Thanks Peter. |
|