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 tusys.view; import java.awt.Color; import java.awt.Dimension; import java.awt.Font; import java.awt.FontMetrics; import java.awt.Graphics; import java.awt.List; import java.util.ArrayList; 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.CategoryDataset; import org.jfree.data.category.DefaultCategoryDataset; import org.jfree.ui.ApplicationFrame; import org.jfree.ui.RefineryUtilities; /** * * @author Candy Olivia Mawalim */ public class jPanelChart extends javax.swing.JPanel { private static java.util.List<String> ruangan = new ArrayList<String>() { { add("7601"); add("7602"); add("7603"); } }; private static java.util.List<Integer> values = new ArrayList<Integer>() { { add(10); add(5); add(4); } }; /** * Creates new form jPanelChart */ public jPanelChart(String chartTitle) { initComponents(); JFreeChart barChart = ChartFactory.createBarChart(chartTitle, "Category", "Score", createDataset(), PlotOrientation.VERTICAL, true, true, false); ChartPanel chartPanel = new ChartPanel(barChart); chartPanel.setPreferredSize(new java.awt.Dimension(560, 367)); add(chartPanel); } private CategoryDataset createDataset() { final String fiat = "FIAT"; final String audi = "AUDI"; final String ford = "FORD"; final String speed = "Speed"; final String millage = "Millage"; final String userrating = "User Rating"; final String safety = "safety"; final DefaultCategoryDataset dataset = new DefaultCategoryDataset(); dataset.addValue(1.0, fiat, speed); dataset.addValue(3.0, fiat, userrating); dataset.addValue(5.0, fiat, millage); dataset.addValue(5.0, fiat, safety); dataset.addValue(5.0, audi, speed); dataset.addValue(6.0, audi, userrating); dataset.addValue(10.0, audi, millage); dataset.addValue(4.0, audi, safety); dataset.addValue(4.0, ford, speed); dataset.addValue(2.0, ford, userrating); dataset.addValue(3.0, ford, millage); dataset.addValue(6.0, ford, safety); return dataset; } private void getRuangan() { } /** * 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() { jPanel1 = new javax.swing.JPanel(); javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); jPanel1.setLayout(jPanel1Layout); jPanel1Layout.setHorizontalGroup(jPanel1Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 400, Short.MAX_VALUE)); jPanel1Layout.setVerticalGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 300, Short.MAX_VALUE)); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); this.setLayout(layout); layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)); layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent( jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)); }// </editor-fold>//GEN-END:initComponents // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JPanel jPanel1; // End of variables declaration//GEN-END:variables }