List of usage examples for org.jfree.chart JFreeChart getCategoryPlot
public CategoryPlot getCategoryPlot()
From source file:result.analysis.Chart.java
void avgMarks(String batch, String sem, String[] colleges) { DefaultCategoryDataset dataset = new DefaultCategoryDataset(); for (String college : colleges) { db = mongoClient.getDB(college); analyz = new Analyze(db); String collection_name = "cs_" + batch + "_" + sem + "_sem"; DBCollection collection = db.getCollection(collection_name); String[] codes = analyz.GetSubCodes(collection); for (String code : codes) { double avg = analyz.GetAverageSubject(collection, code); dataset.setValue(avg, college, code); }// w ww. j a v a 2s .c o m } JFreeChart barChart = ChartFactory.createBarChart("Average in each subject", "SUBJECT", "AVERAGE MARKS", dataset, PlotOrientation.VERTICAL, true, true, false); CategoryPlot plot = barChart.getCategoryPlot(); BarRenderer renderer = (BarRenderer) plot.getRenderer(); // set the color (r,g,b) or (r,g,b,a) Color color = new Color(79, 129, 189); renderer.setSeriesPaint(0, color); ChartFrame frame = new ChartFrame( "Subject-wise average marks of 20" + batch + " batch " + sem + "th semester", barChart); frame.setVisible(true); frame.setSize(Toolkit.getDefaultToolkit().getScreenSize().width, Toolkit.getDefaultToolkit().getScreenSize().height); save_jpeg(barChart); }
From source file:UserInterface.AdminWorkArea.InventoryUsageJPanel.java
private void usageJButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_usageJButtonActionPerformed DefaultTableModel dtm = (DefaultTableModel) deviceUsageJTable.getModel(); int rows = dtm.getRowCount(); DefaultCategoryDataset dataSet = new DefaultCategoryDataset(); for (int i = 0; i < rows; i++) { int num = (int) deviceUsageJTable.getValueAt(i, 1); dataSet.setValue(num, "Number Of Reservations", String.valueOf(deviceUsageJTable.getValueAt(i, 0))); }//from w w w. j ava 2s . c o m JFreeChart chart = ChartFactory.createBarChart("Device Usage Chart", "Device Name", "Number of Reservations", dataSet, PlotOrientation.VERTICAL, false, true, false); CategoryPlot plot = chart.getCategoryPlot(); plot.setRangeGridlinePaint(Color.BLACK); ChartFrame frame = new ChartFrame("Sales Overview", chart); frame.setVisible(true); frame.setSize(600, 600); }
From source file:my.estadistico.Grafica.java
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed try {/*from w w w.j a v a 2s .c o m*/ this.datos();//Obtiene los datos JFreeChart chart = ChartFactory.createBarChart("", "", "", dataset, PlotOrientation.HORIZONTAL, false, false, false); CategoryPlot catPlot = chart.getCategoryPlot(); catPlot.setRangeGridlinePaint(Color.BLACK); this.mostrar(chart); } catch (Exception e) { JOptionPane.showMessageDialog(rootPane, "FAVOR DE INGRESAR DATOS"); } // TODO add your handling code here: }
From source file:presentation.webgui.vitroappservlet.StyleCreator.java
private void previewStyleLegend(HttpServletResponse response) throws IOException { // png creation using jfreechart. /*response.setContentType("text/html"); PrintWriter outPrintWriter = response.getWriter(); outPrintWriter.print("<b>Error</b>: no valid mode was specified! ("+this.mode+")"); outPrintWriter.flush();/*from w w w .j a v a 2 s .c o m*/ outPrintWriter.close(); */ Model3dStylesList myStylesIndex = Model3dStylesList.getModel3dStylesList(); // fill in the SpecialCases vector with valid Model3dStyleSpecialCase objects Vector<Model3dStyleSpecialCase> givSpecialCasesVec = retrieveSpecialCasesVector(); // fill in the SpecialCases vector with valid Model3dStyleSpecialCase objects Vector<Model3dStyleNumericCase> givNumericCasesVec = retrieveNumericCasesVector(); Model3dStylesEntry tmpDummyEntry = new Model3dStylesEntry(null, this.givenGenCapability, this.givenDefaultColor, this.givenDefaultIconfile, this.givenDefaultPrefabfile, givSpecialCasesVec, givNumericCasesVec); response.setContentType("image/png"); OutputStream out = response.getOutputStream(); try { JFreeChart chart = createDatasetAndChart(tmpDummyEntry); int chartHeight = 40; if (chart.getCategoryPlot().getDataset().getColumnKeys().size() > 1) { chartHeight = chart.getCategoryPlot().getDataset().getColumnKeys().size() * 22; } ChartUtilities.writeChartAsPNG(out, chart, 300, chartHeight); } catch (Exception e) { System.err.println(e.toString()); response.setContentType("text/html"); PrintWriter outPrintWriter = response.getWriter(); outPrintWriter.print("<b>Error</b>:" + e.toString()); outPrintWriter.flush(); outPrintWriter.close(); } finally { out.close(); } return; }
From source file:tusys.view.jPanelStatistik.java
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed jenis_kegiatan = jComboBox1.getSelectedItem().toString(); System.out.println(jenis_kegiatan); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); try {/* w w w.j a v a 2 s . co m*/ tanggal_mulai = new java.sql.Date(sdf.parse(jTextFieldTanggalMulai.getText()).getTime()); tanggal_selesai = new java.sql.Date(sdf.parse(jTextFieldTanggalSelesai.getText()).getTime()); if (tanggal_mulai.after(tanggal_selesai)) { JOptionPane.showMessageDialog(null, "tanggal mulai harus sebelum tanggal selesai"); return; } } catch (ParseException ex) { JOptionPane.showMessageDialog(null, "Format tanggal masukan salah"); return; //Logger.getLogger(jPanelStatistik.class.getName()).log(Level.SEVERE, null, ex); } if (jenis_kegiatan.equals("Semua")) { try { stat = mainMenu.getDbc().getAllStatistic(tanggal_mulai, tanggal_selesai); } catch (SQLException ex) { Logger.getLogger(jPanelStatistik.class.getName()).log(Level.SEVERE, null, ex); } } else { try { stat = mainMenu.getDbc().getStatistic(jenis_kegiatan, (tanggal_mulai), (tanggal_selesai)); } catch (SQLException ex) { Logger.getLogger(jPanelStatistik.class.getName()).log(Level.SEVERE, null, ex); } } DefaultCategoryDataset dataset = new DefaultCategoryDataset(); for (int i = 0; i < stat.getRuangan().size(); i++) { dataset.setValue(stat.getFrekuensi().get(i), "Frekuensi", stat.getRuangan().get(i)); } JFreeChart chart = ChartFactory.createBarChart("Statistik Penggunaan Ruangan", "Ruangan", "Frekuensi", dataset, PlotOrientation.VERTICAL, false, true, false); CategoryPlot p = chart.getCategoryPlot(); p.setRangeGridlinePaint(Color.BLACK); ValueAxis yAxis = chart.getCategoryPlot().getRangeAxis(); yAxis.setRange(0.0, 100.0); p.setRangeAxis(yAxis); ChartFrame frame = new ChartFrame("Statistik", chart); frame.setVisible(true); frame.setLocation(500, 200); frame.setSize(565, 410); /* //masih ga keluar gambarnya ChartPanel cp = new ChartPanel(chart); jPanel1.removeAll(); jPanel1.add(cp,BorderLayout.CENTER); jPanel1.revalidate(); mainMenu.getjPanelData1().add(jPanel1); */ }
From source file:my.estadistico.Grafica.java
private void jButton8ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton8ActionPerformed try {/*from w w w. j a v a 2s . c om*/ this.datos();//Obtiene los datos JFreeChart chart = ChartFactory.createBarChart3D("", "", "", dataset, PlotOrientation.HORIZONTAL, false, false, false); CategoryPlot catPlot = chart.getCategoryPlot(); catPlot.setRangeGridlinePaint(Color.BLACK); this.mostrar(chart); } catch (Exception e) { JOptionPane.showMessageDialog(rootPane, "FAVOR DE INGRESAR DATOS"); } // TODO add your handling code here: }
From source file:Gui.admin.GererlesSratistique.java
private void StatistiquesBouttonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_StatistiquesBouttonActionPerformed int size = evaluationTable.getRowCount(); System.out.println(size);/*www. ja v a2s.c o m*/ List<Double> notes = new ArrayList<Double>(); List<Integer> ids = new ArrayList<Integer>(); for (int i = 0; i < size; i++) { notes.add((new Double(evaluationTable.getValueAt(i, 3).toString()))); ids.add((int) evaluationTable.getValueAt(i, 1)); } DefaultCategoryDataset dataset = new DefaultCategoryDataset(); for (int i = 0; i < size; i++) { dataset.setValue(new Double(notes.get(i)), "notes", new Double(ids.get(i))); } //dataset.setValue(evaluationTable); JFreeChart chart = ChartFactory.createBarChart3D("Notes Adhrents", "Id Adhrents", "Notes", dataset, PlotOrientation.VERTICAL, true, true, false); CategoryPlot p = chart.getCategoryPlot(); p.setRangeGridlinePaint(Color.black); ChartFrame frame = new ChartFrame(" les notes des adhrents", chart); frame.setVisible(true); frame.setSize(450, 350); try { } catch (Exception e) { } /* String note =noteTxt.getText(); String idAdherent=idAdherentEvaluText.getText(); DefaultCategoryDataset dataset = new DefaultCategoryDataset(); dataset.setValue(new Double(note), "notes", new Double(idAdherent)); //dataset.setValue(evaluationTable); JFreeChart chart = ChartFactory.createBarChart3D("Notes Adhrents", "Id Adhrents", "Notes", dataset, PlotOrientation.VERTICAL, false, true, false); CategoryPlot p= chart.getCategoryPlot(); p.setRangeGridlinePaint(Color.black); ChartFrame frame = new ChartFrame(" les notes des adhrents", chart); frame.setVisible(true); frame.setSize(450,350); */ try { final ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection()); final File file1 = new File("statistiques.png"); ChartUtilities.saveChartAsPNG(file1, chart, 600, 400, info); } catch (Exception e) { } }
From source file:UserInterface.PDCPrimaryDoctorRole.PDCPrimaryDoctorReportsJPanel.java
private void populateGraphs(Patient patient, String attribute) { int lowerNormal = 0; int higherNormal = 0; int yAxis = 0; DefaultCategoryDataset line_chart_dataset = new DefaultCategoryDataset(); for (VitalSigns vitalSigns : patient.getVitalSignsHistory().getVitalSignsHistory()) { if (attribute.equalsIgnoreCase("ECG")) { yAxis = vitalSigns.getEcg(); lowerNormal = 46;// ww w . ja va2 s . c o m higherNormal = 50; } else if (attribute.equalsIgnoreCase("HEART RATE")) { yAxis = vitalSigns.getHeartRate(); lowerNormal = 60; higherNormal = 90; } else if (attribute.equalsIgnoreCase("RESPIRATORY RATE")) { yAxis = vitalSigns.getHeartRate(); lowerNormal = 12; higherNormal = 25; } else if (attribute.equalsIgnoreCase("WEIGHT IN KG")) { yAxis = vitalSigns.getHeartRate(); lowerNormal = 80; higherNormal = 85; } else if (attribute.equalsIgnoreCase("SYSTOLIC BLOOD PRESSURE")) { yAxis = vitalSigns.getHeartRate(); lowerNormal = 90; higherNormal = 120; } Date currentTimeStamp = new Date(); int currentTime = (int) (currentTimeStamp.getTime()) / (1000 * 60); int vitalSignsTime = (int) vitalSigns.getTimeStamp().getTime() / (1000 * 60); if (currentTime - vitalSignsTime <= 1) { line_chart_dataset.addValue(yAxis, attribute, vitalSigns.getTimeStamp()); } } JFreeChart lineChart = ChartFactory.createLineChart(attribute + " Over Time", "Time", attribute, line_chart_dataset, PlotOrientation.VERTICAL, true, true, false); CategoryPlot pi = lineChart.getCategoryPlot(); pi.setRangeGridlinePaint(Color.WHITE); pi.getRenderer().setSeriesPaint(0, Color.GREEN); pi.setBackgroundPaint(Color.BLACK); ValueMarker marker = new ValueMarker(lowerNormal); marker.setLabel("Normal Range"); marker.setLabelAnchor(RectangleAnchor.TOP_RIGHT); marker.setLabelPaint(Color.WHITE); marker.setLabelTextAnchor(TextAnchor.TOP_RIGHT); marker.setPaint(Color.CYAN); pi.addRangeMarker(marker); ValueMarker marker2 = new ValueMarker(higherNormal); marker2.setLabel("Normal Range"); marker2.setLabelPaint(Color.WHITE); marker2.setLabelAnchor(RectangleAnchor.TOP_RIGHT); marker2.setLabelTextAnchor(TextAnchor.TOP_RIGHT); marker2.setPaint(Color.CYAN); pi.addRangeMarker(marker2); reportJPanel.setLayout(new java.awt.BorderLayout()); ChartPanel panel = new ChartPanel(lineChart); reportJPanel.add(panel, BorderLayout.CENTER); reportJPanel.validate(); }
From source file:Interface.CommunityAdminWorkArea.BestRestaurant.java
private void btnCalculateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCalculateActionPerformed // TODO add your handling code here: Date toDate1 = jDateChooser1.getDate(); Date toDate2 = jDateChooser2.getDate(); if ((toDate1 == null) || (toDate2 == null)) { JOptionPane.showMessageDialog(null, "Invalid date..Kindly enter valid date."); return;/*from w ww. j a v a 2 s . com*/ } long fromDate = (jDateChooser1.getDate().getTime()) / (1000 * 60 * 60 * 24); long toDate = (jDateChooser2.getDate().getTime()) / (1000 * 60 * 60 * 24); //String citizenRewards = null; ArrayList<RestaurantEmployee> restaurantEmployeeList = new ArrayList<>(); for (WorkRequest request : organization.getWorkQueue().getWorkRequestList()) { long requestDate = (request.getRequestDate().getTime()) / (1000 * 60 * 60 * 24); if ((requestDate >= fromDate) && (requestDate <= toDate)) { Employee ee = request.getSender().getEmployee(); if (ee instanceof RestaurantEmployee) { RestaurantEmployee c = (RestaurantEmployee) ee; if (!restaurantEmployeeList.contains(c)) { c.calculateTotalRewardPointsForCitizen(); restaurantEmployeeList.add(c); } } } // else{ // // JOptionPane.showMessageDialog(null, "There are no records for this search criteria."); // } } if (restaurantEmployeeList.isEmpty()) { JOptionPane.showMessageDialog(null, "There are no records for this search criteria."); } ArrayList<RestaurantEmployee> restaurantEmployee = calculateTopThreeRestaurantByRewardPoints( restaurantEmployeeList); DefaultCategoryDataset dataset = new DefaultCategoryDataset(); dataset.setValue(restaurantEmployee.get(0).getCurrentRewardPoints(), "Commercial body", restaurantEmployee.get(0).getName()); dataset.setValue(restaurantEmployee.get(1).getCurrentRewardPoints(), "Commercial body", restaurantEmployee.get(1).getName()); dataset.setValue(restaurantEmployee.get(2).getCurrentRewardPoints(), "Commercial body", restaurantEmployee.get(2).getName()); JFreeChart chart = ChartFactory.createBarChart3D("Types of food collected", "Top 3 Restaurant", "Number of reward points", dataset, PlotOrientation.VERTICAL, false, true, false); CategoryPlot plot = chart.getCategoryPlot(); plot.setRangeGridlinePaint(Color.BLUE); ChartFrame frame = new ChartFrame("Bar Chart for best Restaurant", chart); frame.setVisible(true); frame.setSize(450, 350); }
From source file:Interface.CommunityAdminWorkArea.BestCitizen.java
private void btnCalculateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCalculateActionPerformed // TODO add your handling code here: Date toDate1 = jDateChooser1.getDate(); Date toDate2 = jDateChooser2.getDate(); if ((toDate1 == null) || (toDate2 == null)) { JOptionPane.showMessageDialog(null, "Invalid date..Kindly enter valid date."); return;//w w w.ja va2 s . c om } long fromDate = (jDateChooser1.getDate().getTime()) / (1000 * 60 * 60 * 24); long toDate = (jDateChooser2.getDate().getTime()) / (1000 * 60 * 60 * 24); //String citizenRewards = null; ArrayList<CitizenEmployee> citizenEmployeeList = new ArrayList<>(); for (WorkRequest request : organization.getWorkQueue().getWorkRequestList()) { long requestDate = (request.getRequestDate().getTime()) / (1000 * 60 * 60 * 24); if ((requestDate >= fromDate) && (requestDate <= toDate)) { Employee ee = request.getSender().getEmployee(); if (ee instanceof CitizenEmployee) { CitizenEmployee c = (CitizenEmployee) ee; if (!citizenEmployeeList.contains(c)) { c.calculateTotalRewardPointsForCitizen(); citizenEmployeeList.add(c); } } } // else{ // // JOptionPane.showMessageDialog(null, "There are no records for this search criteria."); // } } if (citizenEmployeeList.isEmpty()) { JOptionPane.showMessageDialog(null, "There are no records for this search criteria."); } ArrayList<CitizenEmployee> citizenEmployee = calculateTopThreeCitizenByRewardPoints(citizenEmployeeList); DefaultCategoryDataset dataset = new DefaultCategoryDataset(); dataset.setValue(citizenEmployee.get(0).getCurrentRewardPoints(), "Citizens", citizenEmployee.get(0).getName()); dataset.setValue(citizenEmployee.get(1).getCurrentRewardPoints(), "Citizens", citizenEmployee.get(1).getName()); dataset.setValue(citizenEmployee.get(2).getCurrentRewardPoints(), "Citizens", citizenEmployee.get(2).getName()); JFreeChart chart = ChartFactory.createBarChart3D("Types of food collected", "Top 3 citizen", "Number of reward points", dataset, PlotOrientation.VERTICAL, false, true, false); CategoryPlot plot = chart.getCategoryPlot(); plot.setRangeGridlinePaint(Color.BLUE); ChartFrame frame = new ChartFrame("Bar Chart for Types of food collected", chart); frame.setVisible(true); frame.setSize(450, 350); }