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

Message ListMessage List     Post MessagePost Message

  Contour Plot Colored Lines (No Map/ No Fill)
Posted by Rick Issen on May-29-2021 01:01
Hi Peter,

I use CD7 for Visual C++ 2019/MFC!

When I put your example (see below) from

https://www.chartdir.com/forum/download_thread.php?bn=chartdir_support&pattern=how+to+modify+the+default+contour+color+scale&thread=1469627703#N1490448996

into your mfcdemo, then

pContourLayer2->setContourWidth(..)

and

pContourLayer2->setContourLabelStyle(..)

does not work.

Please how to procede?

Regards,
Rick


void rw_color_contour(CChartViewer* viewer, int /* chartIndex */)
{
// The x and y coordinates of the grid
double dataX[] = { -4, -3, -2, -1, 0, 1, 2, 3, 4 };
double dataY[] = { -4, -3, -2, -1, 0, 1, 2, 3, 4 };

// Use random numbers for the z values on the XY grid
RanSeries* r = new RanSeries(99);
DoubleArray dataZ = r->get2DSeries((int)(sizeof(dataX) / sizeof(dataX[0])), (int)(sizeof(dataY) / sizeof(dataY[0])), -0.9, 0.9);

// Create a XYChart object of size 420 x 360 pixels
XYChart* c = new XYChart(420, 360);

// Set the plotarea at (30, 25) and of size 300 x 300 pixels. Use semi-transparent grey
// (0xdd000000) horizontal and vertical grid lines
c->setPlotArea(30, 25, 300, 300, -1, -1, -1, 0xdd000000, -1);

// Set the x-axis and y-axis scale
c->xAxis()->setLinearScale(-4, 4, 1);
c->yAxis()->setLinearScale(-4, 4, 1);

// Add a contour layer using the given data and with no filling
ContourLayer* layer = c->addContourLayer(DoubleArray(dataX, (int)(sizeof(dataX) / sizeof(dataX[0]))), DoubleArray(dataY, (int)(sizeof(dataY) / sizeof(dataY[0]))), dataZ);
int noFillGradient[] = { Chart::Transparent, Chart::Transparent };
ColorAxis* cAxis = layer->setColorAxis(350, 25, Chart::TopLeft, 300, Chart::Right);
cAxis->setColorGradient(false, IntArray(noFillGradient, (int)(sizeof(noFillGradient) / sizeof(noFillGradient[0]))));
layer->setContourColor(Chart::Transparent);

// Move the grid lines in front of the contour layer
c->getPlotArea()->moveGridBefore(layer);

// Use a second empty contour layer for the color axis
ContourLayer* pContourLayer2 = c->addContourLayer(DoubleArray(), DoubleArray(), DoubleArray());
ColorAxis* cAxis2 = pContourLayer2->setColorAxis(-350, 25, Chart::TopLeft, 300, Chart::Right);
int colorGradient[] = { 0x0044cc, 0xFFFF00, 0xff0000 };
cAxis2->setColorGradient(false, IntArray(colorGradient, (int)(sizeof(colorGradient) / sizeof(colorGradient[0]))));
cAxis2->setLinearScale(*(std::min_element(dataZ.data, dataZ.data + dataZ.len)), *(std::max_element(dataZ.data, dataZ.data + dataZ.len)));

// Enable contour label by setting its style to black (000000) 8pt default bold font
layer->setContourLabelStyle("bold", 8, 0x000000);

// Set the label to display the value in a CDML block with semi-transparent white (4FFFFFFF)
// background and 2 pixels left/right margin and 1 pixel top/bottom margin
layer->setContourLabelFormat("<*block,bgcolor=4FFFFFFF,margin=2 2 1 1*>{value}");

pContourLayer2->setContourWidth(2); // Does not work!

c->layout();

DoubleArray ticks = cAxis->getTicks();
for (int i = 0; i < ticks.len; ++i)
cAxis->addMark(ticks[i], cAxis2->getColor(ticks[i]));

delete r;

// Output the chart
viewer->setChart(c);

//include tool tip for the chart
viewer->setImageMap(c->getHTMLImageMap("", "", "title='<*cdml*><*font=bold*>X: { x|2}<*br*>Y: { y|2}<*br*>Z: { z|2}''"));
}

  Re: Contour Plot Colored Lines (No Map/ No Fill)
Posted by Peter Kwan on May-29-2021 03:40
Hi Rick,

The setContourLabelStyle/setContourLabelFormat applies to contours generated by ChartDirector. For your case, the lines are mark lines created with Axis.addMark. A mark line can have a label, but that label will be put on the color axis. To create a custom contour with labels, you can use ContourLayer.addCustomContour. You can use both addMark and addCustomContour to put labels on both the color axis and the contour chart. It is like:

for (int i = 0; i < ticks.len; ++i)
{
    cAxis->addMark(ticks[i], cAxis2->getColor(ticks[i]));
    layer->addCustomContour(ticks[i], cAxis2->getColor(ticks[i]), 2, c->formatValue(ticks[i], " {value|1} "));
}

Hope this can help.

Regards
Peter Kwan

  Re: Contour Plot Colored Lines (No Map/ No Fill)
Posted by Rick Issen on May-29-2021 14:02
Attachments:
Hi Peter,

As always, thank you very much for your excellent support! It really works (see attached picture). But, it's difficult to understand (although simple constellation).

I do not understand pColorAxis->addMark(..). What do ticks have to do with the individual contour curves? And you said in another support that the curves are do not available for access...

Regards,
Rick
Colored Contour Plot.png

  Re: Contour Plot Colored Lines (No Map/ No Fill)
Posted by Peter Kwan on May-31-2021 15:59
Hi Rick,

The Axis.addMark can apply to any axis (x, y, color axis and other axis types in other charts). It adds an extra mark to the axis and the associated "grid line" with the axis. The following is a typical usage:

https://www.advsofteng.com/doc/cdnet.htm#markzone.htm

Because the axis normally already has labels, and the chart already has grid lines, so if addMark is used, normally it is for something special. It will put the special label as one of the axis label, and the associated grid line can have a special color or style.

When addMark is applied to a color axis in a contour chart, the associated "grid line" is the contour line.

For your case, because you do not want to fill the contour chart, but want to make the contour line colorful (normally the grid lines are all the same color), so the code uses addMark to add the special contour line. If you provide a label as well, that special label will go to the color axis, not to the contour line

We envision that it may be useful to put special labels on the contour line itself. That's why we add the addCustomContour method.

For your case, the contour label is not really special, but the contour line is special. So it still needs to use addCustomContour.

Regards
Peter Kwan

  Re: Contour Plot Colored Lines (No Map/ No Fill)
Posted by Rick Issen on Jun-01-2021 13:22
Hi Peter,

Thank you very much for your explanation. It gets clearer now...

Regards,
Rick