JFreechart - vertical X-axis labels on an XYChart

笑着哭i 提交于 2019-12-12 03:05:12

问题


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.


回答1:


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

xyPlot.setDomainAxisLocation(AxisLocation.TOP_OR_LEFT);

Example based on a variation of ScatterAdd.




回答2:


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



来源:https://stackoverflow.com/questions/8430747/jfreechart-vertical-x-axis-labels-on-an-xychart

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!