Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package com.jtk.pengelolaanujian.view.dashboard; import com.jtk.pengelolaanujian.controller.dashboard.TriggerDashboardController; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Dimension; import org.jfree.chart.ChartFactory; import org.jfree.chart.ChartPanel; import org.jfree.chart.JFreeChart; import org.jfree.chart.labels.StandardPieSectionLabelGenerator; import org.jfree.chart.plot.PiePlot; import org.jfree.data.general.DefaultPieDataset; import org.jfree.data.general.PieDataset; /** * * @author pahlevi */ public class PiePanelUjian extends javax.swing.JPanel { TriggerDashboardController triggerDashboardController = new TriggerDashboardController(); /** * Creates new form PiePanelUjian */ private JFreeChart piechart; private ChartPanel panel; private int terlalui; private int belum; public PiePanelUjian() { initComponents(); } public void preparation() { terlalui = 0; belum = 0; triggerDashboardController = new TriggerDashboardController(); panel = createChart(createData()); panel.setPreferredSize(new Dimension(250, 250)); setLayout(new BorderLayout()); add(panel, BorderLayout.CENTER); } private PieDataset createData() { terlalui = triggerDashboardController.checkUjianTerlalui(); belum = triggerDashboardController.cekUjianBelumTerlalui(); DefaultPieDataset data = new DefaultPieDataset(); data.setValue("Terlalui", terlalui); data.setValue("Belum", belum); return data; } private ChartPanel createChart(PieDataset data) { piechart = ChartFactory.createPieChart("Ujian Status", data, true, true, false); PiePlot plot = (PiePlot) piechart.getPlot(); plot.setSectionPaint("Terlalui", new Color(60, 70, 5)); plot.setSectionPaint("Belum", new Color(100, 20, 30)); plot.setNoDataMessage("Data Tidak Ada"); plot.setExplodePercent("data", 0.1D); plot.setLabelBackgroundPaint(new Color(255, 228, 225)); plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0} ({1})")); plot.setLegendLabelGenerator(new StandardPieSectionLabelGenerator()); // Key = 0 ----> section as String (Windows, Linux, Lainnya) // Key = 1 ----> section as value (300,200,100) // KEy - 2 ----> section as percentage (50%,33%,17 %) Muncul jika aplikasi telah di running plot.setSimpleLabels(true); plot.setInteriorGap(0.0D); return new ChartPanel(piechart); } /** * This method is called from within the constructor to initialize the form. * WARNING: Do NOT modify this code. The content of this method is always * regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); this.setLayout(layout); layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 400, Short.MAX_VALUE)); layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 300, Short.MAX_VALUE)); }// </editor-fold>//GEN-END:initComponents // Variables declaration - do not modify//GEN-BEGIN:variables // End of variables declaration//GEN-END:variables }