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

Message ListMessage List     Post MessagePost Message

  zero-line color and y-axis ...
Posted by Cho on Jan-31-2018 10:46
Attachments:
Hi,

I have questions:

1)
My code is below;
c->yAxis()->setLinearScale(-40.0, 150.0, 0, 0);
//c->yAxis()->setTickDensity(15);

But Y-Axis is like below picture.
How to modify the code?


2)
The zero-line color is red defaultly.
How to change the zero-line color?


Regards,

Cho
q.jpg

  Re: zero-line color and y-axis ...
Posted by Peter Kwan on Jan-31-2018 15:28
Hi Cho,

in Axis.setLinearScale, the tick increment is to specify the spacing between labels. For example:

c->yAxis()->setLinearScale(-40.0, 150.0, 40, 10);

The label spacing will be 40 above, so the labels will be -40, 0, 40, 80, 120. The axis will end at y = 150, but there will be no label at that position.

If you do not specify the label spacing (specify 0 is not valid), ChartDirector will automatically determine the label spacing. It will then adjust the end-points -40 and 150 so that they will end at a label position. For your case, ChartDirector may have decided to use 50 as the label spacing. Then it adjusts the end points to -50 to 150.

If you want ChartDirector to automatically determine the label spacing, but do not adjust the axis, you may use:

c->yAxis()->setLinearScale(-40.0, 150.0, 0, 0);
c->yAxis()->setRoundiing(false, false);

With the above code, the labels will be at 0, 50, 100, 150. The while y-axis will be from -40 to 150, but there will be no label at y = -40.

If you want other labeling method, such as irregular labels at y = -40, 0, 50, 100, 150 (that is, the labels are not evenly spaced), please let me know. There are methods for adding custom irregular labels, such as Axis.addLabel.

For the red line, by default, ChartDirector will not draw a line at y = 0. Is it possible there is some other code that draws the line (eg. XYChart.addLineLayer using zero data?)

Regards
Peter Kwan

  Re: zero-line color and y-axis ...
Posted by Cho on Jan-31-2018 16:29
Hi Peter,

First, thank you for your answer.
I have additional questions.

I want know such as irregular labels at y = -40, 0, 50, 100, 150 (that is, the labels are not evenly spaced).



For the red line;
I refer to examples and write the following code.
Is there any problems in operation in this way?

// Add a horizontal mark line to the chart at y = 40
// Set the mark line to purple (880088) dash line. Use white (ffffff) for the mark label.
// Put the mark label at the left side of the mark, with a purple (880088) background.
Mark *mark = c->yAxis()->addMark(0, -1, "");
mark->setLineWidth(1);
mark->setMarkColor(c->dashLineColor(0x880088), Chart::Transparent);
mark->setAlignment(Chart::Left);
mark->setBackground(Chart::Transparent);


And I also want to imitate drawing lines using zero data.
Would you give me detailed code?



Regards

Cho

  Re: zero-line color and y-axis ...
Posted by Peter Kwan on Jan-31-2018 22:00
Attachments:
Hi Cho,

Below please find a simple example I have just written. For the labels, I use Axis.setLinearScale and use Chart::NoValue to specify no labels, then I use Axis.addLabel to add them myself. For the mark line, I use your code, and in my case it works normally with a purple dash line at y = 0.


XYChart *c = new XYChart(300, 200);
c->setPlotArea(50, 20, 230, 150, 0xccd8ff, -1, Chart::Transparent, 0xffffff);

c->yAxis()->setLabelStyle("arial.ttf", 10);
c->xAxis()->setLabelStyle("arial.ttf", 10);
c->xAxis()->setTickLength(6, 3);

c->yAxis()->setLinearScale(-40, 150, Chart::NoValue);
c->xAxis()->setLinearScale(0, 30, 10, 1);


double ticks[] = { -40, 0, 50, 100, 150 };
for (int i = 0; i < 5; ++i)
{
const char *label = c->formatValue(ticks[i], (ticks[i] >= 0) ? "{value}" : "\{value}");
c->yAxis()->addLabel(ticks[i], label);
}

Mark *mark = c->yAxis()->addMark(0, -1, "");
mark->setLineWidth(1);
mark->setMarkColor(c->dashLineColor(0x880088), Chart::Transparent);

c->makeChart("test.png");

delete c;


If you want to use addLineLayer to add a line at y = 0, please just provide two points at y = 0, like:

double dataY[] = {0, 0};
LineLayer *layer = c->addLineLayer(DoubleArray(dataY, 2), 0x0000ff);
layer->setXData(0, 5);   // assume the x-coordinates are from 0 to 5


Hope this can help.

Regards
Peter Kwan
test.png

  Re: zero-line color and y-axis ...
Posted by Cho on Feb-01-2018 08:02
Hi Peter,

Thank you very much for your help.

Regards
Cho