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 minor tick for the bar chart
Posted by moses on Jan-11-2024 17:06
I want to set the minor tick for the charts. I found the function axis->setLinearScale(nMinBount, nMaxBount, majorunit, minorUnit) works for the Line chart, but for the bar chart seems it does not work. How to set the minor tick for a bar?

  Re: how to set the minor tick for the bar chart
Posted by Peter Kwan on Jan-12-2024 03:04
Hi Moses,

The setLinearScale should work for all XY charts. In fact, even if the chart is empty, it will work, as it just sets the scale and labels on the axis.

If you have setLinearScale working on a line chart, you can change addLineLayer to addBarLayer. This will then become a bar chart, and it should work too.

If in your case, it does not work for a bar chart, would you mind to clarify how it does not work? Do the bars disappear? Or is the scale on the axis not the same as specified in setLinearScale?

For bar charts, it is common the x-axis labels are text strings. For example, you can use "Q1", "Q2", "Q3", "Q4" as the x-axis labels. If no x-coordinates are specified (eg. Layer.setXData is not used), then the x-coordinates of the data will be the array index 0, 1, 2, 3.  This applies to all XY chart types. The x-coordinates of the labels are also 0, 1, 2, 3. That's why the bars/data points match the labels. Using array indexes as scale is most common if the bars/data points are equally spaced.

If you use Axis.setLinearScale, it will determine the axis scale and labels. If your code does not provide x-coordinates for the data, the data will have x-coordinates 0, 1, 2, 3 .... If your code sets a scale that is not consistent with the data, the bars/data points may fall outside the axis scale (ie, outside the plot area), and will not be visible.

Axis.setLinearScale and Axis.setLabels both sets the scale and labels. They should not be used at the same chart.

Also, for bar charts, the default is to use an indented axis, which sets a left and right axis margin equals to 0.5 x-axis unit. The following describes what is an indented axis.

If the setLinearScale sets the axis to a very small scale (such as 0 to 0.1), then the 0.5 unit margin will become very big. The entire axis will be 1.1 unit, of which only 0.1 unit is the actual scale, and the remaining being the margins. In this case, you may want to disable the indentation using setIndent(false). If x-coordinates are used, you can always position the bars using your own code.

If you need further help, is it possible to attach an image so I can understand how it does not work, or provide some sample code (perhaps by modifying the Simple Bar Chart sample code) to illustrate the issue?

Best Regards
Peter Kwan

  Re: how to set the minor tick for the bar chart
Posted by Peter Kwan on Jan-12-2024 03:15
Hi Moses,

Note that even if Axis.setLabels is used (ie, no x-coordinate used), you can set minor ticks by prefixing the label with "-". For example, for the labels "AAA", "-BBB", "CCC", the label "-BBB" will be displayed as "BBB" with a minor tick. See:

Best Regards
Peter Kwan