I am trying to create an example graph for a different project. The issue is that I am getting the error: Exception in thread “AWT-EventQueue-0” java.lang.RuntimeException: Uncompilable code regarding this line: dataset.addSeries(series); in this code:
public class Graphs extends javax.swing.JFrame {
/**
* Creates new form Graphs
*/
public Graphs() {
initComponents();
XYSeries series = new XYSeries("Weight Progress");
int zeropoint = 0;
for(int i = 0; i < 5; i++) {
series.add(i, i);
zeropoint = i;
}
XYSeriesCollection dataset = new XYSeriesCollection();
dataset.addSeries(series);
JFreeChart chart = ChartFactory.createXYLineChart("Name", "Week", "Time", dataset);
ChartPanel chartPanel = new ChartPanel(chart);
chartPanel.setSize(500, 500);
jPanel1.add(chartPanel); // Add chartPanel to jPanel1
jPanel1.revalidate();
jPanel1.repaint();
}
This code takes place in a JForm in Netbeans IDE.
I manipulated the values used to initialize the series, but it did not work.
New contributor
Michael Peters is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.