你想用mysql数据库创建一个图表,所以我使用了jfreechart,我尝试了这个,
void getData() {
try {
String query="SELECT month,profit FROM profit";
JDBCCategoryDataset dataset=new JDBCCategoryDataset(Database.getConnection(), query);
JFreeChart chart =ChartFactory.createLineChart("Test", "Month", "Profit", dataset,PlotOrientation.VERTICAL,false,true,true);
BarRenderer renderer=new BarRenderer();
CategoryPlot plot=null;
ChartPanel panel=new ChartPanel(chart);
p_line.removeAll();
p_line.add(panel,BorderLayout.CENTER);
} catch (Exception e) {
e.printStackTrace();
}
}
但有例外,
Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: org/jfree/util/PublicCloneable
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
答案 0 :(得分:1)
您必须下载jcommon-<version>.jar
并将其添加到您的类路径中。因为这个jar包含类org/jfree/util/PublicCloneable