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:edu.ucla.stat.SOCR.chart.SuperPieChart.java
/** * Creates a chart.// ww w .j a v a 2s.co m * * @param dataset the dataset. * * @return a chart. */ protected JFreeChart createChart(PieDataset dataset) { JFreeChart chart = ChartFactory.createPieChart(chartTitle, // chart title dataset, // data !legendPanelOn, // include legend true, false); TextTitle title = chart.getTitle(); title.setToolTipText("A title tooltip!"); PiePlot plot = (PiePlot) chart.getPlot(); if (!ThreeDPie) { for (int i = 0; i < pulloutFlag.length; i++) { //System.out.println("SuperPieChart\""+pulloutFlag[i]+"\""); if (pulloutFlag[i].equals("1")) { Comparable key = dataset.getKey(i); plot.setExplodePercent(key, 0.30); } } } 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:userinterface.AdminRole.DataAnalysisJPanel.java
private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed // TODO add your handling code here: int haemo = 0, bp = 0, weight = 0, temp = 0; for (Organization org : enterprise.getOrganizationDirectory().getOrganizationList()) { if (org instanceof DonorOrganization) { for (Donor donor : org.getDonorDirectory().getDonorList()) { for (VitalSigns vs : donor.getVsh().getVitalSignHistory()) { if (vs.getHaemoglobinLevel() < 13) { haemo++;/*from w ww .j a v a2 s.c o m*/ } if (vs.getBloodPressure() < 80 || vs.getBloodPressure() > 120) { bp++; } if (vs.getWeight() < 110 || vs.getWeight() > 400) { weight++; } if (vs.getTemperature() < 90 || vs.getTemperature() > 99) { temp++; } } } } } DefaultPieDataset dataset = new DefaultPieDataset(); dataset.setValue("haemoglobin", haemo); dataset.setValue("bloodpressure", bp); dataset.setValue("weight", weight); dataset.setValue("temperature", temp); JFreeChart chart = ChartFactory.createPieChart("DonorInformation", dataset, true, true, true); // CategoryPlot p = chart.getCategoryPlot(); // p.setRangeGridlinePaint(Color.black); PiePlot p = (PiePlot) chart.getPlot(); ChartFrame frame = new ChartFrame("Donor Information", chart); frame.setVisible(true); frame.setSize(450, 500); }
From source file:org.pentaho.reporting.engine.classic.extensions.legacy.charts.LegacyChartType.java
private JFreeChart createChart(final Expression aExpression) { if (aExpression instanceof BarLineChartExpression) { final CategoryAxis catAxis = new CategoryAxis("Category");// NON-NLS final NumberAxis barsAxis = new NumberAxis("Value");// NON-NLS final NumberAxis linesAxis = new NumberAxis("Value2");// NON-NLS final CategoryPlot plot = new CategoryPlot(createDataset(), catAxis, barsAxis, new BarRenderer()); plot.setRenderer(1, new LineAndShapeRenderer()); // add lines dataset and axis to plot plot.setDataset(1, createDataset()); plot.setRangeAxis(1, linesAxis); // map lines to second axis plot.mapDatasetToRangeAxis(1, 1); // set rendering order plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD); // set location of second axis plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_RIGHT); return new JFreeChart("Bar Line Chart", plot); }/*from ww w . j a v a2 s. c o m*/ if (aExpression instanceof RingChartExpression) { return ChartFactory.createRingChart("Ring Chart", createPieDataset(), true, false, false);// NON-NLS } if (aExpression instanceof AreaChartExpression) { return ChartFactory.createAreaChart("Area Chart", "Category", "Value", createDataset(), PlotOrientation.VERTICAL, true, false, false);// NON-NLS } if (aExpression instanceof BarChartExpression) { return ChartFactory.createBarChart("Bar Chart", "Category", "Value", createDataset(), PlotOrientation.VERTICAL, true, false, false);// NON-NLS } if (aExpression instanceof LineChartExpression) { return ChartFactory.createLineChart("Line Chart", "Category", "Value", createDataset(), PlotOrientation.VERTICAL, true, false, false);// NON-NLS } if (aExpression instanceof MultiPieChartExpression) { return ChartFactory.createMultiplePieChart("Multi Pie Chart", createDataset(), TableOrder.BY_COLUMN, true, false, false);// NON-NLS } if (aExpression instanceof PieChartExpression) { return ChartFactory.createPieChart("Pie Chart", createPieDataset(), true, false, false);// NON-NLS } if (aExpression instanceof WaterfallChartExpressions) { return ChartFactory.createWaterfallChart("Bar Chart", "Category", "Value", createDataset(), PlotOrientation.HORIZONTAL, true, false, false);// NON-NLS } if (aExpression instanceof BubbleChartExpression) { return ChartFactory.createBubbleChart("Bubble Chart", "X", "Y", createXYZDataset(), PlotOrientation.VERTICAL, true, false, false);// NON-NLS } if (aExpression instanceof ExtendedXYLineChartExpression) { return ChartFactory.createXYLineChart("XY Line Chart", "X", "Y", createXYZDataset(), PlotOrientation.VERTICAL, true, false, false);// NON-NLS } if (aExpression instanceof ScatterPlotChartExpression) { return ChartFactory.createScatterPlot("Scatter Chart", "X", "Y", createXYZDataset(), PlotOrientation.VERTICAL, true, false, false);// NON-NLS } if (aExpression instanceof XYAreaLineChartExpression) { final NumberAxis catAxis = new NumberAxis("Range");// NON-NLS final NumberAxis barsAxis = new NumberAxis("Value");// NON-NLS final NumberAxis linesAxis = new NumberAxis("Value2");// NON-NLS final XYPlot plot = new XYPlot(createXYZDataset(), catAxis, barsAxis, new XYAreaRenderer()); plot.setRenderer(1, new XYLineAndShapeRenderer()); // add lines dataset and axis to plot plot.setDataset(1, createXYZDataset()); plot.setRangeAxis(1, linesAxis); // map lines to second axis plot.mapDatasetToRangeAxis(1, 1); // set rendering order plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD); // set location of second axis plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_RIGHT); return new JFreeChart("XY Area Line Chart", plot);// NON-NLS } if (aExpression instanceof XYAreaChartExpression) { return ChartFactory.createXYAreaChart("XY Area Chart", "X", "Y", createXYZDataset(), PlotOrientation.VERTICAL, true, false, false);// NON-NLS } if (aExpression instanceof XYBarChartExpression) { return XYBarChartExpression.createXYBarChart("XY Bar Chart", "X", false, "Y", createIntervalXYDataset(), PlotOrientation.VERTICAL, true, false, false);// NON-NLS } if (aExpression instanceof XYLineChartExpression) { return ChartFactory.createXYLineChart("XY Line Chart", "X", "Y", createXYZDataset(), PlotOrientation.VERTICAL, true, false, false);// NON-NLS } if (aExpression instanceof RadarChartExpression) { final SpiderWebPlot plot = new SpiderWebPlot(createDataset()); return new JFreeChart("Radar Chart", JFreeChart.DEFAULT_TITLE_FONT, plot, true); } if (aExpression instanceof ThermometerChartExpression) { final DefaultValueDataset dataset = new DefaultValueDataset(new Double(65.0)); final ThermometerPlot plot = new ThermometerPlot(dataset); return new JFreeChart("Thermometer Chart", JFreeChart.DEFAULT_TITLE_FONT, plot, true); } return null; }
From source file:tdunnick.jphineas.console.queue.Charts.java
private JFreeChart createPieChart(String title, PieDataset dataset) { JFreeChart chart = ChartFactory.createPieChart(title, // chart title dataset, // data false, // legend true, // tool tips false); // urls PiePlot plot = (PiePlot) chart.getPlot(); // add a URL map to this image for selection o f constraints plot.setURLGenerator(new StandardPieURLGenerator("", "constraint")); // simple labels use less horizontal space plot.setSimpleLabels(true);/*from ww w . ja v a 2 s . com*/ return chart; }
From source file:projekt.CustomRenderer.java
public void raport_lokalny() throws IOException, ClassNotFoundException, SQLException { loginController login = new loginController(); String zapytanie = "select count(*) as Aktualne from projekty, (SELECT Nazwa, Opis, Status_zadania, idUzytkownika,projekt from zadania where Status_zadania = 'Aktualne' and idUzytkownika = '" + login.uzytkownikID + "') x where projekty.Nazwa = x.projekt"; String zapytanie1 = "select count(*) as FORTEST from projekty, (SELECT Nazwa, Opis, Status_zadania, idUzytkownika,projekt from zadania where Status_zadania = 'FORTEST' and idUzytkownika = '" + login.uzytkownikID + "') x where projekty.Nazwa = x.projekt"; String zapytanie2 = "select count(*) as Zakonczone from projekty, (SELECT Nazwa, Opis, Status_zadania, idUzytkownika,projekt from zadania where Status_zadania = 'Zakonczone' and idUzytkownika = '" + login.uzytkownikID + "') x where projekty.Nazwa = x.projekt"; Class.forName("com.mysql.jdbc.Driver"); Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/pz?characterEncoding=utf8", "root", ""); PreparedStatement statment;//from w w w . ja va 2s . c o m ResultSet result; double odp = 0, odp1 = 0, odp2 = 0; statment = con.prepareStatement(zapytanie); result = statment.executeQuery(); if (result.next()) { odp = result.getDouble("Aktualne"); } statment = con.prepareStatement(zapytanie1); result = statment.executeQuery(); if (result.next()) { odp1 = result.getDouble("FORTEST"); } statment = con.prepareStatement(zapytanie2); result = statment.executeQuery(); if (result.next()) { odp2 = result.getDouble("Zakonczone"); } //tu tez zmienic na id statment = con.prepareStatement( "SELECT CONCAT(imie, ' ', nazwisko) as osoba from uzytkownicy WHERE idUzytkownika = '" + login.uzytkownikID + "'"); result = statment.executeQuery(); String bbc = ""; if (result.next()) { bbc = result.getString(1); } DefaultCategoryDataset set2 = new DefaultCategoryDataset(); set2.setValue(odp, "", "Aktualne"); set2.setValue(odp1, "", "FORTEST"); set2.setValue(odp2, "", "Zakonczone"); JFreeChart chart = ChartFactory.createBarChart( "Wszystkie zadania z projektow za ktore odpowiada " + result.getString(1), "Zadania", "Ilosc", set2, PlotOrientation.VERTICAL, false, true, false); final CategoryItemRenderer renderer = new CustomRenderer(new Paint[] { Color.blue, Color.pink, Color.cyan, Color.yellow, Color.orange, Color.cyan, Color.magenta, Color.blue }); final CategoryPlot plot = chart.getCategoryPlot(); plot.setNoDataMessage("NO DATA!"); renderer.setItemLabelsVisible(true); final ItemLabelPosition p = new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER, TextAnchor.CENTER, 45.0); renderer.setPositiveItemLabelPosition(p); plot.setRenderer(renderer); ByteArrayOutputStream out = new ByteArrayOutputStream(); ChartUtilities.writeChartAsJPEG(out, chart, 450, 600); DateFormat dataformat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); DateFormat dataformat1 = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss"); Date data = new Date(); String fileName = "Raport lokalny " + dataformat1.format(data) + ".pdf"; try { PDRectangle PAGE_SIZE = PDRectangle.A4; PDDocument doc = new PDDocument(); PDFont font = PDType0Font.load(doc, getClass().getResourceAsStream("/fonts/RobotoCondensed-Regular.ttf")); PDFont font1 = PDType0Font.load(doc, getClass().getResourceAsStream("/fonts/RobotoCondensed-Bold.ttf")); PDPage page = new PDPage(PAGE_SIZE); PDPage page1 = new PDPage(PAGE_SIZE); doc.addPage(page); PDPageContentStream content = new PDPageContentStream(doc, page); //naglowek strona 1 Naglowek1(content, dataformat, data); //stopka strona1 Stopka(content, doc); content.beginText(); content.setFont(font1, 48); content.moveTextPositionByAmount(135, 550); content.showText("Raport lokalny"); content.endText(); content.beginText(); content.setFont(font, 22); content.moveTextPositionByAmount(30, 250); content.showText("Wersja systemu : 1.0"); content.newLine(); content.moveTextPositionByAmount(0, 35); content.showText("Autor raportu : " + result.getString("osoba")); content.endText(); content.close(); PDPageContentStream content1 = new PDPageContentStream(doc, page1); PDPage page2 = new PDPage(PAGE_SIZE); doc.addPage(page2); PDPageContentStream content2 = new PDPageContentStream(doc, page2); Naglowek1(content2, dataformat, data); //stopka strona2 Stopka(content2, doc); content2.beginText(); content2.setFont(font, 14); content2.moveTextPositionByAmount(30, 775); content2.showText("Wszystkie projekty za ktre odpowiada: " + result.getString(1)); statment = con.prepareStatement( "Select Nazwa, Opis, Poczatek, Koniec, ludzie from projekty where idUzytkownika='" + login.uzytkownikID + "'"); result = statment.executeQuery(); content2.newLine(); int liczba = 615; content2.moveTextPositionByAmount(0, -15); while (result.next()) { content2.newLine(); content2.moveTextPositionByAmount(0, -22); liczba += 22; //content2.showText("Nazwa : "+result.getString("Nazwa")+" Opis: "+result.getString("Opis")+" Data rozpoczecia: "+result.getString("Poczatek")+" Data zakonczenia: "+result.getString("Koniec")); content2.showText("Nazwa : " + result.getString("Nazwa") + " Opis: " + result.getString(1)); content2.newLine(); content2.moveTextPositionByAmount(0, -17); liczba += 22; content2.showText("Data rozpoczecia: " + result.getString("Poczatek") + " Data zakonczenia: " + result.getString("Koniec")); } content2.endText(); // content2.setLineWidth(2); // content2.moveTo(10, liczba + 5); // content2.lineTo(10, liczba +5); // content2.closeAndStroke(); DateFormat dataformat2 = new SimpleDateFormat("yyyy-MM-dd"); statment = con.prepareStatement("Select count(*) as 'Aktualne' from projekty where Koniec > '" + dataformat2.format(data) + "' and idUzytkownika='" + login.uzytkownikID + "'"); result = statment.executeQuery(); int aktualne = 0, zakonczone = 0; if (result.next()) { aktualne = result.getInt("Aktualne"); } statment = con.prepareStatement("Select count(*) as 'Zakonczone' from projekty where Koniec < '" + dataformat2.format(data) + "' and idUzytkownika='" + login.uzytkownikID + "'"); result = statment.executeQuery(); if (result.next()) { zakonczone = result.getInt("Zakonczone"); } DefaultPieDataset pieDataset = new DefaultPieDataset(); pieDataset.setValue("Aktualne", aktualne); pieDataset.setValue("Zakonczone", zakonczone); JFreeChart chart1 = ChartFactory.createPieChart("Zestawienia projekt za ktore odpowiada" + bbc, // Title pieDataset, // Dataset true, // Show legend true, // Use tooltips false // Configure chart to generate URLs? ); PiePlot plot1 = (PiePlot) chart1.getPlot(); plot1.setSectionPaint("Aktualne", Color.blue); plot1.setSectionPaint("Zakonczone", Color.yellow); plot1.setExplodePercent("Aktualne", 0.10); plot1.setSimpleLabels(true); PieSectionLabelGenerator gen = new StandardPieSectionLabelGenerator("{0}: {1} ({2})", new DecimalFormat("0"), new DecimalFormat("0%")); plot1.setLabelGenerator(gen); ByteArrayOutputStream out1 = new ByteArrayOutputStream(); ChartUtilities.writeChartAsJPEG(out1, chart1, 450, 600); PDImageXObject img1 = JPEGFactory.createFromStream(doc, new ByteArrayInputStream(out1.toByteArray())); content2.close(); PDPage page3 = new PDPage(PAGE_SIZE); doc.addPage(page3); PDPageContentStream content3 = new PDPageContentStream(doc, page3); Naglowek1(content3, dataformat, data); //stopka strona2 Stopka(content3, doc); content3.drawImage(img1, 50, 50); content3.close(); PDPage page4 = new PDPage(PAGE_SIZE); doc.addPage(page4); PDPageContentStream content4 = new PDPageContentStream(doc, page4); Naglowek1(content4, dataformat, data); //stopka strona2 Stopka(content4, doc); content4.beginText(); content4.setFont(font, 14); content4.moveTextPositionByAmount(30, 780); content4.showText("Wszystkie zadania w projektach za ktore odpowiada:" + bbc); statment = con.prepareStatement( "SELECT zadania.Nazwa,zadania.Opis,zadania.Status_zadania,zadania.projekt, z.Imie, z.Nazwisko,CONCAT(y.imie, ' ' , y.nazwisko) as 'UZY' FROM zadania , (select Nazwa from projekty where idUzytkownika = '" + login.uzytkownikID + "') x, (SELECT imie, nazwisko, idUzytkownika from uzytkownicy) y,(SELECT imie, nazwisko, idUzytkownika from uzytkownicy where idUzytkownika = '" + login.uzytkownikID + "') z WHERE zadania.projekt = x.Nazwa LIMIT 12"); //poprawic result = statment.executeQuery(); content4.newLine(); int nw = 850; content4.moveTextPositionByAmount(0, -15); nw -= 15; while (result.next()) { content4.newLine(); nw -= 22; content4.moveTextPositionByAmount(0, -22); //content2.showText("Nazwa : "+result.getString("Nazwa")+" Opis: "+result.getString("Opis")+" Data rozpoczecia: "+result.getString("Poczatek")+" Data zakonczenia: "+result.getString("Koniec")); content4.showText("Nazwa : " + result.getString("zadania.Nazwa")); content4.newLine(); nw -= 17; content4.moveTextPositionByAmount(0, -17); content4.showText(" Opis: " + result.getString("zadania.Opis") + " Status zadania: " + result.getString("zadania.Status_zadania")); content4.newLine(); nw -= 17; content4.moveTextPositionByAmount(0, -17); content4.showText(" Projekt: " + result.getString("zadania.projekt") + " Przydzielona osoba do zadania: " + result.getString("UZY")); } content4.endText(); content4.close(); statment = con.prepareStatement( "SELECT count(*) as 'liczba' FROM `zadania` where idUzytkownika='" + login.uzytkownikID + "'"); //poprawic result = statment.executeQuery(); if (result.next()) { } statment = con.prepareStatement( "SELECT zadania.Nazwa,zadania.Opis,zadania.Status_zadania,zadania.projekt, z.Imie, z.Nazwisko,CONCAT(y.imie, \" \", y.nazwisko) as \"UZY\" FROM zadania , (select Nazwa from projekty where idUzytkownika = '" + login.uzytkownikID + "') x, (SELECT imie, nazwisko, idUzytkownika from uzytkownicy) y,(SELECT imie, nazwisko, idUzytkownika from uzytkownicy where idUzytkownika = '" + login.uzytkownikID + "') z WHERE zadania.projekt = x.Nazwa LIMIT 12," + result.getInt(1) + ""); result = statment.executeQuery(); PDPage page5 = new PDPage(PAGE_SIZE); doc.addPage(page5); PDPageContentStream content5 = new PDPageContentStream(doc, page5); Naglowek1(content5, dataformat, data); //stopka strona2 Stopka(content5, doc); content5.beginText(); content5.setFont(font, 14); content5.moveTextPositionByAmount(30, 700); while (result.next()) { content5.newLine(); nw -= 22; content5.moveTextPositionByAmount(0, -22); //content2.showText("Nazwa : "+result.getString("Nazwa")+" Opis: "+result.getString("Opis")+" Data rozpoczecia: "+result.getString("Poczatek")+" Data zakonczenia: "+result.getString("Koniec")); content5.showText("Nazwa : " + result.getString("zadania.Nazwa")); content5.newLine(); nw -= 17; content5.moveTextPositionByAmount(0, -17); content5.showText(" Opis: " + result.getString("zadania.Opis") + " Status zadania: " + result.getString("zadania.Status_zadania")); content5.newLine(); nw -= 17; content5.moveTextPositionByAmount(0, -17); content5.showText(" Projekt: " + result.getString("zadania.projekt") + " Przydzielona osoba do zadania: " + result.getString("UZY")); } content5.endText(); content5.close(); doc.addPage(page1); //naglowek strona 2 Naglowek1(content1, dataformat, data); //stopka strona2 Stopka(content1, doc); PDImageXObject img = JPEGFactory.createFromStream(doc, new ByteArrayInputStream(out.toByteArray())); content1.drawImage(img, 50, 50); content1.close(); doc.save(fileName); doc.close(); } catch (Exception e) { System.err.println(e.getMessage()); } }
From source file:uk.ac.lkl.cram.ui.chart.LearningTypeChartMaker.java
/** * Create a chart from the provide pie dataset * * @return a Chart that can be rendered in a ChartPanel *///from ww w. jav a 2 s .com @Override protected JFreeChart createChart() { //Create a pie chart from the chart factory with no title, a legend and tooltips JFreeChart chart = ChartFactory.createPieChart(null, (PieDataset) dataset, true, true, false); //Get the plot from the chart PiePlot plot = (PiePlot) chart.getPlot(); //Set the tooltip generator, to be "Practice (12%)" plot.setToolTipGenerator(new StandardPieToolTipGenerator( "<html><center>{0} ({2})<br/>Double-click for more</center></html>")); //Remove shadows from the plot plot.setShadowXOffset(0); plot.setShadowYOffset(0); //Remove the labels from the plot plot.setLabelGenerator(null); //Set the colours for the segments plot.setSectionPaint(ACQUISITION, ACQUISITION_COLOR); plot.setSectionPaint(COLLABORATION, COLLABORATION_COLOR); plot.setSectionPaint(DISCUSSION, DISCUSSION_COLOR); plot.setSectionPaint(INQUIRY, INQUIRY_COLOR); plot.setSectionPaint(PRACTICE, PRACTICE_COLOR); plot.setSectionPaint(PRODUCTION, PRODUCTION_COLOR); return chart; }
From source file:com.ikon.servlet.admin.StatsGraphServlet.java
/** * Generate repository statistics/* www. j a v a 2s. co m*/ */ public JFreeChart repoStats(String type) throws IOException, ServletException { String title = null; long[] sizes = null; double[] percents = null; DefaultPieDataset dataset = new DefaultPieDataset(); if (DOCUMENTS.equals(type)) { StatsInfo si = RepositoryInfo.getDocumentsByContext(); percents = si.getPercents(); sizes = si.getSizes(); title = "Documents by context"; } else if (DOCUMENTS_SIZE.equals(type)) { StatsInfo si = RepositoryInfo.getDocumentsSizeByContext(); percents = si.getPercents(); sizes = si.getSizes(); title = "Documents size by context"; } else if (FOLDERS.equals(type)) { StatsInfo si = RepositoryInfo.getFoldersByContext(); percents = si.getPercents(); sizes = si.getSizes(); title = "Folders by context"; } if (title != null && sizes.length > 0 && percents.length > 0) { String taxonomySize = DOCUMENTS_SIZE.equals(type) ? FormatUtil.formatSize(sizes[0]) : Long.toString(sizes[0]); String personalSize = DOCUMENTS_SIZE.equals(type) ? FormatUtil.formatSize(sizes[1]) : Long.toString(sizes[1]); String templateSize = DOCUMENTS_SIZE.equals(type) ? FormatUtil.formatSize(sizes[2]) : Long.toString(sizes[2]); String trashSize = DOCUMENTS_SIZE.equals(type) ? FormatUtil.formatSize(sizes[3]) : Long.toString(sizes[3]); dataset.setValue("Taxonomy (" + taxonomySize + ")", percents[0]); dataset.setValue("Personal (" + personalSize + ")", percents[1]); dataset.setValue("Template (" + templateSize + ")", percents[2]); dataset.setValue("Trash (" + trashSize + ")", percents[3]); } return ChartFactory.createPieChart(title, dataset, true, false, false); }
From source file:UserInterface.CentreForDiseaseControl.DataAnalysis.java
private void summarizeInsuranceJButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_summarizeInsuranceJButtonActionPerformed // TODO add your handling code here: DefaultPieDataset pieDataset = new DefaultPieDataset(); int numberOfCitizensWithNoInsurance = 0; for (PHDEnterprise phdEnterprise : enterprise.getPhdList()) { for (SiteEnterprise siteEnterprise : phdEnterprise.getSiteList()) { for (Person person : siteEnterprise.getPersonDirectory().getPersonList()) { if (person instanceof Patient) { Patient patient = (Patient) person; if (patient.getInsuranceInformation().equals("No Insurance")) { numberOfCitizensWithNoInsurance++; }// www . j av a2 s. com } } } } pieDataset.setValue("No Insurance", numberOfCitizensWithNoInsurance); int numberOfCitizensWithPrivateInsurance = 0; for (PHDEnterprise phdEnterprise : enterprise.getPhdList()) { for (SiteEnterprise siteEnterprise : phdEnterprise.getSiteList()) { for (Person person : siteEnterprise.getPersonDirectory().getPersonList()) { if (person instanceof Patient) { Patient patient = (Patient) person; if (patient.getInsuranceInformation().equals("Private Insurance Coverage")) { numberOfCitizensWithPrivateInsurance++; } } } } } pieDataset.setValue("Private Insurance", numberOfCitizensWithPrivateInsurance); int numberOfCitizensUnderInsured = 0; for (PHDEnterprise phdEnterprise : enterprise.getPhdList()) { for (SiteEnterprise siteEnterprise : phdEnterprise.getSiteList()) { for (Person person : siteEnterprise.getPersonDirectory().getPersonList()) { if (person instanceof Patient) { Patient patient = (Patient) person; if (patient.getInsuranceInformation().equals("Under Insured")) { numberOfCitizensUnderInsured++; } } } } } pieDataset.setValue("Under Insured", numberOfCitizensUnderInsured); JFreeChart chart = ChartFactory.createPieChart("Pie Chart", pieDataset, true, true, true); PiePlot p = (PiePlot) chart.getPlot(); ChartFrame frame = new ChartFrame("Insurance Information of Citizens", chart); frame.setVisible(true); frame.setSize(450, 500); }
From source file:edu.ucla.stat.SOCR.chart.SuperPieChart.java
protected JFreeChart createLegend(PieDataset dataset) { JFreeChart chart = ChartFactory.createPieChart(chartTitle, // chart title dataset, // data true, // include legend true, // tooltips false // urls );//from w w w .ja v a 2 s. com // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART... chart.setBackgroundPaint(Color.white); return chart; }
From source file:de.xirp.chart.ChartManager.java
/** * Returns a pie chart. The chart is generated from the given * {@link de.xirp.db.Record} and key array. The flag * <code>relative</code> indicated whether or not relative * values should be used.//from ww w.j ava2 s . c om * * @param record * The record containing the data. * @param keys * The keys to use. * @param relative * Flag indicating if relative values should be used. * @return A pie chart. * @see org.jfree.chart.JFreeChart * @see de.xirp.db.Record */ private static JFreeChart createPieChart(Record record, String[] keys, boolean relative) { String chartTitle = (relative ? I18n.getString("ChartManager.text.relative") //$NON-NLS-1$ : I18n.getString("ChartManager.text.absolute")) //$NON-NLS-1$ + I18n.getString("ChartManager.text.occurencesOfKey") + record.getName() + ": "; //$NON-NLS-1$ //$NON-NLS-2$ DefaultPieDataset dataset = new DefaultPieDataset(); Map<String, Long> values; values = ChartDatabaseUtil.getValuesForRecord(record, keys, relative); for (String s : values.keySet()) { dataset.setValue(s, values.get(s)); } JFreeChart chart; if (options.is(OptionName.THREE_D)) { chart = ChartFactory.createPieChart3D(chartTitle, dataset, true, true, false); PiePlot3D plot = (PiePlot3D) chart.getPlot(); plot.setStartAngle(290); plot.setDirection(Rotation.CLOCKWISE); plot.setForegroundAlpha(0.5f); plot.setNoDataMessage(NO_DATA_AVAILABLE); plot.setLabelGenerator(new CustomLabelGenerator(options)); } else { chart = ChartFactory.createPieChart(chartTitle, dataset, true, true, false); PiePlot plot = (PiePlot) chart.getPlot(); plot.setSectionOutlinesVisible(true); plot.setNoDataMessage(NO_DATA_AVAILABLE); plot.setCircular(false); plot.setLabelGap(0.02); plot.setLabelGenerator(new CustomLabelGenerator(options)); } exportAutomatically(null, chart); return chart; }