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

Message ListMessage List     Post MessagePost Message

  XYChart with logarithmic axes cannot have custom labels and minorTickInc
Posted by Mármarosi József on Apr-18-2019 23:59
I want to dispay an XYChart that has logaritmic scaling axes, and also want to use labels displaying powers of 10. Unfortunately, ChartDirector does not support this number format, so I have to use custom labels. The issue arises when I want to display helper tick lines. I could hack the issue on the X axis this way (.NET Framework, C#):

        protected void SetLogXAxis(
            XYChart chart,
            List<Model.ChartSeries> series,
            string title,
            bool usePower
            // Set basic axis properties.
            SetAxisProperties(chart.xAxis(), title, Chart.BottomRight);

            // Determine the range of the axis values.
            List<Model.ChartSeries> seriesX = series.Where(s => s.DataX.Count > 0).ToList();
            double lowerPower = seriesX.Count > 0 ?
                Math.Floor(Math.Log10(seriesX.Select(s => s.DataX.Min()).Min())) :
            double upperPower = seriesX.Count > 0 ?
                Math.Ceiling(Math.Log10(seriesX.Select(s => s.DataX.Max()).Max())) :

            double lowerLimit = Math.Pow(10, lowerPower);
            double upperLimit = Math.Pow(10, upperPower);

            // In case of using powers of 10...
            if (usePower)
                List<string> labels = new List<string>();

                // Format the tick values.
                for (double i = lowerPower; i <= upperPower; i++)
                    labels.Add(string.Format("10<*size=12,super*>{0}", i));

                // Set the labels.
                chart.xAxis().setLogScale2(lowerLimit, upperLimit, labels.ToArray());
                chart.xAxis().setLogScale3(labels[0]); // MJ Hack the axis labels bug.

            // Set logarithmic scaling of the axis.
            chart.xAxis().setLogScale(lowerLimit, upperLimit, 10, Chart.LinearTick);
            chart.xAxis().setTickLength2(3, 0);

However, this does not work with th Y axis. If I set the custom labels after having set the minorTickInc, then the minor tick lines are not displayed. The main problem as I understand is that Axis.setLabels(string[]) does not clear or overwrites the existing labels but appends the new values to them.

Has anybody any idea to solve the above issue?


  Re: XYChart with logarithmic axes cannot have custom labels and minorTickInc
Posted by Peter Kwan on Apr-19-2019 03:54
Hi Mármarosi,

In ChartDirector, each axis should have its scale set only once. It is not suggested you call setLogScale2 and setLogScale3 and then setLogScale for the same axis.

For your case, for custom labeling, you can use Axis.addLabel. The following is an example for setting the axis scale:

private void logLinearAxis(Axis a, double lowerLimit, double upperLimit)
    // Set log scale with no labels
    a.setLogScale2(lowerLimit, upperLimit, null);

    double lowerPower = Math.Floor(Math.Log10(lowerLimit));
    double upperPower = Math.Ceiling(Math.Log10(upperLimit));

    // use a loop to add custom labels
    for (double i = lowerPower; i <= upperPower; i++)
        // major ticks
        double tickPos = Math.Pow(10, i);
        a.addLabel(tickPos, string.Format("10<*size=12,super*>{0}", i));

        // minor ticks
        if (i != upperPower)
            for (int j = 2; j <= 9; ++j)
                a.addLabel(j * tickPos, "-");

The following is a test code to show how the above works:

XYChart c = new XYChart(800, 600);
c.setPlotArea(50, 20, 730, 550).setGridColor(0xcccccc, 0xcccccc, 0xcccccc, 0xcccccc);

logLinearAxis(c.xAxis(), 10, 100000);
logLinearAxis(c.yAxis(), 100, 10000);

viewer.Chart = c;

Hope this can help.

Peter Kwan

  Re: XYChart with logarithmic axes cannot have custom labels and minorTickInc
Posted by Marmarosi Jozsef on Apr-19-2019 05:12
Hi Peter,

Thanks for your help. I will be able to use your solution on Tuesday only, we have started  a 4 day long holiday here in Hungary.


  Works well
Posted by Mármarosi József on Apr-23-2019 19:03
It works exactly as I wanted. Thank you.