|
XY graph multi color drawing |
Posted by HS.Kwon on Jul-29-2020 10:19 |
|
Hi Peter!
ChartDirctor is a really cool program.
The programming environment is done in the MFC dialog base.
I am trying to draw a picture like the attached picture.
The graph color is a total of six colors.
Color may vary depending on conditions.
I am trying to do the program below.
double data1[];
double data2[];
double data3[];
double data4[];
double data5[];
double data6[];
int Colr_black = layer->xZoneColor(0, 0x000000,0);
int Colr_Green = layer->xZoneColor(5, 0x00ff00,0);
int Colr_Blue = layer->xZoneColor(10, 0x0000ff,0);
int Colr_Purple = layer->xZoneColor(15, 0x660066,0);
int Colr_Red = layer->xZoneColor(20, 0xff0000,0);
int Colr_Pink = layer->xZoneColor(25, 0xFF66FF,0);
layer->addDataSet(DoubleArray(data1, (int)(sizeof(data1) / sizeof(data1[0]))), Colr_black, "CASE1");
layer->addDataSet(DoubleArray(data2, (int)(sizeof(data2) / sizeof(data2[0]))), Colr_Green, "CASE2");
layer->addDataSet(DoubleArray(data3, (int)(sizeof(data3) / sizeof(data3[0]))), Colr_Blue, "CASE3");
layer->addDataSet(DoubleArray(data4, (int)(sizeof(data4) / sizeof(data4[0]))), Colr_Purple, "CASE4");
layer->addDataSet(DoubleArray(data5, (int)(sizeof(data5) / sizeof(data5[0]))), Colr_Red, "CASE5");
layer->addDataSet(DoubleArray(data6, (int)(sizeof(data6) / sizeof(data6[0]))), Colr_Pink, "CASE6");
I would like to approach the program in this way, but I would like to listen to your opinion and make the program more efficient.
Thank.
|
Re: XY graph multi color drawing |
Posted by Peter Kwan on Jul-29-2020 12:39 |
|
Hi HS.Kwon,
In your attached chart, the color of the lines are not continuous. It has 5 colors. but there are 11 segments. For example, the red color line is separated into 4 segments.
The xZoneColor is used if if there are two colors depending on a threshold value. For example, if the color is red (0xff0000) when x <= 20, and blue (0x0000ff) when x > 20, then you can layer->xZoneColor(20, 0xff0000, 0x0000ff). For your case, because the color segments can be separated, so xZoneColor is not the best method.
Below is an example of a multi-color line. The dataX and dataY are the x and y coordinates of the data points. The pointType specifies the type of data point. (There are 4 types in the example below). Each pointType has a different color.
double dataX[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25};
double dataY[] = {30, 28, 40, 55, 75, 68, 54, 60, 50, 62, 75, 65, 75, 91, 60, 55, 53, 35, 50, 66, 56, 48, 52, 65, 62, 70};
int dataLen = 26;
int pointType[] = { 0, 0, 0, 1, 1, 0, 2, 3, 1, 1, 0, 0, 1, 1, 2, 2, 2, 3, 3, 2, 0, 1, 2, 3, 3};
int colors[] = { 0xff0000, 0x000000, 0xff00ff, 0x00ff00 };
int colorLen = 4;
// Obtain the points of the same type and put them in a line layer
for (int i = 0; i < colorLen; ++i)
{
std::vector<double> yCoor;
std::vector<double> xCoor;
for (int j = 0; j < dataLen - 1; ++j)
{
if (pointType[j] == i)
{
// A line segment joins the current point with the next point, so we need to add both points.
// However, the current point may have already been added as the "next point" of the previous
// segment, so we need to check if we need to add the current point.
if ((yCoor.size() == 0) || (yCoor.back() == Chart::NoValue))
{
xCoor.push_back(dataX[j]);
yCoor.push_back(dataY[j]);
}
xCoor.push_back(dataX[j + 1]);
yCoor.push_back(dataY[j + 1]);
}
else if ((yCoor.size() > 0) && (yCoor.back() != Chart::NoValue))
{
// If the point is of a different type, we need to add Chart::NoValue to break the segment.
xCoor.push_back(dataX[j]);
yCoor.push_back(Chart::NoValue);
}
}
// Draw the layer that contains all segments of the same color
LineLayer* layer = c->addLineLayer(DoubleArray(&(yCoor[0]), yCoor.size()), colors[i]);
layer->setXData(DoubleArray(&(xCoor[0]), xCoor.size()));
layer->setLineWidth(2);
}
Regards
Peter Kwan
|
Re: XY graph multi color drawing |
Posted by HS.Kwon on Jul-30-2020 11:34 |
|
It was really helpful. Was solved.
I'll ask a few more.
1. Is it possible to change the Y-axis color on the surface chart? (checked part in the picture)
2. Is it possible to adjust the graph color according to the conditions specified by the user regardless of the Y axis in the surface chart?
If possible, how would you do it?
|
Re: XY graph multi color drawing |
Posted by HS.Kwon on Jul-31-2020 14:10 |
|
It works exactly fine.
Thank you for your help. |
|