Anybody who knows why JFreechart
is not working in my NetBeans version 8.0.2 and my JDK version 1.8.0. When I run the program, nothing displays?
How can I show a bar graph in my system when JFreechart
is not working in my system?
Anybody who knows how to solve my JFreechart
problem?
My Imports are:
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;
Heres my Code:
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();
I'm using JfreeChart 1.0.19.
I ran this which just put your panel into a JFrame and showed it on the EventQueue and it seemed to work in Netbeans 8.0.2 and 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);
});
Produced this:
Also I should perhaps mention that I created a new maven project and added this as a dependancy.
<dependency>
<groupId>org.jfree</groupId>
<artifactId>jfreechart</artifactId>
<version>1.0.19</version>
</dependency>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.