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

Message ListMessage List     Post MessagePost Message

  Line chart X label problem.
Posted by taejin Kim on Aug-10-2021 12:49
Hi~~
I have problem for display x label.
I use vector. y value is temperature, x value is distance.
vector size is about 900 and I want to display regular distance.

ex)
(95, 1.2),
(96, 1.3),
(93, 1.9),
(97, 2.4),
(95, 2.7),
(96, 3.3),
(93, 3.9),
(97, 4.5),
...

I want to display x label 1,2,3,4
Any information will helpful.
Please let me know....
Thanks....

  Re: Line chart X label problem.
Posted by Peter Kwan on Aug-10-2021 14:35
Hi taejin Kim,

Since you mention "vector", I assume you are using C++.

Suppose you have two data arrays in:

std::vector<double> yData;
std::vector<double> xData;

If you want to plot a line a line chart, you can use:

LineLayer *layer = c->addLineLayer(DoubleArray(&(yData[0]), yData.size()), 0xff0000, "My Line");
layer->setXData(DoubleArray(&(xData[0]), xData.size()));

Do not use Axis.setLabels to configure the x-axis labels. By using setXData to provide the x-coordinates, ChartDirector will automatically determine the x-axis scale and labels based on your data. The x-axis will be like the y-axis. The labels will depend on your data.

If you want to specify the x-axis scale yourself, you can use Axis.setLinearScale:

// Scale from 0 to 10, with each label incremented by 1 so that the labels are
// 0, 1, 2, 3, ...., 10.
c->xAxis()->setLinearScale(0, 10, 1);

The followings are some examples that uses setXData. You can see the labels are automatic:

https://www.advsofteng.com/doc/cdcpp.htm#xyline.htm

https://www.advsofteng.com/doc/cdcpp.htm#multicolorline.htm

https://www.advsofteng.com/doc/cdcpp.htm#multiline2.htm

Hope this can help.

Regards
Peter Kwan

  Re: Line chart X label problem.
Posted by taejin Kim on Aug-10-2021 16:55
Thanks. I just solved it.
Key point is
"Do not use Axis.setLabels to configure the x-axis labels."
use
"setXData"

Many thanks again.