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

Message ListMessage List     Post MessagePost Message

  Number Formatting Help
Posted by Judy on Dec-01-2022 16:30
Hi Peter,

I want to set Axis like this

                    c.yAxis().setFormatCondition(">=", 0);
                    c.yAxis().setLabelFormat("{value}");

                    c.yAxis().setFormatCondition("else");
                    c.yAxis().setLabelFormat("({={value}*-1})");

but it's not work

I'd like the function like NumberFormatNegativePattern.Parentheses

Thanks in advance,

Judy.

  Re: Number Formatting Help
Posted by Peter Kwan on Dec-02-2022 01:36
Hi Judy,

The setFormatCondition is to select a single format for all the labels of the axis. For example, consider the condition:

c.yAxis().setFormatCondition(">=", 10000000);
c.yAxis().setLabelFormat("{={value}/10000000}M");

The above means if the maximum value of the axis label is >= 10000000, the labels will be displayed using M as the unit (that is, 10M instead of 10000000). It applies to all the labels, not just the labels >= 10000000. In this case, all subsequent conditions will be ignored.

For your case, I assume the labels are automatically generated by ChartDirector so your code does not know what are those labels. (If your code specify the label values, it can directly set the labels and there is no need to use setFormatCondition.)

In this case, you may use the following method for custom labelling:

..... create chart as usual and enter all the data and chart layers .....

// Ask ChartDirector to auto-scale the axes, which also generates the label values
c.layoutAxes();

// The label values
double[] ticks = c.yAxis().getTicks();

for (int i = 0; i < ticks.Length; ++i) {
    // modify negative labels
    if (ticks[i] < 0)
        c.yAxis().addLabel(ticks[i], "(" + (-ticks[i]) + ")");
}

You can even made the negative number red in color by using "<*color=FF0000*>(" + (-ticks[i]) + ")"

(*** Note: The above is in C# syntax. You may need to modify it a bit for other programming langauges.)

Best Regards
Peter Kwan