woddle
woddle

Reputation: 1622

JFreechart - vertical X-axis labels on an XYChart

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.

Upvotes: 0

Views: 4985

Answers (2)

woddle
woddle

Reputation: 1622

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

Upvotes: 1

trashgod
trashgod

Reputation: 205785

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.

Upvotes: 1

Related Questions