List of usage examples for org.jfree.chart ChartFactory createPieChart
public static JFreeChart createPieChart(String title, PieDataset dataset, boolean legend, boolean tooltips, boolean urls)
From source file:UserInterface.CDC.VaccineStateDistributionJPanel.java
private void viewChartjButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_viewChartjButtonActionPerformed // TODO add your handling code here: DefaultPieDataset pieDataset = new DefaultPieDataset(); for (StateNetwork state : business.getStateList()) { pieDataset.setValue(state.getStateName(), state.getTotalVaccinesDistributedInState()); }//from ww w .j a v a2 s.co m JFreeChart chart = ChartFactory.createPieChart("Total Vaccines Distributed", pieDataset, true, true, true); PiePlot p = (PiePlot) chart.getPlot(); ChartFrame frame = new ChartFrame("Total Vaccines Distributed", chart); frame.setVisible(true); frame.setSize(450, 500); }
From source file:UserInterface.EmployeeViewArea.ViewIssuesStatisticsJPanel.java
private static JFreeChart createPieChart(PieDataset dataset) { // chart title // data // include legend JFreeChart chart = ChartFactory.createPieChart("Reported Child Issues", dataset, true, true, false); PiePlot plot = (PiePlot) chart.getPlot(); plot.setSectionOutlinesVisible(false); plot.setNoDataMessage("No data available"); return chart; }
From source file:UserInterface.DoctorRole.DoctorReportChartJPanel.java
private void feedjButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_feedjButton2ActionPerformed // TODO add your handling code here: ReportToReporter report = enterprise.getReport(); if (report.getStatus() != null) { DefaultPieDataset pieDataset = new DefaultPieDataset(); pieDataset.setValue("satisfy", report.getYes()); pieDataset.setValue("not satisfy", report.getNo()); JFreeChart chart = ChartFactory.createPieChart("Satifaction", pieDataset, true, true, true); PiePlot p = (PiePlot) chart.getPlot(); // p.setForegroundAlpha(TOP_ALIGNMENT); ChartFrame frame = new ChartFrame("Chart for Satifaction", chart); frame.setVisible(true);//w w w . j ava2 s. c om frame.setSize(350, 450); } else { JOptionPane.showMessageDialog(null, "Sorry, the final report has not been generated"); } }
From source file:UserInterface.CDC.VARESReportingJPanel.java
private void viewChartjButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_viewChartjButtonActionPerformed // TODO add your handling code here: DefaultPieDataset pieDataset = new DefaultPieDataset(); for (StateNetwork state : business.getStateList()) { pieDataset.setValue(state.getStateName(), state.getTotalFailedVaccinesInState()); }//from w w w.jav a 2 s . c o m JFreeChart chart = ChartFactory.createPieChart("Total Vaccines Failed", pieDataset, true, true, true); PiePlot p = (PiePlot) chart.getPlot(); ChartFrame frame = new ChartFrame("Total Vaccines Failed", chart); frame.setVisible(true); frame.setSize(450, 500); }
From source file:simulation.AureoZauleckAnsLab2.java
/** * *///from w w w . ja v a 2 s .co m public AureoZauleckAnsLab2() { // TODO code application logic here Scanner sc = new Scanner(System.in); String choice_s = ""; int choice = 0; do { DisplayMenu(); choice_s = sc.next(); String title = ""; Scanner s = new Scanner(System.in); //test input if (IsNumber(choice_s)) { choice = Convert(choice_s); } else { do { System.out.println("Please enter a number only."); choice_s = sc.next(); } while (!IsNumber(choice_s)); choice = Convert(choice_s); } if (choice == 1) { System.out.println("*** CATEGORICAL ***"); System.out.println(); System.out.println("TITLE(title of data set)"); //sc = new Scanner(System.in); title = s.nextLine(); System.out.println("this is the title: " + title); ArrayList a = new ArrayList<>(); ArrayList<Double> percentages = new ArrayList<>(); ArrayList<ArrayList> all; a = GetData(); Collections.sort(a); all = Stratified(a); System.out.println("GROUPED DATA: " + all); System.out.println("size " + all.size()); double percent = 0.0, sum = 0.0; for (int i = 0; i < all.size(); i++) { ArrayList inner = new ArrayList<>(); inner = all.get(i); //System.out.println(inner); int inner_n = inner.size(); percent = GetPercentage(N, inner_n); percentages.add(percent); sum += percent; System.out.println("" + inner.get(0) + "\t" + " " + percent); } System.out.println("\t" + "total " + Math.ceil(sum)); System.out.println("all = " + all); JFrame frame = new JFrame(); //frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JTable table = new JTable(); table.setModel(new DefaultTableModel((int) (all.size() + 2), 2)); table.setValueAt("VALUE LABELS", 0, 0); table.setValueAt("PERCENTAGE", 0, 1); table.setValueAt("TOTAL = 100%", (int) (all.size() + 1), 1); for (int i = 0; i < all.size(); i++) { table.setValueAt(all.get(i).get(0), i + 1, 0); table.setValueAt(new DecimalFormat("#.##").format(percentages.get(i)), i + 1, 1); } JScrollPane scrollPane = new JScrollPane(table); scrollPane.setBorder(BorderFactory.createTitledBorder(title)); frame.add(scrollPane, BorderLayout.CENTER); frame.setSize(300, 150); frame.setVisible(true); int type = 0, testT = 0; String typeTest = ""; do { System.out.println("GENERATE GRAPH?"); System.out.println("[1] YES"); System.out.println("[2] NO"); System.out.println(); System.out.println("Please pick a number from the choices above."); typeTest = sc.next(); if (IsNumber(typeTest)) { testT = Convert(typeTest); } else { do { System.out.println("Please enter a number only."); typeTest = sc.next(); } while (!IsNumber(typeTest)); testT = Convert(typeTest); } type = testT; } while (type < 1 || type > 2); if (type == 1) { DefaultPieDataset dataset = new DefaultPieDataset(); for (int i = 0; i < all.size(); i++) { dataset.setValue( all.get(i).get(0).toString() + " = " + new DecimalFormat("#.##").format(percentages.get(i)) + "%", percentages.get(i)); } JFreeChart chart = ChartFactory.createPieChart(title, // chart title dataset, // data true, // include legend true, false); ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new java.awt.Dimension(560, 367)); JFrame l = new JFrame(); l.setContentPane(chartPanel); l.setSize(400, 400); l.setVisible(true); } else { //do nothing? } int type2 = 0, testT2 = 0; String typeTest2 = ""; do { System.out.println("REDISPLAY TABLE?"); System.out.println("[1] YES"); System.out.println("[2] NO"); System.out.println(); System.out.println("Please pick a number from the choices above."); typeTest2 = sc.next(); if (IsNumber(typeTest2)) { testT2 = Convert(typeTest2); } else { do { System.out.println("Please enter a number only."); typeTest2 = sc.next(); } while (!IsNumber(typeTest2)); testT2 = Convert(typeTest2); } type2 = testT2; } while (type2 < 1 || type2 > 2); if (type2 == 1) { DisplayTable(all, percentages, title); } else { //do nothing? } } else if (choice == 2) { System.out.println("*** NUMERICAL ***"); System.out.println(); System.out.println("TITLE(title of data set)"); title = s.nextLine(); System.out.println("this is the title " + title); ArrayList<Double> a = new ArrayList<>(); //ArrayList<ArrayList> all; //a = GetData2(); double[] arr = { 70, 36, 43, 69, 82, 48, 34, 62, 35, 15, 59, 139, 46, 37, 42, 30, 55, 56, 36, 82, 38, 89, 54, 25, 35, 24, 22, 9, 55, 19 }; /* double[] arr = {112, 100, 127,120,134,118,105,110,109,112, 110, 118, 117, 116, 118, 122, 114, 114, 105, 109, 107, 112, 114, 115, 118, 117, 118, 122, 106, 110, 116, 108, 110, 121, 113, 120, 119, 111, 104, 111, 120, 113, 120, 117, 105, 110, 118, 112, 114, 114}; */ N = arr.length; double t = 0.0; for (int i = 0; i < N; i++) { a.add(arr[i]); } Collections.sort(a); System.out.println("sorted a " + a); double min = (double) a.get(0); double max = (double) a.get(N - 1); System.out.println("Min" + min); System.out.println("Max" + max); double k = Math.ceil(1 + 3.322 * Math.log10(N)); System.out.println("K " + k); double range = GetRange(min, max); System.out.println("Range " + range); double width = Math.ceil(range / k); //todo, i ceiling sa 1st decimal point System.out.println("Width " + width); ArrayList<Double> cl = new ArrayList<>(); cl.add(min); double rest; for (int i = 1; i < k; i++) { cl.add(min += width); } ArrayList<Double> cl2 = new ArrayList<>(); double cl2min = cl.get(1) - 1; cl2.add(cl2min); for (int i = 1; i < k; i++) { cl2.add(cl2min += width); } System.out.println("cl 1 " + cl); System.out.println("cl 2 " + cl2); ArrayList<Double> tlcl = new ArrayList<>(); double tlclmin = cl.get(0) - Multiplier(cl.get(0)); tlcl.add(tlclmin); for (int i = 1; i < k; i++) { tlcl.add(tlclmin += width); } ArrayList<Double> tucl = new ArrayList<>(); double tuclmin = cl2.get(0) + Multiplier(cl2.get(0)); tucl.add(tuclmin); for (int i = 1; i < k; i++) { tucl.add(tuclmin += width); } System.out.println("tlcl 1 " + tlcl); System.out.println("tucl 2 " + tucl); System.out.println("N " + N); ArrayList<Double> midList = new ArrayList<>(); double mid = (cl.get(0) + cl2.get(0)) / 2; midList.add(mid); for (int i = 1; i < k; i++) { midList.add((tlcl.get(i) + tucl.get(i)) / 2); } for (int i = 0; i < k; i++) { System.out.println((tlcl.get(i) + tucl.get(i)) / 2); } System.out.println("mid" + midList); ArrayList<ArrayList<Double>> freq = new ArrayList<>(); double ctr = 0.0; for (int j = 0; j < k; j++) { for (int i = 0; i < N; i++) { if ((a.get(i) >= tlcl.get(j)) && (a.get(i) <= tucl.get(j))) { freq.add(new ArrayList<Double>()); freq.get(j).add(a.get(i)); } } } ArrayList<Double> freqSize = new ArrayList<>(); double size = 0.0; for (int i = 0; i < k; i++) { size = (double) freq.get(i).size(); freqSize.add(size); } ArrayList<Double> freqPercent = new ArrayList<>(); for (int i = 0; i < k; i++) { freqPercent.add(freqSize.get(i) / N * 100); } ArrayList<Double> cfs = new ArrayList<>(); double cf = freqSize.get(0); cfs.add(cf); for (int i = 1; i < k; i++) { cf = freqSize.get(i) + cfs.get(i - 1); cfs.add(cf); } double sum = 0.0; for (int i = 1; i < cfs.size(); i++) { sum += cfs.get(i); } ArrayList<Double> cps = new ArrayList<>(); double cp = 0.0; for (int i = 0; i < k; i++) { cp = (cfs.get(i) / N) * 100; cps.add(cp); } System.out.println("T o t a l: " + sum); System.out.println(cfs); System.out.println(cps); System.out.println("frequency list " + freq); System.out.println("frequency sizes " + freqSize); System.out.println("frequency percentages " + freqPercent); System.out.println(); System.out.println(title); System.out.println("CLASS LIMITS" + "\t" + "T CLASS LIMITS" + "\t" + "MID" + "\t" + "FREQ" + "\t" + "PERCENT" + "\t" + "CF" + "\t" + "CP"); for (int i = 0; i < k; i++) { System.out.println(cl.get(i) + " - " + cl2.get(i) + "\t" + tlcl.get(i) + " - " + tucl.get(i) + "\t" + midList.get(i) + "\t" + freq.get(i).size() + "\t" + new DecimalFormat("#.##").format(freqPercent.get(i)) + "\t" + cfs.get(i) + "\t" + new DecimalFormat("#.##").format(cps.get(i))); } //2 System.out.println("CLASS LIMITS" + "\t" + "T C L" + "\t" + "MID" + "\t" + "FREQ" + "\t" + "PERCENT" + "\t" + "CF" + "\t" + "CP"); for (int i = 0; i < k; i++) { System.out.println(">=" + cl.get(i) + "\t\t" + " - " + "\t" + " - " + "\t" + freq.get(i).size() + "\t" + new DecimalFormat("#.##").format(freqPercent.get(i)) + "\t" + cfs.get(i) + "\t" + new DecimalFormat("#.##").format(cps.get(i))); } //3 System.out.println("CLASS LIMITS" + "\t" + "T C L" + "\t" + "MID" + "\t" + "FREQ" + "\t" + "PERCENT" + "\t" + "CF" + "\t" + "CP"); for (int i = 0; i < k; i++) { System.out.println("<=" + cl2.get(i) + "\t\t" + " - " + "\t" + " - " + "\t" + freq.get(i).size() + "\t" + new DecimalFormat("#.##").format(freqPercent.get(i)) + "\t" + cfs.get(i) + "\t" + new DecimalFormat("#.##").format(cps.get(i))); } System.out.println("CLASS LIMITS" + "\t" + "T CLASS LIMITS" + "\t" + "MID" + "\t" + "FREQ" + "\t" + "PERCENT" + "\t" + "CF" + "\t" + "CP"); for (int i = 0; i < k; i++) { System.out.println(">=" + cl.get(i) + " and <=" + cl2.get(i) + "\t" + " - " + "\t" + " - " + "\t" + freq.get(i).size() + "\t" + new DecimalFormat("#.##").format(freqPercent.get(i)) + "\t" + cfs.get(i) + "\t" + new DecimalFormat("#.##").format(cps.get(i))); } DisplayTables(k, cl, cl2, tlcl, tucl, midList, freq, freqPercent, cfs, cps, title); int type = 0, testT = 0; String typeTest = ""; do { do { System.out.println(); System.out.println("GENERATE GRAPH?"); System.out.println("[1] YES"); System.out.println("[2] NO"); System.out.println(); System.out.println("Please pick a number from the choices above."); typeTest = sc.next(); if (IsNumber(typeTest)) { testT = Convert(typeTest); } else { do { System.out.println("Please enter a number only."); typeTest = sc.next(); } while (!IsNumber(typeTest)); testT = Convert(typeTest); } type = testT; } while (type < 1 || type > 2); if (type == 1) { int bins = (int) k; System.out.println(); System.out.println("You may input a label for your X axis:"); String x = ""; x = s.nextLine(); createHistogram(a, bins, title, x); int type2 = 0, testT2 = 0; String typeTest2 = ""; do { System.out.println(); System.out.println("REDISPLAY TABLE?"); System.out.println("[1] YES"); System.out.println("[2] NO"); System.out.println(); System.out.println("Please pick a number from the choices above."); typeTest2 = sc.next(); if (IsNumber(typeTest2)) { testT2 = Convert(typeTest2); } else { do { System.out.println("Please enter a number only."); typeTest2 = sc.next(); } while (!IsNumber(typeTest2)); testT2 = Convert(typeTest2); } type2 = testT2; } while ((type2 < 1 || type2 > 2) && type != 2); if (type2 == 1) { DisplayTables(k, cl, cl2, tlcl, tucl, midList, freq, freqPercent, cfs, cps, title); } else { //do nothing? } } } while (type != 2); } else if (choice == 3) { System.out.println("*** QUIT ***"); } } while (choice != 3); System.out.println("Thank you for your time."); s = new Simulation(); }
From source file:UserInterface.PatientRole.PatientReportChartJPanel.java
private void sourcejButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_sourcejButton1ActionPerformed // TODO add your handling code here: ReportToReporter report = enterprise.getReport(); if (report.getStatus() != null) { DefaultPieDataset dataset = new DefaultPieDataset(); dataset.setValue("First hand", report.getFirsthandsource()); dataset.setValue("Second hand", report.getSecondhandsource()); JFreeChart chart = ChartFactory.createPieChart("bar chart", dataset, true, true, true); PiePlot p = (PiePlot) chart.getPlot(); ChartFrame chartFrame = new ChartFrame("Source of Reports", chart); chartFrame.setSize(450, 550);//from www . j a v a 2s .c om chartFrame.setVisible(true); } else { JOptionPane.showMessageDialog(null, "Sorry, the final report has not been generated"); } }
From source file:canreg.client.analysis.Tools.java
public static JFreeChart generateJChart(Collection<CancerCasesCount> casesCounts, String fileName, String header, FileTypes fileType, ChartType chartType, boolean includeOther, boolean legendOn, Double restCount, Double allCount, Color color, String labelsCategoryName) { JFreeChart chart;// w w w. jav a2 s . c o m if (chartType == ChartType.PIE) { NumberFormat format = NumberFormat.getInstance(); format.setMaximumFractionDigits(1); DefaultPieDataset dataset = new DefaultKeyedValuesDataset(); int position = 0; for (CancerCasesCount count : casesCounts) { dataset.insertValue(position++, count.toString() + " (" + format.format(count.getCount() / allCount * 100) + "%)", count.getCount()); } if (includeOther) { dataset.insertValue(position++, "Other: " + restCount.intValue() + " (" + format.format(restCount / allCount * 100) + "%)", restCount); } chart = ChartFactory.createPieChart(header, dataset, legendOn, false, Locale.getDefault()); Tools.setPiePlotColours(chart, casesCounts.size() + 1, color.brighter()); } else { // assume barchart DefaultCategoryDataset dataset = new DefaultCategoryDataset(); for (CancerCasesCount count : casesCounts) { dataset.addValue(count.getCount(), count.getLabel(), count.toString()); } if (includeOther) { dataset.addValue(restCount.intValue(), "Other", "Other: " + restCount); } chart = ChartFactory.createStackedBarChart(header, labelsCategoryName, "Cases", dataset, PlotOrientation.HORIZONTAL, legendOn, true, false); Tools.setBarPlotColours(chart, casesCounts.size() + 1, color.brighter()); } return chart; }
From source file:edu.ucla.stat.SOCR.applications.demo.PortfolioApplication2.java
protected JFreeChart createEmptyChart(String chartTitle, PieDataset dataset) { JFreeChart chart = ChartFactory.createPieChart(chartTitle, // chart title null, // data true, // include legend true, false);/*from www. ja v a2s . c o m*/ PiePlot plot = (PiePlot) chart.getPlot(); plot.setLabelFont(new Font("SansSerif", Font.PLAIN, 12)); plot.setNoDataMessage("No data available"); plot.setCircular(false); plot.setLabelGap(0.02); return chart; }
From source file:org.gridchem.client.gui.charts.UsageChart.java
private void init() { removeAll();//from ww w. j a va 2s .c o m String title = ""; if (CURRENT_CHARTTYPE.equals(ChartType.JOB)) { // dataset = createJobDataset(projectTable); dataset = new DefaultPieDataset(); } else if (CURRENT_CHARTTYPE.equals(ChartType.PROJECT)) { dataset = createProjectDataset(projectCollabTable); title = "CCG Utilization by Project"; } else if (CURRENT_CHARTTYPE.equals(ChartType.RESOURCE)) { dataset = createResourceDataset(projectCollabTable); title = "CCG Utilization by Resource"; } else if (CURRENT_CHARTTYPE.equals(ChartType.USER)) { dataset = createUserDataset(projectCollabTable); title = "CCG Utilization by User"; } chart = ChartFactory.createPieChart(title, // chart title dataset, // data false, // include legend true, // tooltips? false // URLs? ); if (projectCollabTable.size() == 1) { ProjectBean project = projectCollabTable.keySet().iterator().next(); chart.addSubtitle( new TextTitle("Project " + project.getName() + " expires on " + project.getEndDate())); } ((PiePlot) chart.getPlot()).setCircular(true); // ((PiePlot)chart.getPlot()).setExplodePercent(new Integer(defaultProjectIndex), 25); if (CURRENT_CHARTTYPE.equals(ChartType.JOB)) { chart.getPlot().setNoDataMessage("Comprehensive job information is not currently available."); } chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(size); setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.weightx = 1.0; c.weighty = 1.0; c.gridx = 0; c.gridy = 0; c.fill = GridBagConstraints.BOTH; add(chartPanel, c); GridBagConstraints c1 = new GridBagConstraints(); c1.weightx = 0; c1.weighty = 0; c1.gridx = 0; c1.gridy = 1; c1.fill = GridBagConstraints.BOTH; add(navPanel, c1); revalidate(); // setPreferredSize(size); }
From source file:org.psystems.dicom.browser.server.stat.UseagStoreChartServlet.java
public JFreeChart getChart() { PreparedStatement psSelect = null; try {/*from ww w .ja v a 2s . co m*/ Connection connection = Util.getConnection("main", getServletContext()); long dcmSizes = 0; long imgSizes = 0; // // ALL_IMAGE_SIZE // ALL_DCM_SIZE // psSelect = connection // .prepareStatement("SELECT ID, METRIC_NAME, METRIC_DATE, METRIC_VALUE_LONG " // + " FROM WEBDICOM.DAYSTAT WHERE METRIC_NAME = ?"); psSelect = connection.prepareStatement( "SELECT SUM(METRIC_VALUE_LONG) S " + " FROM WEBDICOM.DAYSTAT WHERE METRIC_NAME = ?"); psSelect.setString(1, "ALL_DCM_SIZE"); ResultSet rs = psSelect.executeQuery(); while (rs.next()) { dcmSizes = rs.getLong("S"); } rs.close(); psSelect.setString(1, "ALL_IMAGE_SIZE"); rs = psSelect.executeQuery(); while (rs.next()) { imgSizes = rs.getLong("S"); } rs.close(); String dcmRootDir = getServletContext().getInitParameter("webdicom.dir.src"); long totalSize = new File(dcmRootDir).getTotalSpace(); //TODO ! long freeSize = new File(dcmRootDir).getFreeSpace(); long busySize = totalSize - freeSize; // System.out.println("!!! totalSize=" + totalSize + " freeSize="+freeSize); long diskEmpty = freeSize - imgSizes - dcmSizes; // double KdiskEmpty = (double)diskEmpty/(double)totalSize; // System.out.println("!!! " + KdiskEmpty); double KdiskBusi = (double) busySize / (double) totalSize * 100; // System.out.println("!!! KdiskBusi=" + KdiskBusi); double KdcmSizes = (double) dcmSizes / (double) totalSize * 100; // System.out.println("!!! KdcmSizes=" + KdcmSizes); double KimgSizes = (double) imgSizes / (double) totalSize * 100; // System.out.println("!!! KimgSizes=" + KimgSizes); double KdiskFree = (double) freeSize / (double) (totalSize - KdcmSizes - KimgSizes) * 100; // System.out.println("!!! KdiskFree=" + KdiskFree); DefaultPieDataset dataset = new DefaultPieDataset(); dataset.setValue("??? (DCM-) " + dcmSizes / 1000 + " .", KdcmSizes); dataset.setValue("? (JPG-) " + imgSizes / 1000 + " .", KimgSizes); dataset.setValue("? " + busySize / 1000 + " .", KdiskBusi); dataset.setValue(" " + freeSize / 1000 + " .", KdiskFree); boolean legend = true; boolean tooltips = false; boolean urls = false; JFreeChart chart = ChartFactory.createPieChart( "? ? ?? ?", dataset, legend, tooltips, urls); chart.setBorderPaint(Color.GREEN); chart.setBorderStroke(new BasicStroke(5.0f)); // chart.setBorderVisible(true); // chart.setPadding(new RectangleInsets(20 ,20,20,20)); return chart; } catch (SQLException e) { logger.error(e); e.printStackTrace(); } finally { try { if (psSelect != null) psSelect.close(); } catch (SQLException e) { logger.error(e); } } return null; }