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

Message ListMessage List     Post MessagePost Message

  Remove the last empty tick of a label based x-axis
Posted by at on May-19-2022 15:07
Attachments:
Hi Peter, how can I remove the last empty x-axis tick in the attached chart so that the last label will only be 47.52? That extra tick may have been there because I offset the labels and ticks to -0.5 so that they will be placed between the bars.

Thanks.
Screen Shot 2022-05-19 at 14.49.49 PM-min.png
Screen Shot 2022-05-19 at 14.49.49 PM-min.png

123.35 Kb

  Re: Remove the last empty tick of a label based x-axis
Posted by Peter Kwan on May-19-2022 16:58
Hi at,

By default, if you add some bars and some labels (using Axis.setLabels), ChartDirector will associate each bar with one label. You can shift the labels and/or ticks, but each bar would still be assoicated with one label.

For your case, there are more labels than bars (with your layout, if you have 10 bars, you would have 11 labels). In this case, ChartDirector will assume the missing bars to be empty.

May be you can try to add the axis labels the following way:

$c->xAxis->setLinearScale2(-0.5, -1.5 + count($labels), $labels);
$c->xAxis->setIndent(false);

The code above explicitly provides the position of each label independent of the bars. This should be the position you need.

Regards
Peter Kwan

  Re: Remove the last empty tick of a label based x-axis
Posted by at on May-19-2022 18:18
Attachments:
Hi Peter, I tried your suggestion but unfortunately, the way we implemented the histogram is somewhat unconventional. So I realized based on you response to just pop the x-axis labels so that it will have the same count as the bars and to just add the popped label later. Unfortunately, I cannot seem to add it using the $c->xAxis->addLabel() since the last empty tick is somewhat not recognized by Chartdirector? It's the 49th tick but Chartdirector thinks it has only 48 (see attached). Any workaround on how to add the last label manually?
Screen Shot 2022-05-19 at 18.01.18 PM-min.png
Screen Shot 2022-05-19 at 18.01.18 PM-min.png

139.87 Kb

  Re: Remove the last empty tick of a label based x-axis
Posted by Peter Kwan on May-19-2022 20:08
Hi at,

By default, for a bar chart, the x-axis will be "indented", which means the actual x-axis scale does not cover the entire length of the axis. The following is a chart that uses an indented x-axis scale. Note that the red line does not start or end at the edge of the plot area.

https://www.advsofteng.com/doc/cdphp.htm#dualyaxis.htm

For this type of axis, you cannot add a label at the right end, because it is outside the axis scale. That's why in the code in my last message, I use Axis.setIndent to disable to indentation first.

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

You mentioned "the histogram is somewhat unconventional". May be you can try the followng method, which creates a completely independent axis and put the label there. It should not affect how to implement your histogram.

# Add an extra axis at the bottom
$a = $c->addAxis(Bottom, 0);
$a->setIndent(false);
#Choose any scale you like and set the last label only
$a->setLinearScale2(0, 1, array("", "ABCD"));

You can also use the above extra axis to set any other labels you need.

Best Regards
Peter Kwan