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

Message ListMessage List     Post MessagePost Message

  Using Scatterlayer, setLinearScale problem.
Posted by Hong on Nov-24-2025 15:49
I need dynamic y range.
In my code, use "m_dRangeY_Min", "m_dRangeY_Max" at y-axis setLinearScale.

Only create time(once) set the range success.

I want to change the y-range, every chart update time.



XYChart* c = new XYChart(rect.Width(), rect.Height());

// Set the center of the plot region, and set width x depth x height to by Calc.
int nX = 70;
int nY = (int)(rect.Height() * 0.05);
double dWidthRatio = 0.9;
double dHeightRatio = 0.75;

int nWidth = (int)(dWidthRatio * rect.Width());
int nHeight = (int)(dHeightRatio * rect.Height());
c->setPlotArea(nX, nY, nWidth, nHeight, -1, -1, RGBtoHexInt(0, 0, 0), BtoHexInt(0, 0, 0), -1);
c->setClipping();

// Set the x, y and z axis titles using 10 points Arial Bold font
c->xAxis()->setTitle("Length", "seguisb.ttf", 10);
c->xAxis()->setLinearScale(0, 2000, 100);

c->yAxis()->setTitle("Thickness", "seguisb.ttf", 10);
c->yAxis()->setLinearScale(m_dRangeY_Min, m_dRangeY_Max, 100);

viewer->syncLinearAxisWithViewPort("x", c->xAxis());
viewer->syncLinearAxisWithViewPort("y", c->yAxis());

// Add a scatter group to the chart using 11 pixels glass sphere symbols, in which the color
// depends on the z value of the symbol
int nChartLineColor[] = { 0xF51907, 0x0AF308,  0x0C31EF, 0x726113, 0x8bd8f9, 0xB913D3, 0xE6E6FA, 0xf0f000, 0xFF1493,  0xFF8C00 };

for (int i = 0; i < 20; i++)
{
char num_char[10 + sizeof(char)];
std::sprintf(num_char, "%d", i);

c->addScatterLayer(DoubleArray(m_pDataTopX[i], 2000), DoubleArray(m_pDataTopY[i], 2000),
num_char, Chart::CircleSymbol, 4, nChartLineColor[i], nChartLineColor[i]);
}

delete viewer->getChart();
viewer->setChart(c);

  Re: Using Scatterlayer, setLinearScale problem.
Posted by Peter Kwan on Nov-24-2025 23:16
Hi Hong,

(A) The "c->yAxis()->setLinearScale(m_dRangeY_Min, m_dRangeY_Max, 100);" means the y-axis range will be from m_dRangeY_Min to m_dRangeY_Max. If the m_dRangeY_Min and m_dRangeY_Max does not change, then the axis scale will not change.

(B) The "viewer->syncLinearAxisWithViewPort("y", c->yAxis());" means the y-axis scale is determined by the user, not by your code. This is usually used for zoomable and scrollable chart. In this case, the user can zoom in/out to change the y-axis scale.

That means (A) and (B) conflicts with each other. The setLinearScale means the code control the axis scale, but the syncLinearAxisWithViewPort means the user control he axis scale. You can only use either (A) or (B), not both.

If you want allow the user to zoom in/out, and you want m_dRangeY_Min to m_dRangeY_Max to be the full range (the maximum scale), the please use:

viewer->setFullRange("y", m_dRangeY_Min, m_dRangeY_Max);
viewer->syncLinearAxisWithViewPort("y", c->yAxis());

For example, if (m_dRangeY_Min, m_dRangeY_Max) is (0, 1000), then the user can zoom out up to 0 - 1000. The user cannot zoom out to 0 - 1000000 because (0, 1000) is already the maximum scale.

If you do not allow the user to zoom in/out, please remove (B).

Best Regards
Peter Kwan