List of usage examples for org.jfree.data.general DefaultPieDataset setValue
public void setValue(Comparable key, double value)
From source file:com.haskins.cloudtrailviewer.utils.ChartFactory.java
private static ChartPanel createPieChart(String type, List<Entry<String, Integer>> events, int width, int height) { DefaultPieDataset dataset = new DefaultPieDataset(); for (Map.Entry<String, Integer> event : events) { dataset.setValue(event.getKey(), event.getValue()); }// w ww . jav a 2 s . co m JFreeChart jFChart; if (type.contains("3d")) { jFChart = org.jfree.chart.ChartFactory.createPieChart3D("", dataset, false, true, false); } else { jFChart = org.jfree.chart.ChartFactory.createPieChart("", dataset, false, true, false); } PiePlot plot = (PiePlot) jFChart.getPlot(); plot.setBackgroundPaint(null); plot.setInteriorGap(0.01); plot.setOutlineVisible(false); plot.setLabelGenerator(null); // use gradients and white borders for the section colours plot.setBaseSectionOutlinePaint(Color.WHITE); plot.setSectionOutlinesVisible(true); plot.setBaseSectionOutlineStroke(new BasicStroke(2.0f)); TextTitle t = jFChart.getTitle(); t.setHorizontalAlignment(HorizontalAlignment.LEFT); t.setFont(new Font("Arial", Font.BOLD, 16)); final ChartPanel jChartPanel = new ChartPanel(jFChart, width, height, width, height, width, height, false, false, true, true, false, true); jChartPanel.setMinimumDrawWidth(0); jChartPanel.setMaximumDrawWidth(Integer.MAX_VALUE); jChartPanel.setMinimumDrawHeight(0); jChartPanel.setMaximumDrawHeight(Integer.MAX_VALUE); return jChartPanel; }
From source file:br.ufba.eleicoestransparentes.view.chart.GraficoPizza.java
/** * Creates a sample dataset./* ww w . ja va2 s . c o m*/ * * @return A sample dataset. */ private static PieDataset createDataset(ArrayList<PontosGrafico> pontos) { DefaultPieDataset dataset = new DefaultPieDataset(); for (PontosGrafico ponto : pontos) dataset.setValue(ponto.rotulo, new Double(ponto.valor)); return dataset; }
From source file:cz.zcu.kiv.eegdatabase.wui.components.utils.ChartUtils.java
public static BufferedImage gererateChartForTopDownloadHistory(ChoiceHistory choiceHistory, boolean generateEmptyGraph, List<DownloadStatistic> topDownloadedFilesList, long countOfFilesHistory) { long countFile = 0; DefaultPieDataset dataset = new DefaultPieDataset(); if (!generateEmptyGraph && topDownloadedFilesList != null) { for (int i = 0; i < topDownloadedFilesList.size(); i++) { dataset.setValue(topDownloadedFilesList.get(i).getFileName(), new Long(topDownloadedFilesList.get(i).getCount())); countFile = countFile + topDownloadedFilesList.get(i).getCount(); }/*from w ww .j av a2s.co m*/ if (countOfFilesHistory > countFile) { dataset.setValue("Other", countOfFilesHistory - countFile); } } String chartTitle = ResourceUtils.getString("title.dailyStatistic"); if (choiceHistory == ChoiceHistory.WEEKLY) { chartTitle = ResourceUtils.getString("title.weeklyStatistic"); } else if (choiceHistory == ChoiceHistory.MONTHLY) { chartTitle = ResourceUtils.getString("title.monthlyStatistic"); } JFreeChart chart = ChartFactory.createPieChart3D(chartTitle, // chart // title dataset, // data true, // include legend true, false); PiePlot3D plot = (PiePlot3D) chart.getPlot(); plot.setStartAngle(290); plot.setDirection(Rotation.CLOCKWISE); plot.setForegroundAlpha(0.5f); plot.setNoDataMessage(ResourceUtils.getString("label.noDataMessage")); return chart.createBufferedImage(600, 400); }
From source file:org.gbif.portal.web.util.ChartUtils.java
/** * Writes out the image using the supplied file name. * // w w w .j a v a 2 s . c o m * @param legend * @param fileName * @return */ public static String writePieChartImageToTempFile(Map<String, Double> legend, String fileName) { String filePath = System.getProperty(tmpDirSystemProperty) + File.separator + fileName + defaultExtension; File fileToCheck = new File(filePath); if (fileToCheck.exists()) { return fileName + defaultExtension; } final DefaultPieDataset data = new DefaultPieDataset(); Set<String> keys = legend.keySet(); for (String key : keys) { logger.info("Adding key : " + key); data.setValue(key, legend.get(key)); } // create a pie chart... final boolean withLegend = true; final JFreeChart chart = ChartFactory.createPieChart(null, data, withLegend, false, false); PiePlot piePlot = (PiePlot) chart.getPlot(); piePlot.setLabelFont(new Font("Arial", Font.PLAIN, 10)); piePlot.setLabelBackgroundPaint(Color.WHITE); LegendTitle lt = chart.getLegend(); lt.setBackgroundPaint(Color.WHITE); lt.setWidth(300); lt.setBorder(0, 0, 0, 0); lt.setItemFont(new Font("Arial", Font.PLAIN, 11)); chart.setPadding(new RectangleInsets(0, 0, 0, 0)); chart.setBorderVisible(false); chart.setBackgroundImageAlpha(0); chart.setBackgroundPaint(Color.WHITE); chart.setBorderPaint(Color.LIGHT_GRAY); final BufferedImage image = new BufferedImage(300, 250, BufferedImage.TYPE_INT_RGB); KeypointPNGEncoderAdapter adapter = new KeypointPNGEncoderAdapter(); adapter.setQuality(1); try { adapter.encode(image); } catch (IOException e) { logger.error(e.getMessage(), e); } final Graphics2D g2 = image.createGraphics(); g2.setFont(new Font("Arial", Font.PLAIN, 11)); final Rectangle2D chartArea = new Rectangle2D.Double(0, 0, 300, 250); // draw chart.draw(g2, chartArea, null, null); try { FileOutputStream fOut = new FileOutputStream(fileToCheck); ChartUtilities.writeChartAsPNG(fOut, chart, 300, 250); return fileToCheck.getName(); } catch (IOException e) { logger.error(e.getMessage(), e); return null; } }
From source file:utils.Graphs.java
public static File generate(File baseFolder, String titles[], int[] values, Color backgroundColor) { DefaultPieDataset dataset = new DefaultPieDataset(); // add our data values int i = -1;//from w w w. j a va 2 s . c o m for (String title : titles) { i++; dataset.setValue(title, values[i]); } final JFreeChart chart = // ChartFactory.createPieChart("", dataset, true, true, false); ChartFactory.createPieChart("", // chart title dataset, // data true, // include legend true, false); PiePlot plot = (PiePlot) chart.getPlot(); //PiePlot3D plot = (PiePlot3D) chart.getPlot(); //plot.setStartAngle(290); plot.setStartAngle(45); plot.setDirection(Rotation.CLOCKWISE); plot.setForegroundAlpha(0.5f); // final PiePlot plot = (PiePlot) chart.getPlot(); plot.setBackgroundPaint(backgroundColor); // plot.setLegendLabelGenerator( // new StandardPieSectionLabelGenerator("{0} {2}")); chart.setBorderVisible(false); chart.getPlot().setOutlineVisible(false); chart.getLegend().setFrame(BlockBorder.NONE); // get the same background chart.setBackgroundPaint(backgroundColor); chart.getLegend().setBackgroundPaint(backgroundColor); // hide the shadow effects plot.setShadowXOffset(0); plot.setShadowYOffset(0); //chart.getLegend().setVisible(false); plot.setCircular(true); //plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0} {2}", NumberFormat.getNumberInstance(), NumberFormat plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{2}", NumberFormat.getNumberInstance(), NumberFormat.getPercentInstance())); plot.setNoDataMessage("No data found."); Color greenColor = new Color(0x8FBC0C); Color redColor = new Color(0xFF0000); //Color redColor = new Color(0xDA6022); plot.setSectionPaint(0, greenColor); plot.setSectionPaint(1, redColor); plot.setSectionOutlinesVisible(true); final ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection()); final File file = new File(baseFolder, "chart.png"); try { ChartUtilities.saveChartAsPNG(file, chart, 200, 160, info); } catch (IOException ex) { Logger.getLogger(Graphs.class.getName()).log(Level.SEVERE, null, ex); } // //// final ChartPanel chartPanel = new ChartPanel(chart, true); // final ChartPanel chartPanel = new ChartPanel(chart, true); // chartPanel.setMinimumDrawWidth(0); // chartPanel.setMaximumDrawWidth(Integer.MAX_VALUE); // chartPanel.setMinimumDrawHeight(0); // chartPanel.setMaximumDrawHeight(Integer.MAX_VALUE); // JDialog dialog = new JDialog(); // dialog.add(chartPanel); // dialog.setLayout(new GridLayout(1, 1)); // dialog.setSize(400, 200); // dialog.setVisible(true); return file; }
From source file:thesisdata.PieChartDemo1.java
/** * Creates a sample dataset.//from ww w. j ava 2 s .c om * * @return A sample dataset. */ private static PieDataset createDataset() { DefaultPieDataset dataset = new DefaultPieDataset(); try (BufferedReader br = new BufferedReader(new FileReader("summery.txt"))) { String line; while ((line = br.readLine()) != null) { String st[]; st = line.split(" "); dataset.setValue(st[0], new Double(st[1])); } } catch (Exception ex) { // return dataset; } return dataset; }
From source file:charts.PieChart3D.java
/** * Creates a sample dataset./* w w w.jav a 2s . c o m*/ * * Source: http://www.bbc.co.uk/news/business-15489523 * * @return A sample dataset. */ private static PieDataset createDataset(PieChartModel model) { DefaultPieDataset dataset = new DefaultPieDataset(); if (model.getDataList() == null || model.getDataList().isEmpty()) { dataset.setValue("FCH", new Double(400)); dataset.setValue("FCA", new Double(1500)); dataset.setValue("FCG", new Double(204)); dataset.setValue("FCS", new Double(430)); dataset.setValue("FCJ", new Double(40)); } else { model.getDataList().forEach(data -> dataset.setValue(data.getKey(), data.getValue())); } return dataset; }
From source file:org.jfree.chart.demo.ThumbnailDemo1.java
private static PieDataset createDataset2() { DefaultPieDataset defaultpiedataset = new DefaultPieDataset(); defaultpiedataset.setValue("Java", new Double(43.200000000000003D)); defaultpiedataset.setValue("Visual Basic", new Double(10D)); defaultpiedataset.setValue("C/C++", new Double(17.5D)); defaultpiedataset.setValue("PHP", new Double(32.5D)); defaultpiedataset.setValue("Perl", null); return defaultpiedataset; }
From source file:com.exam.server.ConvertPDF.java
public static JFreeChart generatePieChart(ArrayList<DeviceDTO> input) { int shutdownCount = 0; int inspectedCount = 0; int earlyCount = 0; int uninspectedCount = 0; int duplicateCount = 0; int lateCount = 0; int unscheduledCount = 0; int downloadedCount = 0; for (DeviceDTO deviceDTO : input) { if (deviceDTO.getData1() != null && deviceDTO.getData1().equalsIgnoreCase("SHUTDOWN_EVENT")) { shutdownCount++;/*from w w w. j av a 2s . c om*/ } if (deviceDTO.getData1() != null && deviceDTO.getData1().equalsIgnoreCase("INSPECTED")) { inspectedCount++; } if (deviceDTO.getData1() != null && deviceDTO.getData1().equalsIgnoreCase("EARLY")) { earlyCount++; } if (deviceDTO.getData1() != null && deviceDTO.getData1().equalsIgnoreCase("UNINSPECTED")) { uninspectedCount++; } if (deviceDTO.getData1() != null && deviceDTO.getData1().equalsIgnoreCase("DUPLICATE")) { duplicateCount++; } if (deviceDTO.getData1() != null && deviceDTO.getData1().equalsIgnoreCase("LATE")) { lateCount++; } if (deviceDTO.getData1() != null && deviceDTO.getData1().equalsIgnoreCase("UNSCHEDULED")) { unscheduledCount++; } if (deviceDTO.getData1() != null && deviceDTO.getData1().equalsIgnoreCase("DOWNLOADED")) { downloadedCount++; } } DefaultPieDataset dataSet = new DefaultPieDataset(); dataSet.setValue("SHUTDOWN_EVENT", shutdownCount); dataSet.setValue("INSPECTED", inspectedCount); dataSet.setValue("EARLY", earlyCount); dataSet.setValue("UNINSPECTED", uninspectedCount); dataSet.setValue("DUPLICATE", duplicateCount); dataSet.setValue("LATE", lateCount); dataSet.setValue("UNSCHEDULED", unscheduledCount); dataSet.setValue("DOWNLOADED", downloadedCount); JFreeChart chart = ChartFactory.createPieChart("Device break up on basis of data1:", dataSet, true, true, false); return chart; }
From source file:grafici.FatturePieChart.java
/** * Creates a sample dataset.//from w w w .j a va 2s . c o m * * @return A sample dataset. */ private static PieDataset createDataset(int tipo) { DefaultPieDataset dataset = new DefaultPieDataset(); System.out.println("Data set"); try { for (int i = 1; i < 13; i++) { Double importo = new Double(FatturaDAO.getFatturatoMese(i)); dataset.setValue(mesi[i - 1] + ":" + importo, importo); } } catch (Exception e) { e.printStackTrace(); } return dataset; }