java - JFreeChart : Zoom-in for domain axis is not working when CategoryAxis is used

标签 java jfreechart

我正在使用 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 似乎不支持在域范围内缩放

enter image description here

如果您使用图表工厂,要允许在域轴上缩放,请切换到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/

相关文章:

java - Spring REST/MVC & Security 异常处理 & 过滤链需求

java - h2 不以编程方式启动

java - Tapestry动态生成图像

Java 和 JFreechart 面板

java - JFreeChart 插值值

java - 在Java中使用json Schema过滤json实例

java - cassandra 3.x 触发器示例错误

java - 使用 Arraylist 追加序列

JFreeChart MouseListener 不解析图表元素

java - 对 XYSplineRenderer 的绘图进行动画处理