Netbeans 8.0.2中的JFreechart& JDK 1.8.0无法正常工作

时间:2015-09-19 15:50:43

标签: java netbeans jfreechart

任何知道为什么JFreechart在我的NetBeans版本8.0.2和我的JDK版本1.8.0中不起作用的人。当我运行程序时,什么都没有显示?

JFreechart在我的系统中无效时,如何在系统中显示条形图?

有谁知道如何解决我的JFreechart问题?

我的进口是:

import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.category.DefaultCategoryDataset;

继承我的守则:

DefaultCategoryDataset barchartdata = new DefaultCategoryDataset();
barchartdata.setValue(100000,"","Name");
barchartdata.setValue(200000,"","Name");
barchartdata.setValue(500000,"","Name");    
JFreeChart barChart = ChartFactory.createAreaChart("Instructor Name","","", barchartdata, PlotOrientation.VERTICAL, true, true, true);
CategoryPlot barchrt = barChart.getCategoryPlot();
barchrt.setRangeGridlinePaint(Color.ORANGE); 
ChartPanel barPanel = new ChartPanel(barChart);
jPanel11.removeAll();
jPanel11.add(barPanel,BorderLayout.CENTER);            
jPanel11.validate();

我正在使用JfreeChart 1.0.19。

1 个答案:

答案 0 :(得分:1)

我运行了这个,只是将您的面板放入JFrame并在EventQueue上显示它,它似乎适用于Netbeans 8.0.2和JDK 1.8.0_60。

java.awt.EventQueue.invokeLater(() -> {
    DefaultCategoryDataset barchartdata = new DefaultCategoryDataset();
    barchartdata.setValue(100000, "", "Name");
    barchartdata.setValue(200000, "", "Name");
    barchartdata.setValue(500000, "", "Name");
    JFreeChart barChart = ChartFactory.createAreaChart("Instructor Name", "", "", barchartdata, PlotOrientation.VERTICAL, true, true, true);
    CategoryPlot barchrt = barChart.getCategoryPlot();
    barchrt.setRangeGridlinePaint(Color.ORANGE);
    ChartPanel barPanel = new ChartPanel(barChart);
    JPanel jPanel11 = new JPanel();
    jPanel11.removeAll();
    jPanel11.add(barPanel, BorderLayout.CENTER);
    jPanel11.validate();
    JFrame frame = new JFrame();
    frame.add(jPanel11);
    frame.pack();
    frame.setVisible(true);
});

制作了这个:

Screenshot of triangular graph

另外,我或许应该提一下,我创建了一个新的maven项目并将其作为一个依赖项添加。

<dependency>
    <groupId>org.jfree</groupId>
    <artifactId>jfreechart</artifactId>
    <version>1.0.19</version>
</dependency>