0

I am using jfreechart library to draw a series chart. I have taken values on y-axis, time on x-axis and 3 categories as series. Everything is fine but I'm not able to zoom-in domain axis although it's working fine for range axis. Is this possible?

Following lines of code may help you to find some scenario of my code:

final ChartPanel chartPanel = new ChartPanel(chart);
chartPanel.setDomainZoomable(true);
chartPanel.setRangeZoomable(true);
this.add(chartPanel, BorderLayout.CENTER);

and

//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)
);
4

1 回答 1

1

看起来您使用的CategoryPlot是不支持在域范围内缩放的

在此处输入图像描述

XYPlot如果您正在使用图表工厂,要允许缩放域轴切换到 a ,代码是

JFreeChart chart = ChartFactory.createXYLineChart(...);

如果您能够将情节投射到CategoryPlot出现问题的地方。我已经检查过LineChartDemo3 ,这段代码会导致错误(java.lang.ClassCastException):

try {
        final CategoryPlot cplot = (CategoryPlot) chart.getPlot();
    } catch (Exception e) {
        e.printStackTrace();
    }
于 2012-06-26T15:23:39.753 回答