List of usage examples for org.jfree.chart ChartFactory createPieChart3D
public static JFreeChart createPieChart3D(String title, PieDataset dataset, boolean legend, boolean tooltips, boolean urls)
From source file:UserInterface.CustomerRole.CustomerTaxJPanel.java
public void displayChart(Date date1) { int total = 0; int k;//from w w w . j a va2s . c o m int count = 0; int avg = 0; Sensor s = (Sensor) jTable1.getValueAt(0, 0); Date b = s.getDate(); DateFormat formatter = new SimpleDateFormat("MM/dd/yy"); Date date = new Date(); try { date = formatter.parse("12/11/16"); } catch (Exception e) { } //date = System.out.println(jTable1.getValueAt(0, 5)); System.out.println(jTable1.getValueAt(0, 4)); list = new ArrayList<>(); for (int l = 0; l < jTable1.getRowCount(); l++) { if (date.getDate() == b.getDate()) { Sensor s1 = (Sensor) jTable1.getValueAt(l, 0); total = total + s1.getCurrentEmissionCO2(); count++; } } avg = total / count; list.add(avg); int avg1 = 0; for (int l = 0; l < jTable1.getRowCount(); l++) { if (date.getDate() == b.getDate()) { Sensor s1 = (Sensor) jTable1.getValueAt(l, 0); total = total + s1.getCurrentEmissionCO2(); count++; } } avg = total / count; list.add(avg); for (int l = 0; l < jTable1.getRowCount(); l++) { if (date.getDate() == b.getDate()) { Sensor s1 = (Sensor) jTable1.getValueAt(l, 0); total = total + s1.getNormalCO2(); count++; } } avg1 = total / count; int avg3 = 0; for (int l = 0; l < jTable1.getRowCount(); l++) { if (date.getDate() == b.getDate()) { Sensor s1 = (Sensor) jTable1.getValueAt(l, 0); total = total + s1.getCurrentEmissionNOx(); count++; } } avg3 = total / count; int avg4 = 0; for (int l = 0; l < jTable1.getRowCount(); l++) { if (date.getDate() == b.getDate()) { Sensor s1 = (Sensor) jTable1.getValueAt(l, 0); total = total + s1.getNormalNOx(); count++; } } avg4 = total / count; int avg5 = 0; for (int l = 0; l < jTable1.getRowCount(); l++) { if (date.getDate() == b.getDate()) { Sensor s1 = (Sensor) jTable1.getValueAt(l, 0); total = total + s1.getSolarCurrentEmissionCO2(); count++; } } avg5 = total / count; int avg6 = 0; for (int l = 0; l < jTable1.getRowCount(); l++) { if (date.getDate() == b.getDate()) { Sensor s1 = (Sensor) jTable1.getValueAt(l, 0); total = total + s1.getSolarNormalCO2(); count++; } } avg6 = total / count; int avg7 = 0; for (int l = 0; l < jTable1.getRowCount(); l++) { if (date.getDate() == b.getDate()) { Sensor s1 = (Sensor) jTable1.getValueAt(l, 0); total = total + s1.getSolarCurrentEmissionNOx(); count++; } } avg7 = total / count; int avg8 = 0; for (int l = 0; l < jTable1.getRowCount(); l++) { if (date.getDate() == b.getDate()) { Sensor s1 = (Sensor) jTable1.getValueAt(l, 0); total = total + s1.getSolarNormalNOx(); count++; } } avg8 = total / count; int combo = avg + avg3; int combo1 = avg5 + avg7; DefaultPieDataset dataset22 = new DefaultPieDataset(); dataset22.setValue("Fuel Emission", new Integer(combo)); dataset22.setValue("Solar Emission ", new Integer(combo1)); JFreeChart chart22 = ChartFactory.createPieChart3D("Comparison Chart ", // chart title dataset22, // data true, // include legend true, false); final PiePlot3D plot = (PiePlot3D) chart22.getPlot(); plot.setStartAngle(270); plot.setForegroundAlpha(0.60f); plot.setInteriorGap(0.02); ChartFrame frame33 = new ChartFrame("3D Pie Chart for EMission Comparison from different sources", chart22); frame33.setVisible(true); frame33.setSize(500, 400); DefaultCategoryDataset dataset = new DefaultCategoryDataset(); dataset.setValue(avg, b, "curr CO2"); dataset.setValue(avg1, b, "normal CO2"); dataset.setValue(avg3, b, "current NOx"); dataset.setValue(avg4, b, "normal NOx"); //dataset.setValue(a1,b1,"current"); JFreeChart chart = ChartFactory.createBarChart("Normal Fuel Emission Chart", "CO2 Emission", "in (g/KM)", dataset, PlotOrientation.VERTICAL, false, false, false); CategoryPlot p = chart.getCategoryPlot(); p.setRangeGridlinePaint(Color.BLACK); ChartFrame frame = new ChartFrame("Bar Chart for Customer", chart); frame.setVisible(true); frame.setSize(500, 400); DefaultCategoryDataset dataset1 = new DefaultCategoryDataset(); dataset1.setValue(avg5, b, "curr CO2"); dataset1.setValue(avg6, b, "normal CO2"); dataset1.setValue(avg7, b, "current NOx"); dataset1.setValue(avg8, b, "normal NOx"); //dataset.setValue(a1,b1,"current"); JFreeChart chart2 = ChartFactory.createBarChart("Solar Emission Chart", "CO2 Emission", "in (g/KM)", dataset1, PlotOrientation.VERTICAL, false, false, false); CategoryPlot p1 = chart.getCategoryPlot(); p1.setRangeGridlinePaint(Color.BLACK); ChartFrame frame1 = new ChartFrame("Bar Chart for Customer", chart2); frame1.setVisible(true); frame1.setSize(500, 400); }
From source file:swing.PrincipalMDI.java
private void jMenuItem6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem6ActionPerformed // TODO add your handling code here: List<Ticket> serviceList = new ArrayList<>(); for (Ticket t : list) { System.out.println(t.getSousService().getNom()); if (t.getSousService().getNom().equals("Malpropret")) { serviceList.add(t);/*from ww w .j a v a 2s .co m*/ } } DefaultPieDataset pieDataSet = new DefaultPieDataset(); for (Ticket ticket : serviceList) { pieDataSet.setValue(ticket.getSousService().getNom(), 1); } JFreeChart chart = ChartFactory.createPieChart3D("Camembert", pieDataSet, true, true, true); PiePlot3D p = (PiePlot3D) chart.getPlot(); //p.setForegroundAlpha(TOP_ALIGNMENT); ChartFrame frame = new ChartFrame("camembert", chart); frame.setVisible(true); frame.setSize(600, 500); }
From source file:view.statistics.IssueChart.java
private void showChartBtn1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_showChartBtn1ActionPerformed String option = "" + optionCombo.getSelectedItem(); String chartType = "" + chartCombo.getSelectedItem(); if (option.equals("Blood Components")) { try {// w w w. j a v a2 s .c om int cryoCount = 0; int ffpCount = 0; int freshBloodCount = 0; int plasmaCount = 0; int plateletsCount = 0; ResultSet rst = null; String year = "" + yearCombo.getSelectedItem(); String month = "" + monthCombo.getSelectedItem(); rst = IssueController.getIssueInfo(year, month); while (rst.next()) { String type = rst.getString("BloodType"); if (type.equalsIgnoreCase("CRYO")) { cryoCount++; } else if (type.equalsIgnoreCase("FFP")) { ffpCount++; } else if (type.equalsIgnoreCase("Fresh Blood")) { freshBloodCount++; } else if (type.equalsIgnoreCase("Plasma/CSP")) { plasmaCount++; } else if (type.equalsIgnoreCase("Platelets")) { plateletsCount++; } } if (chartType.equals("Pie Chart")) { DefaultPieDataset piedataset = new DefaultPieDataset(); piedataset.setValue("CRYO", cryoCount); piedataset.setValue("FFP", ffpCount); piedataset.setValue("Fresh Blood", freshBloodCount); piedataset.setValue("Plasma/CSP", plasmaCount); piedataset.setValue("Platelets", plateletsCount); JFreeChart chart = ChartFactory.createPieChart3D("Issued Blood Components", piedataset, true, true, true); ChartPanel panel = new ChartPanel(chart); chart.setBackgroundPaint(Color.PINK); chart.getTitle().setPaint(Color.RED); chartArea.add(panel); panel.setSize(chartArea.getSize()); panel.setVisible(true); } else { DefaultCategoryDataset dataset = new DefaultCategoryDataset(); dataset.setValue(cryoCount, "Issued Values", "CRYO"); dataset.setValue(ffpCount, "Issued Values", "FFP"); dataset.setValue(freshBloodCount, "Issued Values", "Fresh Blood"); dataset.setValue(plasmaCount, "Issued Values", "Plasma/CSP"); dataset.setValue(plateletsCount, "Issued Values", "Platelets"); if (chartType.equals("Bar Chart")) { JFreeChart chart = ChartFactory.createBarChart3D("Issued Bloood Components", "Blood Component", "Issued Values", dataset, PlotOrientation.VERTICAL, false, true, false); chart.setBackgroundPaint(Color.PINK); chart.getTitle().setPaint(Color.RED); CategoryPlot p = chart.getCategoryPlot(); p.setRangeGridlinePaint(Color.BLUE); ChartPanel panel = new ChartPanel(chart); chartArea.add(panel); panel.setSize(chartArea.getSize()); panel.setVisible(true); } else if (chartType.equals("Line Chart")) { JFreeChart chart = ChartFactory.createLineChart3D("Issued Blood Components", "Blood Component", "Issued Values", dataset, PlotOrientation.VERTICAL, false, true, false); chart.setBackgroundPaint(Color.PINK); chart.getTitle().setPaint(Color.RED); CategoryPlot p = chart.getCategoryPlot(); p.setRangeGridlinePaint(Color.BLUE); ChartPanel panel = new ChartPanel(chart); chartArea.add(panel); panel.setSize(chartArea.getSize()); panel.setVisible(true); } } } catch (SQLException ex) { JOptionPane.showMessageDialog(null, "-1Data Error!", "Warning!", JOptionPane.OK_OPTION); } catch (ClassNotFoundException ex) { Logger.getLogger(IssueChart.class.getName()).log(Level.SEVERE, null, ex); } } else if (option.equals("Blood Groups")) { try { int Apos = 0; int Bpos = 0; int Aneg = 0; int Bneg = 0; int ABpos = 0; int Opos = 0; int ABneg = 0; int Oneg = 0; ResultSet rst = null; String year = "" + yearCombo.getSelectedItem(); String month = "" + monthCombo.getSelectedItem(); rst = IssueController.getIssueInfo(year, month); while (rst.next()) { String type = rst.getString("BloodGroup"); if (type.equalsIgnoreCase("A+")) { Apos++; } else if (type.equalsIgnoreCase("B+")) { Bpos++; } else if (type.equalsIgnoreCase("A-")) { Aneg++; } else if (type.equalsIgnoreCase("B-")) { Bneg++; } else if (type.equalsIgnoreCase("AB+")) { ABpos++; } else if (type.equalsIgnoreCase("AB-")) { ABneg++; } else if (type.equalsIgnoreCase("O+")) { Opos++; } else if (type.equalsIgnoreCase("O-")) { Oneg++; } } if (chartType.equals("Pie Chart")) { DefaultPieDataset piedataset = new DefaultPieDataset(); piedataset.setValue("A+", Apos); piedataset.setValue("A-", Aneg); piedataset.setValue("B+", Bpos); piedataset.setValue("B-", Bneg); piedataset.setValue("AB+", ABpos); piedataset.setValue("AB-", ABneg); piedataset.setValue("O+", Opos); piedataset.setValue("O-", Oneg); JFreeChart chart = ChartFactory.createPieChart3D("Issued Blood Groups", piedataset, true, true, true); ChartPanel panel = new ChartPanel(chart); chart.setBackgroundPaint(Color.PINK); chart.getTitle().setPaint(Color.RED); chartArea.add(panel); panel.setSize(chartArea.getSize()); panel.setVisible(true); } else { DefaultCategoryDataset dataset = new DefaultCategoryDataset(); dataset.setValue(Apos, "Issued Values", "A+"); dataset.setValue(Aneg, "Issued Values", "A-"); dataset.setValue(Bpos, "Issued Values", "B+"); dataset.setValue(Bneg, "Issued Values", "B-"); dataset.setValue(ABpos, "Issued Values", "AB+"); dataset.setValue(ABneg, "Issued Values", "AB-"); dataset.setValue(Opos, "Issued Values", "O+"); dataset.setValue(Oneg, "Issued Values", "O-"); if (chartType.equals("Bar Chart")) { JFreeChart chart = ChartFactory.createBarChart3D("Issued Bloood Groups", "Blood Group", "Issued Values", dataset, PlotOrientation.VERTICAL, false, true, false); chart.setBackgroundPaint(Color.PINK); chart.getTitle().setPaint(Color.RED); CategoryPlot p = chart.getCategoryPlot(); p.setRangeGridlinePaint(Color.BLUE); ChartPanel panel = new ChartPanel(chart); chartArea.add(panel); panel.setSize(chartArea.getSize()); panel.setVisible(true); } else if (chartType.equals("Line Chart")) { JFreeChart chart = ChartFactory.createLineChart3D("Issued Blood Groups", "Blood Group", "Issued Values", dataset, PlotOrientation.VERTICAL, false, true, false); chart.setBackgroundPaint(Color.PINK); chart.getTitle().setPaint(Color.RED); CategoryPlot p = chart.getCategoryPlot(); p.setRangeGridlinePaint(Color.BLUE); ChartPanel panel = new ChartPanel(chart); chartArea.add(panel); panel.setSize(chartArea.getSize()); panel.setVisible(true); } } } catch (SQLException ex) { JOptionPane.showMessageDialog(null, "0Data Error!", "Warning!", JOptionPane.OK_OPTION); } catch (ClassNotFoundException ex) { Logger.getLogger(IssueChart.class.getName()).log(Level.SEVERE, null, ex); } } else if (option.equals("Gender")) { try { int male = 0; int female = 0; ResultSet rst = null; String year = "" + yearCombo.getSelectedItem(); String month = "" + monthCombo.getSelectedItem(); rst = IssueController.getRequesteeInfo(year, month); while (rst.next()) { String type = rst.getString("Gender"); if (type.equalsIgnoreCase("Male")) { male++; } else if (type.equalsIgnoreCase("Female")) { female++; } } if (chartType.equals("Pie Chart")) { DefaultPieDataset piedataset = new DefaultPieDataset(); piedataset.setValue("Male", male); piedataset.setValue("Female", female); JFreeChart chart = ChartFactory.createPieChart3D("Blood Requestees", piedataset, true, true, true); ChartPanel panel = new ChartPanel(chart); chart.setBackgroundPaint(Color.PINK); chart.getTitle().setPaint(Color.RED); chartArea.add(panel); panel.setSize(chartArea.getSize()); panel.setVisible(true); } else { DefaultCategoryDataset dataset = new DefaultCategoryDataset(); dataset.setValue(male, "", "Male"); dataset.setValue(female, "", "Female"); if (chartType.equals("Bar Chart")) { JFreeChart chart = ChartFactory.createBarChart3D("Blood Requestees", "Gender", "", dataset, PlotOrientation.VERTICAL, false, true, false); chart.setBackgroundPaint(Color.PINK); chart.getTitle().setPaint(Color.RED); CategoryPlot p = chart.getCategoryPlot(); p.setRangeGridlinePaint(Color.BLUE); ChartPanel panel = new ChartPanel(chart); chartArea.add(panel); panel.setSize(chartArea.getSize()); panel.setVisible(true); } else if (chartType.equals("Line Chart")) { JFreeChart chart = ChartFactory.createLineChart3D("Blood Requestees", "Gender", "", dataset, PlotOrientation.VERTICAL, false, true, false); chart.setBackgroundPaint(Color.PINK); chart.getTitle().setPaint(Color.RED); CategoryPlot p = chart.getCategoryPlot(); p.setRangeGridlinePaint(Color.BLUE); ChartPanel panel = new ChartPanel(chart); chartArea.add(panel); panel.setSize(chartArea.getSize()); panel.setVisible(true); } } } catch (SQLException ex) { JOptionPane.showMessageDialog(null, "1Data Error!", "Warning!", JOptionPane.OK_OPTION); } catch (ClassNotFoundException ex) { Logger.getLogger(IssueChart.class.getName()).log(Level.SEVERE, null, ex); } } else if (option.equals("Hospitals")) { try { String[] hospitals = new String[10]; int[] hospitalCount = new int[10]; int noOfHospitals = 0; ResultSet rst = null; String year = "" + yearCombo.getSelectedItem(); String month = "" + monthCombo.getSelectedItem(); rst = SampleDetailsController.getAllHospitals(); while (rst.next()) { hospitals[noOfHospitals] = rst.getString("Name"); hospitalCount[noOfHospitals] = 0; noOfHospitals++; } rst = IssueController.getRequesteeInfo(year, month); while (rst.next()) { String type = rst.getString("Hospital"); for (int i = 0; i < noOfHospitals; i++) { if (type.equalsIgnoreCase(hospitals[i])) { hospitalCount[i]++; } } } if (chartType.equals("Pie Chart")) { DefaultPieDataset piedataset = new DefaultPieDataset(); for (int i = 0; i < noOfHospitals; i++) { piedataset.setValue(hospitals[i], hospitalCount[i]); } JFreeChart chart = ChartFactory.createPieChart3D("Issued Hospitals", piedataset, true, true, true); ChartPanel panel = new ChartPanel(chart); chart.setBackgroundPaint(Color.PINK); chart.getTitle().setPaint(Color.RED); chartArea.add(panel); panel.setSize(chartArea.getSize()); panel.setVisible(true); } else { DefaultCategoryDataset dataset = new DefaultCategoryDataset(); for (int i = 0; i < noOfHospitals; i++) { dataset.setValue(hospitalCount[i], "Issued Values", hospitals[i]); } if (chartType.equals("Bar Chart")) { JFreeChart chart = ChartFactory.createBarChart3D("Issued Hospitals", "Hospital", "Issued Values", dataset, PlotOrientation.VERTICAL, false, true, false); chart.setBackgroundPaint(Color.PINK); chart.getTitle().setPaint(Color.RED); CategoryPlot p = chart.getCategoryPlot(); p.setRangeGridlinePaint(Color.BLUE); ChartPanel panel = new ChartPanel(chart); chartArea.add(panel); panel.setSize(chartArea.getSize()); panel.setVisible(true); } else if (chartType.equals("Line Chart")) { JFreeChart chart = ChartFactory.createLineChart3D("Issued Hospitals", "Hospital", "Issued Values", dataset, PlotOrientation.VERTICAL, false, true, false); chart.setBackgroundPaint(Color.PINK); chart.getTitle().setPaint(Color.RED); CategoryPlot p = chart.getCategoryPlot(); p.setRangeGridlinePaint(Color.BLUE); ChartPanel panel = new ChartPanel(chart); chartArea.add(panel); panel.setSize(chartArea.getSize()); panel.setVisible(true); } } } catch (SQLException ex) { ex.printStackTrace(); JOptionPane.showMessageDialog(null, "2Data Error!", "Warning!", JOptionPane.OK_OPTION); } catch (ClassNotFoundException ex) { Logger.getLogger(IssueChart.class.getName()).log(Level.SEVERE, null, ex); } } else if (option.equals("Age Groups")) { try { int[] ages = new int[10]; for (int i = 0; i < 10; i++) { ages[i] = 0; } ResultSet rst = null; String year = "" + yearCombo.getSelectedItem(); String month = "" + monthCombo.getSelectedItem(); rst = IssueController.getRequesteeInfo(year, month); while (rst.next()) { int age = Integer.parseInt(rst.getString("Age")); if (age <= 10 && age > 0) { ages[0]++; } else if (age <= 20 && age > 10) { ages[1]++; } else if (age <= 30 && age > 20) { ages[2]++; } else if (age <= 40 && age > 30) { ages[3]++; } else if (age <= 50 && age > 40) { ages[4]++; } else if (age <= 60 && age > 50) { ages[5]++; } else if (age <= 70 && age > 60) { ages[6]++; } else if (age <= 80 && age > 70) { ages[7]++; } else if (age <= 90 && age > 80) { ages[8]++; } else if (age <= 100 && age > 90) { ages[9]++; } } rst = IssueController.getRequesteeInfo(year, month); if (chartType.equals("Pie Chart")) { DefaultPieDataset piedataset = new DefaultPieDataset(); for (int i = 0; i < 10; i++) { piedataset.setValue(i * 10 + "-" + (i * 10 + 10), ages[i]); } JFreeChart chart = ChartFactory.createPieChart3D("Issued Age Groups", piedataset, true, true, true); ChartPanel panel = new ChartPanel(chart); chart.setBackgroundPaint(Color.PINK); chart.getTitle().setPaint(Color.RED); chartArea.add(panel); panel.setSize(chartArea.getSize()); panel.setVisible(true); } else { DefaultCategoryDataset dataset = new DefaultCategoryDataset(); for (int i = 0; i < 10; i++) { dataset.setValue(ages[i], "Issued Values", i * 10 + "-" + (i * 10 + 10)); } if (chartType.equals("Bar Chart")) { JFreeChart chart = ChartFactory.createBarChart3D("Issued Age Groups", "Age Groups", "Issued Values", dataset, PlotOrientation.VERTICAL, false, true, false); chart.setBackgroundPaint(Color.PINK); chart.getTitle().setPaint(Color.RED); CategoryPlot p = chart.getCategoryPlot(); p.setRangeGridlinePaint(Color.BLUE); ChartPanel panel = new ChartPanel(chart); chartArea.add(panel); panel.setSize(chartArea.getSize()); panel.setVisible(true); } else if (chartType.equals("Line Chart")) { JFreeChart chart = ChartFactory.createLineChart3D("Issued Age Groups", "Age Groups", "Issued Values", dataset, PlotOrientation.VERTICAL, false, true, false); chart.setBackgroundPaint(Color.PINK); chart.getTitle().setPaint(Color.RED); CategoryPlot p = chart.getCategoryPlot(); p.setRangeGridlinePaint(Color.BLUE); ChartPanel panel = new ChartPanel(chart); chartArea.add(panel); panel.setSize(chartArea.getSize()); panel.setVisible(true); } } } catch (SQLException ex) { JOptionPane.showMessageDialog(null, "3Data Error!", "Warning!", JOptionPane.OK_OPTION); } catch (ClassNotFoundException ex) { Logger.getLogger(IssueChart.class.getName()).log(Level.SEVERE, null, ex); } } }
From source file:net.sourceforge.atunes.kernel.modules.statistics.StatsDialogController.java
/** * Sets the general chart.//from w w w .ja v a 2 s .co m */ private void setGeneralChart() { DefaultPieDataset dataset = new DefaultPieDataset(); int different = this.statisticsHandler.getDifferentAudioObjectsPlayed(); int total = this.repositoryHandler.getAudioFilesList().size(); dataset.setValue(I18nUtils.getString("SONGS_PLAYED"), different); dataset.setValue(I18nUtils.getString("SONGS_NEVER_PLAYED"), total - different); JFreeChart chart = ChartFactory.createPieChart3D(I18nUtils.getString("SONGS_PLAYED"), dataset, false, false, false); chart.setBackgroundPaint(GuiUtils.getBackgroundColor()); chart.getTitle().setPaint(GuiUtils.getForegroundColor()); chart.setPadding(new RectangleInsets(5, 0, 0, 0)); DefaultDrawingSupplier drawingSupplier = new DefaultDrawingSupplier( new Paint[] { new Color(0, 1, 0, 0.6f), new Color(1, 0, 0, 0.6f) }, new Paint[] { new Color(0, 1, 0, 0.4f), new Color(1, 0, 0, 0.4f) }, DefaultDrawingSupplier.DEFAULT_STROKE_SEQUENCE, DefaultDrawingSupplier.DEFAULT_STROKE_SEQUENCE, DefaultDrawingSupplier.DEFAULT_SHAPE_SEQUENCE); chart.getPlot().setDrawingSupplier(drawingSupplier); ((PiePlot3D) chart.getPlot()).setOutlineVisible(false); ((PiePlot3D) chart.getPlot()).setBackgroundPaint(GuiUtils.getBackgroundColor()); getComponentControlled().getGeneralChart().setIcon(new ImageIcon(chart.createBufferedImage(710, 250))); }
From source file:graficos.Grafico1.java
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed ChartPanel panel;/*from w w w .j av a 2s. c o m*/ JFreeChart chart = null; if (l.isSelected()) { //Grafico de Linea int ban = 1; //para validar que la tabla no esta vacia o que tenga solo caracteres numericos XYSplineRenderer renderer = new XYSplineRenderer();// renderizador XYSeriesCollection dataset = new XYSeriesCollection();// variable para almacenar los datos que le enviamos para hacer el ploteo //Ejes x , y ValueAxis x = new NumberAxis(); ValueAxis y = new NumberAxis(); XYSeries serie = new XYSeries("Datos");//almacena conjunto de datos que vamos a graficar //Le paso por parametro el nombre que recibe la serie XYPlot plot; // Hago el recorrido del JTable datos y lo agrego a la serie try { for (int fila = 0; fila < 5; fila++) { GraficoLinea.removeAll(); serie.add(Float.parseFloat(String.valueOf(datos.getValueAt(fila, 0))), Float.parseFloat(String.valueOf(datos.getValueAt(fila, 1)))); } } catch (Exception e) { ban = 0; JOptionPane.showMessageDialog(this, e.toString()); } if (ban == 1) { // Pasos claves para hacer el grafico de linea // Agrego al dataset la serie de datos. dataset.addSeries(serie); //Nombres de los ejes x.setLabel("Eje X"); y.setLabel("Eje Y"); //Ploteo pasando por parametr , el data set, los ejes y el renderer. plot = new XYPlot(dataset, x, y, renderer); chart = new JFreeChart(plot); chart.setTitle("Grafico de Lineas"); } } else { if (b.isSelected()) { //Grafico de Barra DefaultCategoryDataset data = new DefaultCategoryDataset(); // este esta hecho con datos que yo invente.. String producto1 = "Sopa Quick"; String producto2 = "Yerba Mate"; String dia1 = "Dia 1"; String dia2 = "Dia 2"; String dia3 = "Dia 3"; String dia4 = "Dia 4"; String dia5 = "Dia 5"; data.addValue(14, dia1, producto1); data.addValue(17, dia2, producto1); data.addValue(19, dia3, producto1); data.addValue(27, dia4, producto1); data.addValue(30, dia5, producto1); data.addValue(1, dia1, producto2); data.addValue(4, dia2, producto2); data.addValue(9, dia3, producto2); data.addValue(16, dia4, producto2); data.addValue(33, dia5, producto2); chart = ChartFactory.createBarChart("Grafico de Barra", "Dia", "Cantidad", data, PlotOrientation.VERTICAL, true, true, true); CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setDomainGridlinesVisible(true); } else { //Grafico de Torta DefaultPieDataset data = new DefaultPieDataset(); data.setValue("Categoria1", 20); data.setValue("Categoria2", 400); data.setValue("Categoria3", 60); chart = ChartFactory.createPieChart3D("Grafico de Torta", data, true, true, true); } } panel = new ChartPanel(chart); panel.setBounds(5, 10, 410, 400); if (b.isSelected()) {//Barra GraficoBarra.add(panel); GraficoBarra.repaint(); } else { if (l.isSelected()) {//Linea GraficoLinea.add(panel); GraficoLinea.repaint(); } else { //Torta GraficoTorta.add(panel); GraficoTorta.repaint(); } } }
From source file:UserInterface.WaterSupplyAdmin.UsagePatternJPanel.java
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed int total = 0; for (Organization organization : enterprise.getOrganizationDirectory().getOrganizationList()) { if (organization instanceof CustomerOrganization) { for (Employee employee : organization.getEmployeeDirectory().getEmployeeList()) { Customer customer = (Customer) employee; total += customer.getTotalUsageVolume(); }//www . ja va 2s . c o m } } if (total == 0) { JOptionPane.showMessageDialog(null, "No Customer has used water yet"); return; } DefaultPieDataset dataset = new DefaultPieDataset(); for (Organization organization : enterprise.getOrganizationDirectory().getOrganizationList()) { if (organization instanceof CustomerOrganization) { for (Employee employee : organization.getEmployeeDirectory().getEmployeeList()) { Customer customer = (Customer) employee; dataset.setValue(customer.getName(), customer.getTotalUsageVolume()); } } } JFreeChart chart = ChartFactory.createPieChart3D("Customer Water Usage", dataset, true, true, true); ChartFrame frame = new ChartFrame("Pie Chart demonstrating customer water usage ", chart); PiePlot3D plot = (PiePlot3D) chart.getPlot(); plot.setStartAngle(200); plot.setForegroundAlpha(0.50f); RefineryUtilities.centerFrameOnScreen(frame); frame.setVisible(true); frame.setSize(650, 550); }
From source file:org.adempiere.apps.graph.ChartBuilder.java
private JFreeChart create3DPieChart() { final JFreeChart chart = ChartFactory.createPieChart3D(chartModel.get_Translation(MChart.COLUMNNAME_Name), getPieDataset(), false, true, true); return chart; }
From source file:ventanas.Reportes.java
public static void crearPieChart(DefaultPieDataset pData, JPanel jgra, String titulo) { JFreeChart grafica;//from w w w.j a va2s . co m grafica = ChartFactory.createPieChart3D(titulo, pData, true, true, true); ChartPanel panel = new ChartPanel(grafica); jgra.removeAll(); jgra.add(panel, BorderLayout.CENTER); jgra.repaint(); }
From source file:lu.uni.lassy.excalibur.examples.icrash.dev.web.java.views.AdminAuthView.java
private void drawGraph(String name, Integer[] responses) { DefaultPieDataset dataset = new DefaultPieDataset(); dataset.setValue("Answer 1", responses[0].doubleValue()); dataset.setValue("Answer 2", responses[1].doubleValue()); dataset.setValue("Answer 3", responses[2].doubleValue()); JFreeChart chart = ChartFactory.createPieChart3D(name, dataset, true, true, false); PiePlot3D plot = (PiePlot3D) chart.getPlot(); plot.setForegroundAlpha(0.5f);/*from w w w . ja va 2s .co m*/ plot.setCircular(true); final JFreeChartWrapper chartP = new JFreeChartWrapper(chart); GridLayout diagramLayout = new GridLayout(2, 2); diagramLayout.setSpacing(true); diagramLayout.setMargin(true); diagramLayout.setSizeFull(); diagramLayout.addComponent(chartP); diagramPanel.setContent(diagramLayout); }
From source file:co.edu.eam.ingesoft.desarrollo.vista.gui.ReportesEstadisticas.java
private void jCBProgramaItemStateChanged(java.awt.event.ItemEvent evt) {// GEN-FIRST:event_jCBProgramaItemStateChanged try {/*from w w w.j a v a 2 s . com*/ ChartPanel panel; Programa programa = (Programa) jCBPrograma.getSelectedItem(); List<InformacionLaboral> listaInfoLab = controlador.listaEgresadosPorOcupacion(programa); jPanelEgresadosPorOcup.removeAll(); double empleado = 0; double desempleado = 0; double independiente = 0; double empresario = 0; int contadorEmpleado = 0; int contadordDesempleado = 0; int contadorIndependiente = 0; int contadorEmpresario = 0; for (int i = 0; i < listaInfoLab.size(); i++) { if (listaInfoLab.get(i).getSituacionActual().equals("Empleado")) { contadorEmpleado++; } else if (listaInfoLab.get(i).getSituacionActual().equals("Desempleado")) { contadordDesempleado++; } else if (listaInfoLab.get(i).getSituacionActual().equals("Independiente")) { contadorIndependiente++; } else if (listaInfoLab.get(i).getSituacionActual().equals("Empresario")) { contadorEmpresario++; } else { JOptionPane.showMessageDialog(null, "No hay empleados registrados"); } empleado = (contadorEmpleado * 100) / listaInfoLab.size(); desempleado = (contadordDesempleado * 100) / listaInfoLab.size(); independiente = (contadorIndependiente * 100) / listaInfoLab.size(); empresario = (contadorEmpresario * 100) / listaInfoLab.size(); } DefaultPieDataset ds = new DefaultPieDataset(); ds.setValue("Empleado: " + empleado + "%", empleado); ds.setValue("Desempleado: " + desempleado + "%", desempleado); ds.setValue("Independiente: " + independiente + "%", independiente); ds.setValue("Empresario: " + empresario + "%", empresario); JFreeChart jf = ChartFactory.createPieChart3D("Reporte de egresados por tipo de ocupacin", ds, true, true, true); panel = new ChartPanel(jf); panel.setBounds(20, 50, 720, 350); jPanelEgresadosPorOcup.add(panel); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } }