|
Vertical line (position between labels) |
Posted by Marko on Oct-03-2017 16:37 |
|
Hi
I need to position a vertical line like the one attached. I know addMark uses indexes (0,1,2,3...) not actual values. Is there any other way?
|
Re: Vertical line (position between labels) |
Posted by Peter Kwan on Oct-03-2017 21:19 |
|
Hi Marko,
Is the chart you attached created by ChartDirector? If it is created by ChartDirector, you have already known how to add the vertical line. Would you mind to clarify what is the issue? Is it the mark label displaying 2.52, which is not consistent with the axis labels?
The addMark uses the same value you use for the x-axis. If the x-axis is numeric, like:
c.xAxis().setLinearScale(-1, 4, 1);
then the mark uses the same value as the x-axis. So if you add a mark at x = 1.52, it will be displayed at x=1.52 in the axis scale.
However, the x-axis are using labels, like {"-1", "Apple", "one", "two", "3.8932", "Apple"}, then the mark can only use array index. In this case, the index x = 2.5 will be in between the labels "one" and "two". It is because for labels, they can be anything, and ChartDirector would not attempt to understand them. So it uses array index for the purpose of positioning.
For your case, without seeing your code, I am not sure if you are using a numeric x-axis or a label based x-axis. If the x-axis labels come from Axis.setLabels or Axis.setLabels2, then it is a label based x-axis. In this case, the labels are for human reading only and has no meaning to ChartDirector, and array index will be used for positioning.
If your code uses Axis.setLinearScale, or if your code uses Layer.setXData to provide the x-coordinates for the data points, and let ChartDirector automatically scale the x-axis, then the x-axis is numeric.
If you would like to use a label based x-axis, then you can configure the mark label to anything you like. For example:
c.xAxis().addMark(2.52, 0xff0000, "1.52");
If the above still does not address the issue, is it possible to clarify what is the issue?
Regards
Peter Kwan |
Re: Vertical line (position between labels) |
Posted by Marko on Oct-04-2017 16:03 |
|
Hi Peter
The chart is not created by ChartDirector, I just wanted to illustrate my problem.
I was using labels and the marks where positioning to the nearest index. I have changed x-axis to numeric, now all's warking as supposed.
Thank you for your thorough explanation. |
Re: Vertical line (position between labels) |
Posted by Peter Kwan on Oct-04-2017 20:57 |
|
Hi Marko,
Even if you are using labels, you can put the mark anywhere by using fractional index.
For example, the x = 0, 1, 2, 3, are at the first, second, third and fourth labels. The x = 2.37 will be somewhere in between the third and fourth label.
But I think in your case, using a numeric x-axis is more natural.
Regards
Peter Kwan |
|