List of usage examples for org.jfree.data.general DefaultPieDataset setValue
public void setValue(Comparable key, double value)
From source file:com.modeln.build.ctrl.charts.CMnBuildChart.java
/** * Validate the data submitted by the user and return any error codes. * * @param req HTTP request/*from www . ja v a2s . c om*/ * @param res HTTP response * * @return Error code if any errors were found. */ public static final JFreeChart getMetricChart(CMnDbBuildData build) { JFreeChart chart = null; DefaultPieDataset pieData = new DefaultPieDataset(); if ((build.getMetrics() != null) && (build.getMetrics().size() > 0)) { Enumeration metrics = build.getMetrics().elements(); while (metrics.hasMoreElements()) { CMnDbMetricData currentMetric = (CMnDbMetricData) metrics.nextElement(); String name = currentMetric.getMetricType(currentMetric.getType()); // Get elapsed time in "minutes" Long value = new Long(currentMetric.getElapsedTime() / (1000 * 60)); pieData.setValue(name, value); } } // API: ChartFactory.createPieChart(title, data, legend, tooltips, urls) chart = ChartFactory.createPieChart("Build Metrics", pieData, true, true, false); // get a reference to the plot for further customization... PiePlot plot = (PiePlot) chart.getPlot(); chartFormatter.formatMetricChart(plot, "min"); return chart; }
From source file:org.sipfoundry.sipxconfig.site.cdr.CdrReports.java
private static Image createTerminationCallsPieImage(List<CdrGraphBean> beans) { // Create a dataset DefaultPieDataset data = new DefaultPieDataset(); // Fill dataset with beans data for (CdrGraphBean terminationCall : beans) { data.setValue(terminationCall.getKey(), terminationCall.getCount()); }/* w ww . j av a 2s . c o m*/ // Create a chart with the dataset JFreeChart chart = ChartFactory.createPieChart(EMPTY_TITLE, data, true, true, true); chart.setBackgroundPaint(Color.lightGray); chart.getTitle().setPaint(Color.BLACK); PiePlot chartplot = (PiePlot) chart.getPlot(); chartplot.setCircular(true); chartplot.setLabelGenerator(new StandardPieSectionLabelGenerator(PIECHART_SECTIONLABEL_FORMAT)); // Create and return the image return chart.createBufferedImage(500, 220, BufferedImage.TYPE_INT_RGB, null); }
From source file:weka.core.ChartUtils.java
/** * Create a pie chart from summary data (i.e. a list of values and their * corresponding frequencies).//from w w w . j a va 2s . co m * * @param values a list of values for the chart * @param freqs a list of corresponding frequencies * @param showLabels true if the chart will show labels * @param showLegend true if the chart will show a legend * @param additionalArgs optional arguments to the renderer (may be null) * @return a pie chart * @throws Exception if a problem occurs */ protected static JFreeChart getPieChartFromSummaryData(List<String> values, List<Double> freqs, boolean showLabels, boolean showLegend, List<String> additionalArgs) throws Exception { if (values.size() != freqs.size()) { throw new Exception("Number of bins should be equal to number of frequencies!"); } String plotTitle = "Pie Chart"; String userTitle = getOption(additionalArgs, "-title"); plotTitle = (userTitle != null) ? userTitle : plotTitle; String xLabel = getOption(additionalArgs, "-x-label"); xLabel = xLabel == null ? "" : xLabel; String yLabel = getOption(additionalArgs, "-y-label"); yLabel = yLabel == null ? "" : yLabel; DefaultPieDataset dataset = new DefaultPieDataset(); for (int i = 0; i < values.size(); i++) { String binLabel = values.get(i); Number freq = freqs.get(i); dataset.setValue(binLabel, freq); } JFreeChart chart = ChartFactory.createPieChart(plotTitle, // chart title dataset, // data showLegend, // include legend false, false); PiePlot plot = (PiePlot) chart.getPlot(); if (!showLabels) { plot.setLabelGenerator(null); } else { plot.setLabelFont(new Font("SansSerif", Font.PLAIN, 12)); plot.setNoDataMessage("No data available"); // plot.setCircular(false); plot.setLabelGap(0.02); } chart.setBackgroundPaint(java.awt.Color.white); chart.setTitle(new TextTitle(plotTitle, new Font("SansSerif", Font.BOLD, 12))); return chart; }
From source file:org.posterita.businesslogic.performanceanalysis.CustomPOSReportManager.java
public static PieChart generatePieChart(Properties ctx, String title, String subtitle, int account_id, Timestamp fromDate, Timestamp toDate, String salesGroup, String priceQtyFilter) throws OperationException { PieChart pieChart = new PieChart(); pieChart.setTitle(title);// w w w . j av a 2 s . c o m pieChart.setSubtitle(subtitle); String pieChartSQL = SalesAnalysisReportManager.getPieChartDataSetSQL(ctx, account_id, fromDate, toDate, salesGroup); ArrayList<Object[]> list = ReportManager.getReportData(ctx, pieChartSQL, false); DefaultPieDataset pieDataset = new DefaultPieDataset(); StandardPieSectionLabelGenerator labelGenerator = null; if (priceQtyFilter.equalsIgnoreCase(Constants.PRICE)) { //against price for (Object[] obj : list) { String name = (String) obj[0]; BigDecimal price = (BigDecimal) obj[1]; pieDataset.setValue(name, price); } String currency = POSTerminalManager.getDefaultSalesCurrency(ctx).getCurSymbol(); labelGenerator = new StandardPieSectionLabelGenerator("{0} = " + currency + "{1}"); } else { //against qty for (Object[] obj : list) { String name = (String) obj[0]; BigDecimal qty = (BigDecimal) obj[2]; pieDataset.setValue(name, qty); } labelGenerator = new StandardPieSectionLabelGenerator(); } pieChart.setDataset(pieDataset); PiePlot p = (PiePlot) pieChart.getChart().getPlot(); p.setLegendLabelGenerator(labelGenerator); pieChart.getChart().setBackgroundPaint(Color.white); return pieChart; }
From source file:org.hxzon.demo.jfreechart.PieDatasetDemo2.java
private static JFreeChart createPieChart(PieDataset dataset, PieDataset previousDataset) { final boolean greenForIncrease = true; final boolean subTitle = true; final boolean showDifference = true; int percentDiffForMaxScale = 20; PiePlot plot = new PiePlot(dataset); plot.setLabelGenerator(new StandardPieSectionLabelGenerator()); plot.setInsets(new RectangleInsets(0.0, 5.0, 5.0, 5.0)); if (tooltips) { plot.setToolTipGenerator(new StandardPieToolTipGenerator()); }/*from w w w. j a v a 2 s .co m*/ if (urls) { plot.setURLGenerator(new StandardPieURLGenerator()); } @SuppressWarnings({ "rawtypes", "unchecked" }) List<Comparable> keys = dataset.getKeys(); DefaultPieDataset series = null; if (showDifference) { series = new DefaultPieDataset(); } double colorPerPercent = 255.0 / percentDiffForMaxScale; for (@SuppressWarnings("rawtypes") Comparable key : keys) { Number newValue = dataset.getValue(key); Number oldValue = previousDataset.getValue(key); if (oldValue == null) { if (greenForIncrease) { plot.setSectionPaint(key, Color.green); } else { plot.setSectionPaint(key, Color.red); } if (showDifference) { series.setValue(key + " (+100%)", newValue); } } else { double percentChange = (newValue.doubleValue() / oldValue.doubleValue() - 1.0) * 100.0; double shade = (Math.abs(percentChange) >= percentDiffForMaxScale ? 255 : Math.abs(percentChange) * colorPerPercent); if (greenForIncrease && newValue.doubleValue() > oldValue.doubleValue() || !greenForIncrease && newValue.doubleValue() < oldValue.doubleValue()) { plot.setSectionPaint(key, new Color(0, (int) shade, 0)); } else { plot.setSectionPaint(key, new Color((int) shade, 0, 0)); } if (showDifference) { series.setValue( key + " (" + (percentChange >= 0 ? "+" : "") + NumberFormat.getPercentInstance().format(percentChange / 100.0) + ")", newValue); } } } if (showDifference) { plot.setDataset(series); } JFreeChart chart = new JFreeChart("Pie Chart Demo 2", JFreeChart.DEFAULT_TITLE_FONT, plot, legend); if (subTitle) { TextTitle subtitle = null; subtitle = new TextTitle("Bright " + (greenForIncrease ? "red" : "green") + "=change >=-" + percentDiffForMaxScale + "%, Bright " + (!greenForIncrease ? "red" : "green") + "=change >=+" + percentDiffForMaxScale + "%", new Font("SansSerif", Font.PLAIN, 10)); chart.addSubtitle(subtitle); } plot.setNoDataMessage("No data available"); return chart; }
From source file:edu.wpi.cs.wpisuitetng.modules.requirementmanager.view.requirements.NewPieChartPanel.java
/** * @return the data of iterations to be displayed by the pie chart *//*from w ww . jav a2 s.c o m*/ private static PieDataset setDataIteration() { DefaultPieDataset dataSet = new DefaultPieDataset(); List<Iteration> iterations = IterationModel.getInstance().getIterations();// list of iterations List<Requirement> requirements = RequirementModel.getInstance().getRequirements();// list of requirements int[] iterationNum = new int[iterations.size()]; for (int i = 0; i < iterations.size(); i++) { for (int j = 0; j < requirements.size(); j++) { if (requirements.get(j).getIteration().toString().equals(iterations.get(i).toString())) { iterationNum[i]++;// increments the number if the requiremet // belongs to the given iteration } } } for (int k = 0; k < iterationNum.length; k++) { dataSet.setValue(iterations.get(k).toString(), iterationNum[k]);// sets // the // data } return dataSet; }
From source file:edu.wpi.cs.wpisuitetng.modules.requirementmanager.view.requirements.NewPieChartPanel.java
/** * @return the data with the percentage of requirements with a given status * to be displayed by the pie chart *//* ww w . j a v a 2s .co m*/ private static PieDataset setDataStatus() { int numStatusNew = 0; int numStatusDeleted = 0; int numStatusInprogress = 0; int numStatusComplete = 0; int numStatusOpen = 0; DefaultPieDataset dataSet = new DefaultPieDataset(); List<Requirement> requirements = RequirementModel.getInstance().getRequirements();// list of requirements for (int i = 0; i < requirements.size(); i++) { if (requirements.get(i).getStatus() == RequirementStatus.NEW) { numStatusNew += 1; } else if (requirements.get(i).getStatus() == RequirementStatus.DELETED) { numStatusDeleted += 1; } else if (requirements.get(i).getStatus() == RequirementStatus.INPROGRESS) { numStatusInprogress += 1; } else if (requirements.get(i).getStatus() == RequirementStatus.COMPLETE) { numStatusComplete += 1; } else { numStatusOpen += 1; } } dataSet.setValue("New", numStatusNew); dataSet.setValue("Deleted", numStatusDeleted); dataSet.setValue("In Progress", numStatusInprogress); dataSet.setValue("Complete", numStatusComplete); dataSet.setValue("Open", numStatusOpen); return dataSet; }
From source file:org.jfree.chart.demo.MouseListenerDemo1.java
public MouseListenerDemo1(String s) { super(s);/*w w w .j av a2s .com*/ DefaultPieDataset defaultpiedataset = new DefaultPieDataset(); defaultpiedataset.setValue("Java", new Double(43.200000000000003D)); defaultpiedataset.setValue("Visual Basic", new Double(0.0D)); defaultpiedataset.setValue("C/C++", new Double(17.5D)); org.jfree.chart.JFreeChart jfreechart = ChartFactory.createPieChart("Pie Chart Demo 1", defaultpiedataset, true, true, false); ChartPanel chartpanel = new ChartPanel(jfreechart, false, false, false, false, false); chartpanel.addChartMouseListener(this); chartpanel.setPreferredSize(new Dimension(500, 270)); setContentPane(chartpanel); }
From source file:com.insa.tp3g1.esbsimulator.view.PieChart.java
/** * Creates a sample dataset */ //HashMap<String,Integer> values private PieDataset createDataset(int lost) { DefaultPieDataset result = new DefaultPieDataset(); result.setValue("Lost=" + lost + "%", 29); result.setValue("succecced=" + (100 - lost) + "%", 100 - lost); return result; }
From source file:WeeklyReport.Charts.java
protected JFreeChart pieChart() { DefaultPieDataset dataset = new DefaultPieDataset(); dataset.setValue("Automobile/POVs (New & Used)", new Double(new CargoTypeData().automobiles())); dataset.setValue("Construction Equipment", new Double(new CargoTypeData().construction())); dataset.setValue("Trucks, Busses, Vans, & Chassis", new Double(new CargoTypeData().trucks())); dataset.setValue("Agricultural Equipment & Tractors", new Double(new CargoTypeData().agricultural())); dataset.setValue("Boats on Trailer", new Double(new CargoTypeData().BT())); dataset.setValue("Boats on Cradle", new Double(new CargoTypeData().BC())); dataset.setValue("Static Cargo (Forklift & MAFI)", new Double(new CargoTypeData().staticCargo())); JFreeChart chart = ChartFactory.createPieChart("Quotes by Commodity Class", dataset, true, true, false); return chart; }