Post date: Mar 22, 2020 3:4:25 AM
Then after MySQL tutorial, it was time for a JFreeChart tutorial at https://www.tutorialspoint.com/jfreechart/jfreechart_quick_guide.htm .
I wish that the Internet would somehow make the dating more apparent. But as it turns out, there is updating to do which in the case of tutorials is harder than the tutorial itself.
JFreeChart 1.50 does not require a JCommon jar because since long ago, it has become standalone. So
org.jfree.ui.ApplicationFrame is now org.jfree.chart.ui.ApplicaIationFrame;
org.jfree.ui.RefineryUtilities is now org.jfree.chart.ui.UIUtils.
the IDE complained about new Double(20), so I changed it to 20,0 and that seemed to work.
import javax.swing.JPanel;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.data.general.DefaultPieDataset;
import org.jfree.data.general.PieDataset;
import org.jfree.chart.ui.ApplicationFrame;
import org.jfree.chart.ui.UIUtils;
/**
*
* @author Lenovo
*/
public class Charting extends ApplicationFrame {
public Charting (String title) {
super(title);
setContentPane(createDemoPanel());
}
private static PieDataset createDataset() {
DefaultPieDataset dataset = new DefaultPieDataset();
dataset.setValue("Iphone 5s", 20.0);
dataset.setValue("Samsung Grand", 20.0);
dataset.setValue("MotoG", 40.0);
dataset.setValue("Nokia Lumia", 10.0);
return dataset;
}
private static JFreeChart createChart(PieDataset dataset) {
JFreeChart chart = ChartFactory.createPieChart(
"Mobile Sales",
dataset,
true,
true,
false);
return chart;
}
private static JPanel createDemoPanel() {
JFreeChart chart = createChart(createDataset());
return new ChartPanel(chart);
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Charting demo = new Charting("Mobile Sales");
demo.setSize(560, 367);
UIUtils.centerFrameOnScreen(demo);
demo.setVisible(true);
}
}