我正在使用 jfreechart 库来绘制系列图表。我将 y 轴上的值、x 轴上的时间和 3 个类别作为系列。一切都很好,但我无法放大域轴,尽管它对于范围轴工作正常。这可能吗?
以下代码行可以帮助您找到我的代码的一些场景:
final ChartPanel chartPanel = new ChartPanel(chart);
chartPanel.setDomainZoomable(true);
chartPanel.setRangeZoomable(true);
this.add(chartPanel, BorderLayout.CENTER);
和
//set plot specifications
final CategoryPlot plot = (CategoryPlot) chart.getPlot();
plot.setBackgroundPaint(new Color(0xffffe0));
plot.setDomainGridlinesVisible(true);
plot.setDomainGridlinePaint(Color.lightGray);
plot.setRangeGridlinePaint(Color.lightGray);
//CUSTOMIZE DOMAIN AXIS
final CategoryAxis domainAxis = (CategoryAxis) plot.getDomainAxis();
//customize domain label position
domainAxis.setCategoryLabelPositions(
CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0)
);
最佳答案
您使用的 CategoryPlot
似乎不支持在域范围内缩放
如果您使用图表工厂,要允许在域轴上缩放,请切换到XYPlot
,代码为
JFreeChart chart = ChartFactory.createXYLineChart(...);
如果您能够将绘图转换为CategoryPlot
,则说明出现了问题。我检查了 LineChartDemo3
,此代码导致错误 (java.lang.ClassCastException
):
try {
final CategoryPlot cplot = (CategoryPlot) chart.getPlot();
} catch (Exception e) {
e.printStackTrace();
}
关于java - JFreeChart : Zoom-in for domain axis is not working when CategoryAxis is used,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11207957/