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

Message ListMessage List     Post MessagePost Message

  Moving Y axis
Posted by Alexx on Jul-22-2018 01:43
Attachments:
Is it possible to move the y-axis, as shown in figure?
5.jpg

  Re: Moving Y axis
Posted by Peter Kwan on Jul-22-2018 19:35
Hi Alexx,

If you just want to move the axis, with all other things unchanged, you can use Axis.setOffset. Note that if any of the lines are using the axis, the lines will not be moved, so they will not match the axis. For example:

// move the axis to the left by 10 pixels, and to the bottom by 40 pixels
c->yAxis2()->setOffset(10, 40);

If you want to move the axis so that the 0 point is at the plot area bottom, you would need to use the following method:

... create everything in the chart as usual ...

// Now we can auto-scale the axis to determine the labels and their positions
c->layoutAxes();

// Compute the distance to move = distance between the 0 label from the plot area bottom
int offsetY = c->getPlotArea()->getBottomY() - c->getYCoor(0, c->yAxis2());

// Move the axis
c->yAxis2()->setOffset(10, offsetY);

Regards
Peter Kwan

  Re: Moving Y axis
Posted by Alexx on Jul-23-2018 04:23
Attachments:
Hi Peter

Thanks for reply.
I don't successfully asked.
Yes, I need not just shift y-axis, I need to shift axis together with the line (red).
I used c.layoutAxes, but I did not get the desired result (see pictures).
The Y-axis must move together with the curve (red).
Also, need to shift the X-axis labels (when offset, the curve will override them).

p.s I use vba
4.jpg
3.jpg

  Re: Moving Y axis
Posted by Peter Kwan on Jul-24-2018 04:55
Hi Alexx,

You may try to create a hidden axis with the scale shifted and then bind the red line layer to hidden axis afterwards. It is like:

Call c.layoutAxes()
Call c.yAxis2().setOffset(10, c.getPlotArea().getBottomY() - c.getYCoor(0, c.yAxis2()))

Dim hiddenAxis As Axis
Set hiddenAxis = c.addAxis(cd.Right, 0)
Call hiddenAxis.setColors(cd.Transparent, cd.Transparent)
Call hiddenAxis.syncAxis(c.yAxis2(), 1, -c.yAxis2().getMinValue())

Call myLayer.setUseYAxis(hiddenAxis)


If your red axis scale is specified by your code (eg. using Axis.setLinearScale) instead of automatically determined by ChartDirector, then it is also possible to do the above without entering the data first and calling XYChart.layoutAxes. All we need to do is to compute the offset ourselves (instead of using getYCoor). This is possible because your code specifies both the axis scale and the plot area size and so have all the necessary information to do the computation.

Regards
Peter Kwan

  Re: Moving Y axis
Posted by Alexx on Jul-26-2018 04:19
Thank you Peter, everything is ok

Regards

  Re: Moving Y axis
Posted by Alexx on Aug-04-2018 03:35
Attachments:
Hi Peter
Sorry, but I have another problem.
I need to shift 3rd Y-axis (rightAxis2) together with the BarLayer (layer2 - blue)..
By analogy with your example i wrote the following code:

Dim hiddenAxis2 As ChartDirector.Axis

    Call c.layoutAxes
    Call rightAxis2.setOffset(70, c.getPlotArea.getBottomY - c.getYCoor(0, c.yAxis2))
Set hiddenAxis2 = c.addAxis(cd.Right, 5)
    Call hiddenAxis2.setColors(&H5588CC, &H5588CC)
    Call hiddenAxis2.syncAxis(rightAxis2, 1, -10)
    Call layer2.setUseYAxis(hiddenAxis2)

but it does not work for the 3rd axis of U, there is nothing on the graph - it's empty.

Here's how I need it..
1.jpg

  Re: Moving Y axis
Posted by Peter Kwan on Aug-05-2018 03:14
Hi Alexx,

In your code, the intercept (the second parameter of syncAxis) of the hiddenAxis2 is not -10. From your chart, it should be something like 65.

I found that ChartDirector will not draw any axis that is not layout (axis that are created after c.layoutAxes). So the hiddenAxis2 will not be visible.

Note that for a bar chart, for positive data values, the top of the bar is the data value. The bottom of the bar is just arbitrary. It is usually 0 if the 0 is within the plot area. If the 0 is not in the plot area, then the bar will just start from the bottom of the plot area. (We often see bar charts that do not start from 0, which is perfectly normal).

For your case, I see that you also move the x-axis lower. If everything is moved lower, may be you can just extend the entire plot area lower. In this way, you do not need to move the axis or create hidden axis. If you do not want the axis to extend to the top of the plot area, you can always use Axis.setMargin. For example, you can see the following chart:

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

Note that on the left y-axis of the top chart, it is 0M - 300M, and it only occupies the bottom of the chart. This is achieved by setting a top margin for the axis with Axis.setMargin.

Another example is at:

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

The left y-axis also does not extend to the top of the plot area. There are some space left for the legend box. This y-axis is also configured using Axis.setMargin.

If you want an axis not to extend to the bottom of the plot area, you can use Axis.setMargin to set a bottom margin as well.


If you still want to use hiddenAxis and offset the axis, for the bar layer, you can use a Box-Whisker layer instead. For a box chart, you can specify both the top edge and the bottom edge of the box, so the bottom edge can go outside the plot area. Alternatively, you can draw a separate chart and overlay it on top of your existing chart (eg. use the MultiChart object or use DrawArea.merge).


Regards
Peter Kwan