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

Message ListMessage List     Post MessagePost Message

  Custom Y-Axis
Posted by Ola on Jun-17-2020 11:37
Attachments:
I want a custom Y-Scale on the left side of the graph, I set the yscale2 to the "real" values and it works well. The picture shows what I want to show even if the values in the graph is different.

I tried something like this, but It doesn't really work very well, maybe you have a better suggestion?

String[] yLabels2 = { "0", "30", "60", "", "0", "60", "180"};

            c.yAxis().setLabels(yLabels2);
            c.yAxis().setLinearScale(0, 180, 10, 10);

            // Set the axis stem to transparent
            c.xAxis().setColors(Chart.Transparent);

            c.yAxis().setColors(Chart.Transparent);

            c.yAxis2().setColors(Chart.Transparent, Chart.Transparent, Chart.Transparent, Chart.Transparent);
            c.yAxis2().setTickColor(Chart.Transparent);

            c.yAxis2().setLinearScale(0, 4000, 250, 250);


I have offset the line graphs in the code, but need to update the y-axis. BTW, I do not want to see yAxis2, that part works.

I want the same number of major lines as shown in my picture, this will be fixed as well as the numbers on the y-axis.

Thanks!
Scale.png

  Re: Custom Y-Axis
Posted by Peter Kwan on Jun-17-2020 14:42
Hi Ola,

Labels such as "0", "30", "60" are treated as names for display, and have no meaning to ChartDirector. You can set the labels to "Apple", "ABC", "1000" and ChartDirector will just  display them evenly spaced on the axis, and use just their array index (0, 1, 2, ...) as the coordinates.

For your case, you need to use two y-axes for the 0 to 60 scale and 0 to 180 scale. The two axes can both be located on the left side. The following is an example:

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

In the above example, the two left axes are separated. It is because we added an offset when creating the axes. If the offset is 0, the two left axes will overlap at the left plot area border. You can use Axis.setMargin to add a top margin to one axis (which means the top part of the axis will have no scale), and a bottom margin to the axis to move its axis scale up. This can separate the axis scale vertically.

When you add your line, can use Layer.setUseYAxis to specify which y-axis it uses.

You can let ChartDirector auto-scale the axes, or you can use Axis.setLinearScale to configure the axis yourself. The axis labels configured this way are evenly spaced. If you need to be irregularly spaced labels (such as 0 60 180), you would need to create an axis scale with no labels, then add the labels yourself. It is like:

// axis scale is 0 to 180 with no labels
c.yAxis().setLinearScale2(0, 180, new string[] {});

// custom labels
double[] labelPositions = { 0, 60, 180 };
for (int i = 0; i < labelPositions.Length; ++i)
   c.yAxis().addLabel(labelPositions[i], "" + labelPositions[i]);

Hope this can help.

Regards
Peter Kwan

  Re: Custom Y-Axis
Posted by Ola on Jun-18-2020 00:36
Peter,

Again, thank you!

I ended up with this code:


            String[] yLabels2 = { "0", "30", "60", " ", "0", "60", "120", "180", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " " };

c.yAxis().setLinearScale2(0, 200, yLabels2);

c.yAxis().setColors(Chart.Transparent);

c.yAxis2().setColors(Chart.Transparent, Chart.Transparent, Chart.Transparent, Chart.Transparent);

c.yAxis2().setTickColor(Chart.Transparent);

c.yAxis2().setLinearScale(0, 4000, 50, 50);

layer.setUseYAxis2();

/Ola