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 userInterface.StateAdminRole; import business.enterprise.PhdEnterprise; import business.organization.ClinicOrganization; import business.organization.HospitalOrganization; import business.organization.Organization; import java.awt.CardLayout; import java.awt.Color; import java.awt.Dimension; import java.awt.GradientPaint; import javax.swing.JPanel; import org.jfree.chart.ChartFactory; import org.jfree.chart.ChartPanel; import org.jfree.chart.JFreeChart; import org.jfree.chart.axis.CategoryAxis; import org.jfree.chart.axis.CategoryLabelPositions; import org.jfree.chart.axis.NumberAxis; import org.jfree.chart.labels.StandardCategorySeriesLabelGenerator; import org.jfree.chart.plot.CategoryPlot; import org.jfree.chart.plot.PlotOrientation; import org.jfree.chart.renderer.category.BarRenderer; import org.jfree.data.category.CategoryDataset; import org.jfree.data.category.DefaultCategoryDataset; /** * * @author Dev */ public class DecisionChart4JPanel extends javax.swing.JPanel { /** * Creates new form DecisionChart4JPanel */ JPanel userProcessContainer; PhdEnterprise e; public DecisionChart4JPanel(JPanel userProcessContainer, PhdEnterprise e) { initComponents();// throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. this.userProcessContainer = userProcessContainer; this.e = e; JFreeChart jfreechart1 = createChart1(createDataset1()); ChartPanel chartpanel1 = new ChartPanel(jfreechart1); chartpanel1.setPreferredSize(new Dimension(1000, 540)); jPanel1.add(chartpanel1); CardLayout layout1 = (CardLayout) jPanel1.getLayout(); layout1.next(jPanel1); } private static JFreeChart createChart1(CategoryDataset categorydataset) { JFreeChart jfreechart = ChartFactory.createBarChart("Total Vaccinations", "Hospital", "Value", categorydataset, PlotOrientation.VERTICAL, true, true, false); CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot(); categoryplot.setDomainGridlinesVisible(true); categoryplot.setRangeCrosshairVisible(true); categoryplot.setRangeCrosshairPaint(Color.blue); NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis(); numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); BarRenderer barrenderer = (BarRenderer) categoryplot.getRenderer(); barrenderer.setDrawBarOutline(false); GradientPaint gradientpaint = new GradientPaint(0.0F, 0.0F, Color.blue, 0.0F, 0.0F, new Color(0, 0, 64)); GradientPaint gradientpaint1 = new GradientPaint(0.0F, 0.0F, Color.green, 0.0F, 0.0F, new Color(0, 64, 0)); GradientPaint gradientpaint2 = new GradientPaint(0.0F, 0.0F, Color.red, 0.0F, 0.0F, new Color(64, 0, 0)); barrenderer.setSeriesPaint(0, gradientpaint); barrenderer.setSeriesPaint(1, gradientpaint1); barrenderer.setSeriesPaint(2, gradientpaint2); barrenderer.setLegendItemToolTipGenerator(new StandardCategorySeriesLabelGenerator("Tooltip: {0}")); CategoryAxis categoryaxis = categoryplot.getDomainAxis(); categoryaxis.setCategoryLabelPositions( CategoryLabelPositions.createUpRotationLabelPositions(0.52359877559829882D)); return jfreechart; } private CategoryDataset createDataset1() { String s = "Total Vaccinations"; //ArrayList<HospitalOrganization> temp = new ArrayList<>(); DefaultCategoryDataset defaultcategorydataset = new DefaultCategoryDataset(); for (Organization ho : e.getOrganizationDirectory().getOrganizationList()) { int total = 0; if (ho instanceof HospitalOrganization) { //temp.add((HospitalOrganization) ho); HospitalOrganization hoo = (HospitalOrganization) ho; total += hoo.getTotalVaccine(); for (Organization o3 : ho.getOrganizationDirectory().getOrganizationList()) { if (o3 instanceof ClinicOrganization) { ClinicOrganization coo = (ClinicOrganization) o3; total += coo.getTotalVaccine(); } } defaultcategorydataset.addValue(total, s, ho.getName()); } } return defaultcategorydataset; } /** * 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() { java.awt.GridBagConstraints gridBagConstraints; jPanel1 = new javax.swing.JPanel(); jLabel1 = new javax.swing.JLabel(); setLayout(new java.awt.GridBagLayout()); jPanel1.setBackground(new java.awt.Color(255, 255, 255)); jPanel1.setLayout(new java.awt.CardLayout()); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 1; gridBagConstraints.gridwidth = 2; gridBagConstraints.ipadx = 717; gridBagConstraints.ipady = 437; gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; gridBagConstraints.insets = new java.awt.Insets(29, 39, 11, 55); add(jPanel1, gridBagConstraints); jLabel1.setText("People Vaccined"); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 0; gridBagConstraints.ipadx = 194; gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; gridBagConstraints.insets = new java.awt.Insets(25, 340, 0, 0); add(jLabel1, gridBagConstraints); }// </editor-fold>//GEN-END:initComponents // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JLabel jLabel1; private javax.swing.JPanel jPanel1; // End of variables declaration//GEN-END:variables }