Cara Membuat Diagram Presentase Covid-19

Membuat Data ODP, PDP, dan Meninggal Karena Virus Covid-19

Halo teman-teman pada blog saya akan menjelaskan cara membuat grafik data terkena Covid-19 dengan program Java. simak dan perhatikan 
Sama seperti grafik sebelumnya kita buat Java class terlebih dahulu seperti di bawah


Setelah itu buat JFrame data


Jangan lupa tambah Librarynya


Import Library lagi


Bisa di-copy di bawah

import java.awt.GridLayout;
 import javax.swing.JFrame;
 import javax.swing.JPanel;
 import javax.swing.SwingUtilities;
 import javax.swing.UIManager;
 import org.jfree.chart.ChartFactory; 
 import org.jfree.chart.ChartPanel;
 import org.jfree.chart.JFreeChart;
 import org.jfree.chart.plot.PiePlot3D;
 import org.jfree.data.general.DefaultPieDataset;
 import org.jfree.data.general.PieDataset;
 import org.jfree.util.Rotation;

Kemudian masukkan sourcenya


Bisa di-copy di bawah 

public class Grafik_pie_covid extends JFrame{
   
    double n1_bud=0, n2_bud=0, n3_bud=0, n4_bud=0;
    public void setNilai (String nil1, String nil2, String nil3, String nil4){
        try{
            n1_bud = Double.parseDouble(nil1);
        }catch (NumberFormatException e){}
        try{
            n2_bud = Double.parseDouble(nil2);
        }catch (NumberFormatException e){}
        try{
            n3_bud = Double.parseDouble(nil3);
        }catch (NumberFormatException e){}
        try{
            n4_bud = Double.parseDouble(nil4);
        }catch (NumberFormatException e){}
        // CREATE SETTING FOR THE FRAME
        this.setSize(600,400);
        this.setTitle("DIAGRAM PIE Covid-19 Budi");
        this.setLocationRelativeTo(null);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        // CREATE DATA FOR BOTH PIE CHART
        PieDataset daset1_bud = buildData1();
        PieDataset daset2_bud = buildData2();
        // CREATE PIE CHART BASED ON PIE DATASET
        JFreeChart chart1_bud = buildChart1(daset1_bud,"DATA COVID 19 TAngerang");
        JFreeChart chart2_bud = buildChart2(daset2_bud,"PERBANDINGAN DATA KESELAMATAN");
        // CREATE JPANEL TO INPUT GRAPHICS PIE WITH GRID 2,1
        JPanel pane = new JPanel(new GridLayout(2,1));
        // ADDING CHART 1 AND 2 TO PANEL
        pane.add(new ChartPanel(chart1_bud));
        pane.add(new ChartPanel(chart2_bud));
        // CREATE CONTENT FOR PANEL
        this.setContentPane(pane);
       
    }

Setelah itu set frame, buat frame pada kelas jframenya seperti dibawah 

Setelah membuatnya mirip atau terserah kalian, kita set source panelnya; 

Bisa di-copy di bawah 


    private void Simpan_budActionPerformed(java.awt.event.ActionEvent evt) {                                          
        // TODO add your handling code here:
        int a, b, c, d;
       

        a = Integer.parseInt(pos_bud.getText());
        b = Integer.parseInt(odp_bud.getText());
        c = Integer.parseInt(pdp_bud.getText());
        d = Integer.parseInt(dd_bud.getText());
       
        num1_bud.setText(""+a);
        num2_bud.setText(""+b);
        num3_bud.setText(""+c);
        num4_bud.setText(""+d);
    }                                         
    private void Grafik_budActionPerformed(java.awt.event.ActionEvent evt) {                                          
        // TODO add your handling code here:
        Grafik_pie_covid Grafik_bud = new Grafik_pie_covid();
        Grafik_ozy.setNilai(num1_bud.getText(),num2_bud.getText(),num3_bud.getText(),num4_bud.getText());
        Grafik_bud.setVisible(true);
    }   
   
Setelah itu buat kriteria pie


 

Bisa di-copy di bawah


    private JFreeChart buildChart1 (PieDataset daset1_bud, String judul){
        JFreeChart chart1_bud = ChartFactory.createPieChart3D(judul,
                daset1_bud,
                true,
                true,
                false);
       
        PiePlot3D plot_bud = (PiePlot3D) chart1_bud.getPlot();
            plot_bud.setStartAngle(0);
            plot_bud.setDirection(Rotation.ANTICLOCKWISE);
            plot_bud.setForegroundAlpha(0.5f);
           
            return chart1_bud;
}
    private JFreeChart buildChart2 (PieDataset daset2_bud, String judul){
        JFreeChart chart2_bud = ChartFactory.createPieChart3D(judul,
                daset2_bud,
                true,
                true,
                false);
        PiePlot3D plot_bud = (PiePlot3D) chart2_bud.getPlot();
            plot_bud.setStartAngle(0);
            plot_bud.setDirection(Rotation.ANTICLOCKWISE);
            plot_bud.setForegroundAlpha(0.5f);
           
            return chart2_bud;
    }

Setelah itu buat main methodnya


   
Bisa di-copy disini

public static void main (String[] args){
        try{
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        }catch (Exception e){}
        SwingUtilities.invokeLater(new Runnable(){
            @Override
            public void run(){
                new Grafik_pie_covid().setVisible(true);
            }
        });
    }
   
 
Maka hasil runnya


SUKSES

Komentar