JFreechart创建具有较大值的NumberAxis时出错

时间:2014-07-15 10:23:49

标签: java charts jfreechart

使用JFreechart创建图表时出现以下错误。如果手动或在代码中增加帧大小,则图表会正确显示。我在面板中有多个图,所以尺寸是一个约束。

JFreechart:1.0.18 Windows 7 Enterprise上的Java 1.8.0_05。

非常感谢任何帮助。提前致谢。

Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: Must be finite.
at org.jfree.chart.axis.NumberTickUnitSource.getCeilingTickUnit(NumberTickUnitSource.java:114)
at org.jfree.chart.axis.NumberAxis.selectHorizontalAutoTickUnit(NumberAxis.java:855)
at org.jfree.chart.axis.NumberAxis.selectAutoTickUnit(NumberAxis.java:824)
at org.jfree.chart.axis.NumberAxis.refreshTicksHorizontal(NumberAxis.java:949)
at org.jfree.chart.axis.NumberAxis.refreshTicks(NumberAxis.java:921)
at org.jfree.chart.axis.ValueAxis.reserveSpace(ValueAxis.java:820)
at org.jfree.chart.plot.XYPlot.calculateDomainAxisSpace(XYPlot.java:3029)
at org.jfree.chart.plot.XYPlot.calculateAxisSpace(XYPlot.java:2988)
at org.jfree.chart.plot.XYPlot.draw(XYPlot.java:3130)
at org.jfree.chart.JFreeChart.draw(JFreeChart.java:1230)
at org.jfree.chart.ChartPanel.paintComponent(ChartPanel.java:1629)
at javax.swing.JComponent.paint(JComponent.java:1053)
at javax.swing.JComponent.paintChildren(JComponent.java:886)
at javax.swing.JComponent.paint(JComponent.java:1062)
at javax.swing.JComponent.paintChildren(JComponent.java:886)
at javax.swing.JComponent.paint(JComponent.java:1062)
at javax.swing.JLayeredPane.paint(JLayeredPane.java:586)
at javax.swing.JComponent.paintChildren(JComponent.java:886)
at javax.swing.JComponent.paintToOffscreen(JComponent.java:5224)
at javax.swing.RepaintManager$PaintManager.paintDoubleBuffered(RepaintManager.java:1532)
at javax.swing.RepaintManager$PaintManager.paint(RepaintManager.java:1455)
at javax.swing.RepaintManager.paint(RepaintManager.java:1252)
at javax.swing.JComponent.paint(JComponent.java:1039)
at java.awt.GraphicsCallback$PaintCallback.run(GraphicsCallback.java:39)
at sun.awt.SunGraphicsCallback.runOneComponent(SunGraphicsCallback.java:79)
at sun.awt.SunGraphicsCallback.runComponents(SunGraphicsCallback.java:116)
at java.awt.Container.paint(Container.java:1973)
at java.awt.Window.paint(Window.java:3901)
at javax.swing.RepaintManager$3.run(RepaintManager.java:822)
at javax.swing.RepaintManager$3.run(RepaintManager.java:794)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:75)
at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:794)
at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:769)
at javax.swing.RepaintManager.prePaintDirtyRegions(RepaintManager.java:718)
at javax.swing.RepaintManager.access$1100(RepaintManager.java:62)
at javax.swing.RepaintManager$ProcessingRunnable.run(RepaintManager.java:1680)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:744)
at java.awt.EventQueue.access$400(EventQueue.java:97)
at java.awt.EventQueue$3.run(EventQueue.java:697)
at java.awt.EventQueue$3.run(EventQueue.java:691)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:75)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:714)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)

java代码如下:

import java.awt.BorderLayout;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JLabel;

import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;

public class JFreechartTest {

    public static void main(String[] args) {

        JFrame frame = new JFrame();
        frame.getContentPane().setLayout(new BorderLayout());
        frame.getContentPane().add(new JLabel("Test"), BorderLayout.NORTH);
        frame.getContentPane().add(getJFreeChart(), BorderLayout.CENTER);

        frame.setSize(400, 400);
        frame.setLocationRelativeTo(null);
        frame.setTitle("test");
        frame.setVisible(true);
    }

    private static JComponent getJFreeChart(){
        XYSeriesCollection dataset = new XYSeriesCollection();
        XYSeries series = new XYSeries("Curve 1", false);

        series.add(0.1639147148815060, 1);
        series.add(1.0631847644348063, 2);
        series.add(1.1639841138915930, 3);
        series.add(15.832345248913860, 4);
        series.add(12.639847148911010, 5);
        series.add(7682421148.0915560, 6);
        series.add(16398471489180.260, 7);
        series.add(263973784891506.01, 8);
        series.add(143984714832406.01, 9);
        series.add(0.1142278254296188E17, 10);
        series.add(439990854230983.1, 11);
        dataset.addSeries(series);

        NumberAxis rangeAxis = new NumberAxis("Range");
        NumberAxis domainAxis = new NumberAxis("Domain");
        domainAxis.setInverted(true);

        XYLineAndShapeRenderer lineRenderer = new XYLineAndShapeRenderer();
        lineRenderer.setUseFillPaint(true);
        lineRenderer.setBaseShapesVisible(false);
        lineRenderer.setAutoPopulateSeriesShape(true);

        XYPlot plot = new XYPlot(dataset, domainAxis, rangeAxis, lineRenderer);
        JFreeChart chart = new JFreeChart(null, null, plot, false);

        return new ChartPanel(chart);
    }

}

编辑: 我在Linux(Red Hat Enterprise Server Release 6.1)上测试了上面的代码并得到了同样的错误。

0 个答案:

没有答案