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

Message ListMessage List     Post MessagePost Message

  How to set the axis label between tick marks for the Line chart
Posted by moses on Jan-10-2024 15:07
Attachments:
Hello,

We have a feature request that allows users to set the axis label between the tick marks,  how to set it in C++?
Screenshot 2024-01-10 150638.png

  Re: How to set the axis label between tick marks for the Line chart
Posted by Peter Kwan on Jan-10-2024 19:12
Hi Moses,

Are you referring to the x-axis labels (the labels "12/31/2014", "1/31/2015" ....)?

You can set the labels to any text you like. The exact method depends on how the chart is set up.

In the simplest case, if your code provides the x-axis labels as a StringArray, you can simply modify your StringArray based on user input, and then redraw the chart. For example, consider the sample code below:

https://www.advsofteng.com/doc/cdcpp.htm#multiline.htm

The x-axis labels are set up using Axis.setLabels. You can provide a user interface to allow the user to edit the list of labels, then set up the StringArray based on the user input, then redraw the chart. Usually, no additional code is needed to redraw the chart, as it is the same code that draws the chart in the first place.

If some chart setup, your code does not provide and cannot predict what are the x-axis labels (eg. the labels are automatically determined by ChartDirector based on the data). In this case, other method would be needed. Please let me know if this is the case.

Best Regards
Peter Kwan

  Re: How to set the axis label between tick marks for the Line chart
Posted by moses on Jan-10-2024 21:16
Attachments:
I mean how to set the axis label in the middle of two tick marks, not on a tick mark.
In Excel, there is a option can set it.
Screenshot 2024-01-10 211329.png
Screenshot 2024-01-10 211605.png

  Re: How to set the axis label between tick marks for the Line chart
Posted by Peter Kwan on Jan-10-2024 21:48
Hi Moses.

Sorry for my mis-understanding. If the labels are configured using Axis.setLabels, you can
put the axis labels in between the ticks by using an "indented axis" and shifting the shifting the ticks by 0.5 unit.

The code is like:

    c->xAxis()->setIndent(true);
    c->xAxis()->setTickOffset(0.5);

The following is an example with a bar chart. For bar charts, indented axis is the default (so the sample code does not need to call setIndent):

https://www.advsofteng.com/doc/cdcpp.htm#softlightbar.htm

For line charts, the default is not to indent the axis, so setIndent is necessary.

See:

https://www.advsofteng.com/doc/cdcpp.htm#Axis.setIndent.htm
https://www.advsofteng.com/doc/cdcpp.htm#Axis.setTickOffset.htm

Best Regards
Peter Kwan

  Re: How to set the axis label between tick marks for the Line chart
Posted by moses on Jan-11-2024 17:02
Thanks, it's helpful.