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

Message ListMessage List     Post MessagePost Message

  Equivalent of SetTickOffset in value based axis
Posted by at on May-26-2015 17:21
Hi Peter, I have a histogram chart in which the x-axis is having labels while the x-axis2 is value based(setXData).
The values of the axes should align. I use setTickOffset(0.5) in the x-axis, what should I use for x-axis2 for the
values to still be aligned? I tried setMargin but it's in pixel and I cannot hard code a value since the size of the
histogram is variable. How can I get the the equivalent of tickoffset in pixel?

Thanks.

  Re: Equivalent of SetTickOffset in value based axis
Posted by Peter Kwan on May-27-2015 03:26
Hi at,

The setTickOffset is applicable to both label based and value based axes.

For your case, you mentioned you are drawing a "histogram". Is it a bar chart (as
histograms are most common realized as a bar chart)? I assume the primary x-axis is
configured with Axis.setLabels.

If it is a bar chart, the x-axis by default will be "indented" (see Axis.setIndent). Suppose
you have 5 bars. The coordinates of the center position of the bars will be x = 0, 1, 2, 3,
4, which is the location of the 5 labels. However, the actual axis scale will be extended
by 0.5 unit on both sides, otherwise half of the first and last bars will fall outside the plot
area. So the full axis scale will be effectively -0.5 to 4.5, with the labels and ticks at 0,
1, 2, 3, 4. If you setTickOffset(0.5), the ticks will be moved by 0.5 units, so the ticks are
at -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, while the labels are still at 0, 1, 2, 3, 4.

For the second x-axis, I am not sure how it is configured. (The setXData method you
mentioned are for configuring the layers, not the axis.) Are you using Axis.setLinearScale?

Since the xAxis2 is never used by any layers or data sets, it is mainly for human reading.
So one easy method to solve the problem is to use Axis.setLabels also for the xAxis2. You
may configure the secondary x-axis to be indented to by using Axis.setIndent. In this
way, the labels and ticks of the two axes will align, and you can use any labels you like
on the xAxis2. Any labels that you can achieve with Axis.setLinearScale should also be
achievable with Axis.setLabels.

If you must use Axis.setLinearScale, there are two methods:

(a) The Axis.setLinearScale should set a scale that corresponds to -0.5 to 4.5 of the
primary x-axis (or -0.5 to N - 0.5, where N is the number of bars), but with no labels. You
can then add the label at between the ticks using Axis.addLabel.

(b) Use setMargin on the secondary x-axis to indent the axis for the same amount. The
amount is plot_area_width / (2 * no_of_bars)  = half the bar slot width, and use
Axis.setTickOffset to shift by ticks equal to half the distance (in axis scale unit) between
ticks.

Hope this can help.

Regards
Peter Kwan

  Re: Equivalent of SetTickOffset in value based axis
Posted by at on May-27-2015 14:23
Attachments:
Hi Peter, sorry for not being clear, please see attached. The chart labels are 0, 1, 2 to 38 and has a mark with a
value of 28.5575 located in x-axis2 since x-axis are just labels. What I did was to set the x-axis2 to setLinearScale
using the min and max of the labels.  My goal is to align the 2 axes so that the mark will still be correct with
respect to the x-axis labels. How to do this?
histogram.png