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

Message ListMessage List     Post MessagePost Message

  xychart multiple yaxis xaxis Add Mark
Posted by John Butler on Jul-31-2015 16:21
Attachments:
Hi,

I'm trying to add a mark to XY chart, i'm changing the linear scale on the xAxis to add the
mark where I want but then my other lines that use the yAxis and YAxis2 disappear even
though I've set them to use the correct axis, see code below:

c.yAxis().setTitle("Valuation", "arialbd.ttf")
c.yAxis().setLinearScale(0, 18000, 1000)
c.yAxis2().setTitle("Score","arialbd.ttf")
c.yAxis2().setLinearScale(3.5, 8.5, 1)
c.xAxis().setLinearScale(2015, 2020, 1)

layer = c.addLineLayer2()
layer.addDataSet([10000, 10000,10000,10000,10000,10000], 0xCC6600, "Target Valuation
")
layer.setUseYAxis(c.yAxis())

layer2.addDataSet([4.5,5.0,5,5,6.0,6.5,7.0], 0x383838 , "Score").setUseYAxis2()
layer2.setUseYAxis2()

c.xAxis().setLinearScale(labels.first.to_i, labels.last.to_i, 1)
mark = c.xAxis().addMark(2017, 0xDD8888, "TRA", "", 10)
mark.setMarkColor(0x0000FF)
mark.setLineWidth(3)
mark.setAlignment(ChartDirector::Left)
mark.setFontAngle(90)

if i remove this line of code below I can see both my Y lines of data correctly:
c.xAxis().setLinearScale(labels.first.to_i, labels.last.to_i, 1)

As soon as I try and add the mark and scale the x axis then I can see the mark but my Y
data disappears.

Any ideas?
valuation_range_vs_target.png

  Re: xychart multiple yaxis xaxis Add Mark
Posted by Peter Kwan on Jul-31-2015 17:37
Hi John,

If you use setLinearScale to configure the range of the x-axis, you must also provide x-
coordinates for your data points (use Layer.setXData or Layer.setXData2). If you do not
provide x-coordinates for the data points, ChartDirector will assume the x-coordinates to
be 0, 1, 2, 3, ...., which are outside your x-axis range, and so the lines are not displayed.

For your case, apart from using setLinearScale, another method is to add the mark at the
array index position of 2017. For example, if your labels are 2015, 2016, 2017, 2018,
2019, 2020 (set using Axis.setLabels), the index position of the label 2017 is at x = 2, so
the mark can be added at x = 2. I believe in Ruby, the Array.index method can be used to
determine the index of an element in an array.

Hope this can help.

Regards
Peter Kwan

  Re: xychart multiple yaxis xaxis Add Mark
Posted by John Butler on Jul-31-2015 17:55
Thanks Peter, its easier for me just the set the X labels and use the index, keeps it simple.

Ideally for the marker I would just want a marker in the middle of the chart on the 2017 X
axis, maybe an image/icon or something rather than a full line. Whats the best way to do
this, can't seem to find some examples?

  Re: xychart multiple yaxis xaxis Add Mark
Posted by Peter Kwan on Jul-31-2015 23:29
Hi John,

In your code, you have put a text label TRA on the left side of the mark line. You can also
put the label at the center on the mark line by using the ChartDirector::Center alignment.
In ChartDirector, text can contain icons (eg. see the chart title in the Y-Zone Color sample
code). So instead of using TRA, you can just use an icon. You can configure the mark line
to be transparent while the text is non-transparent (using Mark.setMarkColor). In this way,
you can put an icon in the place of the mark line.

There are other methods as well, such as using BaseChart.addText or adding a scatter
layer with a single point.

Hope this can help.

Regards
Peter Kwan

  Re: xychart multiple yaxis xaxis Add Mark
Posted by John Butler on Aug-01-2015 00:38
thanks again Peter, i set the line thickness off the mark to 0 and added the image where the
text was and all looking good now.