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

Message ListMessage List     Post MessagePost Message

  How to set label number of the Axis When using the 'addDataSet' function.
Posted by mirro187 on May-22-2019 10:05
Attachments:
for example , set 01/2019 02/2019 03/2019 04/2019 05/2019 06/2019 ...... 12/2019


std::map<std::string, UsageRateDataChart>::iterator it = mapdata.begin();
for (it; it != mapdata.end(); it++)
{
UsageRateDataChart data = it->second;
if (!isFirst)
{
layer->setLineWidth(2);
layer->setXData(DoubleArray(data._xData.data(), data._xData.size()));
isFirst = true;
}
QString   qstr = QString::fromLocal8Bit(it->first.c_str());
layer->addDataSet(DoubleArray(data._yData.data(), data._yData.size()),data._color, qstr.toStdString().data());
}
QQ图片20190522094907.png

  Re: How to set label number of the Axis When using the 'addDataSet' function.
Posted by Peter Kwan on May-22-2019 22:56
Hi mirro187,

By default, ChartDirector will automatically determine the axis scale and labels based on the xData and yData of all the layers in the chart. There are several API that can control how the labels are automatically determined. Some of them are:

https://www.advsofteng.com/doc/cdcpp.htm#Axis.setAutoScale.htm
https://www.advsofteng.com/doc/cdcpp.htm#Axis.setTickDensity.htm
https://www.advsofteng.com/doc/cdcpp.htm#BaseMeter.setLabelFormat.htm

For example, you can use the following code to configure the x and y label formats:

c->xAxis()->setLabelFormat("{value|mm/yyyy}");
c->yAxis()->setLabelFormat("{value}%");

If you prefer to configure the axis scale and labels with your own code, you can use Axis.setLinearScale or Axis.setDateScale. For example:

// y-axis scale from 0 to 100, with a tick every 20 units, and with a "%" after the label
c->yAxis()->setLinearScale(0, 100, 20);
c->yAxis()->setLabelFormat("{value}%");

// x-axis scale from 2019-1-1 00:00:00 to 2019-12-31 00:00:00, with a tick every 2 months
c->xAxis()->setDateScale(Chart::chartTime(2019, 1, 1), Chart::chartTime(2019, 12, 31), 60 * 86400);
c->xAxis()->setLabelFormat("{value|mm/yyyy}");

Hope this can help.

Regards
Peter Kwan