0

I have an XYLineChart, where the labels on the X axis are written horizontally. I would like to be able to write them vertically (descending).

I can already do this for BarCharts:

CategoryPlot plot = (CategoryPlot) chart.getPlot();
final CategoryAxis domainAxis = plot.getDomainAxis();
domainAxis.setCategoryLabelPositions(CategoryLabelPositions.DOWN_90);

but an XYChart returns an XYPlot, rather than a CategoryPlot, and the getDomainAxis() of an XYPlot returns a ValueAxis, not a CategoryAxis. ValueAxis lets me call

setVerticalTickLabels(true);

which is almost there! But it draws them ascending, rather than descending. Any way around this?

Thanks,

Edit: I need the domain axis to stay at the bottom of the chart. Hadn't considered it being any other way when making the original post.

woddle
  • 1,522
  • 1
  • 18
  • 34

2 Answers2

1

ValueAxis does this automatically in drawTickMarksAndLabels() for an axis on the RectangleEdge.TOP edge:

xyPlot.setDomainAxisLocation(AxisLocation.TOP_OR_LEFT);

enter image description here

Example based on a variation of ScatterAdd.

Community
  • 1
  • 1
trashgod
  • 200,320
  • 28
  • 229
  • 974
  • Thanks. I need the labels on the bottom, rather than the top, though. I've had to modify the source to achieve this. – woddle Dec 12 '11 at 09:04
  • You can accept this answer by clicking on the [empty check mark](http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work/5235#5235) at the left or pose another answer showing your approach. – trashgod Dec 12 '11 at 14:56
0

Answering my own question, this didn't seem to be possible, so I had to add the functionality to the jfreechart source myself.

woddle
  • 1,522
  • 1
  • 18
  • 34