GRAFIK SEDERHANA DI JAVA NETBEAN
1. Buka netbean
2.
Buat
Project baru(nama terserah)
3.
Buat
Package baru(nama terserah) >Buat Jframe(beri nama chartgaris)
4.
Masukkan
Lybrary Jfreechart > Klik kanan Lybrary > AddJar> Arahkan ke Lybrary
JFreeChart
5.
Masukkan
kode berikut yang berwarna hijau
6. Selesai > coba di Run
package BAKERY_FOOD;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import
org.jfree.chart.plot.PlotOrientation;
import
org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.ui.RefineryUtilities;
public class chartgaris extends
javax.swing.JFrame {
public chartgaris(String applicationTitle , String chartTitle) {
JFreeChart lineChart = ChartFactory.createLineChart(
chartTitle,
"Tahun"," Angka Perkembangan",
createDataset(),
PlotOrientation.VERTICAL,
true,true,false);
ChartPanel chartPanel = new ChartPanel( lineChart );
chartPanel.setPreferredSize( new
java.awt.Dimension( 560 , 367 ) );
setContentPane( chartPanel );
}
private DefaultCategoryDataset createDataset(
) {
DefaultCategoryDataset dataset = new DefaultCategoryDataset( );
dataset.addValue( 15 , "Recipe" , "2010" );
dataset.addValue( 300 , "Recipe" , "2011" );
dataset.addValue( 60 , "Recipe" , "2012" );
dataset.addValue( 70 , "Recipe" , "2013" );
dataset.addValue( 115 , "Recipe" , "2014" );
dataset.addValue( 400 , "Recipe" ,
"2015" );
dataset.addValue( 300 , "Recipe" , "2016" );
dataset.addValue( 250 , "Recipe" , "2017" );
return dataset;
}
public static void main(String
args[]) {
chartgaris chart = new chartgaris(
"" ,
"GRAFIK PENJUALAN TH 2010-2017");
java.awt.EventQueue.invokeLater(new
Runnable() {
public void run() {
}
});
}
Ini Hasilnya