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:net.footballpredictions.footballstats.swing.ResultsPieChart.java
/** * Updates the relative sizes of the pie chart segments. *///w w w . j a v a 2 s .c om public void updateGraph(int won, int drawn, int lost) { DefaultKeyedValues values = new DefaultKeyedValues(); values.addValue(messageResources.getString("headToHead.won"), won); values.addValue(messageResources.getString("headToHead.drawn"), drawn); values.addValue(messageResources.getString("headToHead.lost"), lost); PieDataset dataSet = new DefaultPieDataset(values); JFreeChart chart = ChartFactory.createPieChart(title, dataSet, false, // Legend. true, // Tooltips. false); // URLs. PiePlot plot = (PiePlot) chart.getPlot(); plot.setInteriorGap(0); plot.setSectionPaint(0, Colours.WIN); plot.setSectionPaint(1, Colours.DRAW); plot.setSectionPaint(2, Colours.DEFEAT); plot.setBackgroundPaint(null); plot.setOutlinePaint(null); plot.setLabelGenerator(null); plot.setToolTipGenerator(new StandardPieToolTipGenerator("{0} {1} ({2})")); setChart(chart); }
From source file:org.operamasks.faces.render.graph.PieChartRenderer.java
protected JFreeChart createChart(UIChart comp) { Dataset dataset = createDataset(comp); JFreeChart chart = null;//from ww w . j a v a 2 s . c o m PiePlot pieplot = null; boolean ring = Coercion.coerceToBoolean(comp.getAttributes().get("ring")); if (dataset instanceof CategoryDataset) { CategoryDataset catset = (CategoryDataset) dataset; if (catset.getRowCount() == 1) { PieDataset pieset = new CategoryToPieDataset(catset, TableOrder.BY_ROW, 0); if (ring) { chart = ChartFactory.createRingChart(null, pieset, false, false, false); } else if (comp.isEffect3D()) { chart = ChartFactory.createPieChart3D(null, pieset, false, false, false); } else { chart = ChartFactory.createPieChart(null, pieset, false, false, false); } pieplot = (PiePlot) chart.getPlot(); } else { if (comp.isEffect3D()) { chart = ChartFactory.createMultiplePieChart3D(null, catset, TableOrder.BY_ROW, false, false, false); } else { chart = ChartFactory.createMultiplePieChart(null, catset, TableOrder.BY_ROW, false, false, false); } pieplot = (PiePlot) ((MultiplePiePlot) chart.getPlot()).getPieChart().getPlot(); } } if (pieplot != null) { if (!comp.isDrawItemLabel()) { pieplot.setLabelGenerator(null); } if (comp.isShowItemTips()) { pieplot.setToolTipGenerator(new StandardPieToolTipGenerator()); } Object startAngle = comp.getAttributes().get("startAngle"); if (startAngle != null) { pieplot.setStartAngle(Coercion.coerceToDouble(startAngle)); } } return chart; }
From source file:org.openmrs.module.vcttrac.web.view.chart.VCTVersusPITChartView.java
@Override protected JFreeChart createChart(Map<String, Object> model, HttpServletRequest request) { DefaultPieDataset pieDataset = new DefaultPieDataset(); VCTModuleService service = Context.getService(VCTModuleService.class); try {//from w w w .j a va2s .co m Date reportingDate = new Date(); int numberOfClientInVCT = service.getNumberOfClientByVCTOrPIT(1, reportingDate); int numberOfClientInPIT = service.getNumberOfClientByVCTOrPIT(2, reportingDate); int all = numberOfClientInVCT + numberOfClientInPIT; Float percentageVCT = new Float(100 * numberOfClientInVCT / all); pieDataset.setValue(VCTTracUtil.getMessage("vcttrac.home.vctclient", null) + " (" + numberOfClientInVCT + " , " + percentageVCT + "%)", percentageVCT); Float percentagePIT = new Float(100 * numberOfClientInPIT / all); pieDataset.setValue(VCTTracUtil.getMessage("vcttrac.home.pitclient", null) + " (" + numberOfClientInPIT + " , " + percentagePIT + "%)", percentagePIT); JFreeChart chart = ChartFactory.createPieChart( VCTTracUtil.getMessage("vcttrac.home.vctclient", null) + " " + VCTTracUtil.getMessage("vcttrac.graph.statistic.comparedto", null) + " " + VCTTracUtil.getMessage("vcttrac.home.pitclient", null), pieDataset, true, true, false); return chart; } catch (Exception e) { log.error(">>VCT>>vs>>PIT>>PIE>>CHART>> " + e.getMessage()); e.printStackTrace(); return null; } }
From source file:org.jfree.chart.demo.PieChartDemo3.java
/** * Default constructor./*from w w w . j av a2 s .c om*/ * * @param title the frame title. */ public PieChartDemo3(final String title) { super(title); // create a dataset... final DefaultPieDataset data = new DefaultPieDataset(); // create the chart... final JFreeChart chart = ChartFactory.createPieChart("Pie Chart Demo 3", // chart title data, // data true, // include legend true, false); final PiePlot plot = (PiePlot) chart.getPlot(); plot.setNoDataMessage("No data available"); plot.setNoDataMessageFont(new Font("Serif", Font.ITALIC, 10)); plot.setNoDataMessagePaint(Color.red); // add the chart to a panel... final ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new java.awt.Dimension(500, 270)); setContentPane(chartPanel); }
From source file:fitmon.PieChart.java
/** * Creates a chart./*ww w. j av a 2 s .co m*/ * * @param dataset the dataset. * * @return A chart. */ public static JFreeChart createChart(PieDataset dataset) { JFreeChart chart = ChartFactory.createPieChart("Food Stat of the Week", // chart title dataset, // data true, // include legend true, false); 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:net.sourceforge.processdash.ui.web.reports.PieChart.java
/** Create a line chart. */ @Override//from w w w . j a v a2s.co m public JFreeChart createChart() { CategoryDataset catData = data.catDataSource(); PieDataset pieData = null; if (catData.getColumnCount() == 1) pieData = DatasetUtilities.createPieDatasetForColumn(catData, 0); else pieData = DatasetUtilities.createPieDatasetForRow(catData, 0); JFreeChart chart = null; if (get3DSetting()) { chart = ChartFactory.createPieChart3D(null, pieData, true, true, false); chart.getPlot().setForegroundAlpha(ALPHA); } else { chart = ChartFactory.createPieChart(null, pieData, true, true, false); } PiePlot plot = (PiePlot) chart.getPlot(); if (parameters.get("skipItemLabels") != null || parameters.get("skipWedgeLabels") != null) plot.setLabelGenerator(null); else if (parameters.get("wedgeLabelFontSize") != null) try { float fontSize = Float.parseFloat((String) parameters.get("wedgeLabelFontSize")); plot.setLabelFont(plot.getLabelFont().deriveFont(fontSize)); } catch (Exception lfe) { } if (parameters.get("ellipse") != null) plot.setCircular(true); else plot.setCircular(false); Object colorScheme = parameters.get("colorScheme"); if ("byPhase".equals(colorScheme)) maybeConfigurePhaseColors(plot, pieData); else if ("consistent".equals(colorScheme)) // since 2.0.9 configureConsistentColors(plot, pieData); else if (parameters.containsKey("c1")) configureIndividualColors(plot, pieData); String interiorGap = (String) parameters.get("interiorGap"); if (interiorGap != null) try { plot.setInteriorGap(Integer.parseInt(interiorGap) / 100.0); } catch (NumberFormatException e) { } String interiorSpacing = (String) parameters.get("interiorSpacing"); if (interiorSpacing != null) try { plot.setInteriorGap(Integer.parseInt(interiorSpacing) / 200.0); } catch (NumberFormatException e) { } if (!parameters.containsKey("showZeroValues")) { plot.setIgnoreZeroValues(true); plot.setIgnoreNullValues(true); } return chart; }
From source file:uk.ac.lkl.cram.ui.chart.TLALearningTypeChartFactory.java
private static JFreeChart createChart(PieDataset dataset) { //Create a pie chart from the chart factory with no title, a legend and no tooltips JFreeChart chart = ChartFactory.createPieChart(null, dataset, true, false, false); //Set the background colour of the chart Paint backgroundPaint = Color.white; chart.setBackgroundPaint(backgroundPaint); //Get the plot from the chart PiePlot plot = (PiePlot) chart.getPlot(); //Set the background colour of the plot to be the same as the chart plot.setBackgroundPaint(backgroundPaint); //Remove shadows from the plot plot.setShadowXOffset(0);/*from ww w . j ava 2s .c o m*/ plot.setShadowYOffset(0); //Remove the outline from the plot plot.setOutlineVisible(false); //Remove the labels from the plot plot.setLabelGenerator(null); //Set the colours for the segments plot.setSectionPaint(LearningTypeChartMaker.ACQUISITION, LearningTypeChartMaker.ACQUISITION_COLOR); plot.setSectionPaint(LearningTypeChartMaker.COLLABORATION, LearningTypeChartMaker.COLLABORATION_COLOR); plot.setSectionPaint(LearningTypeChartMaker.DISCUSSION, LearningTypeChartMaker.DISCUSSION_COLOR); plot.setSectionPaint(LearningTypeChartMaker.INQUIRY, LearningTypeChartMaker.INQUIRY_COLOR); plot.setSectionPaint(LearningTypeChartMaker.PRACTICE, LearningTypeChartMaker.PRACTICE_COLOR); plot.setSectionPaint(LearningTypeChartMaker.PRODUCTION, LearningTypeChartMaker.PRODUCTION_COLOR); //Get the legend from the chart LegendTitle legend = chart.getLegend(); //Set the font of the legend to be the same as the platform UI legend.setItemFont(UIManager.getFont("Label.font")); //Set the background colour of the legend to be the same as the chart legend.setBackgroundPaint(backgroundPaint); //Remove the border from the legend legend.setFrame(BlockBorder.NONE); //Locate the legend to the right of the plot legend.setPosition(RectangleEdge.RIGHT); return chart; }
From source file:msi.gama.outputs.layers.charts.ChartJFreeChartOutputPie.java
@Override public void createChart(final IScope scope) { super.createChart(scope); if (style.equals(IKeyword.THREE_D)) { chart = ChartFactory.createPieChart3D(getName(), null, false, true, false); } else if (style.equals(IKeyword.RING)) { chart = ChartFactory.createRingChart(getName(), null, false, true, false); } else if (style.equals(IKeyword.EXPLODED)) { chart = ChartFactory.createPieChart(getName(), null, false, true, false); } else {// w w w . ja va2 s. c om chart = ChartFactory.createPieChart(getName(), null, false, true, false); } }
From source file:uom.research.thalassemia.util.PieChartCreator.java
/** * Creates a chart.//from w w w.ja v a 2s.co m * * @param dataset the dataset. * * @return A chart. */ private JFreeChart createChart(PieDataset dataset) { JFreeChart chart = ChartFactory.createPieChart(title, // chart title dataset, // data true, // no legend true, // tooltips false // no URL generation ); // set a custom background for the chart chart.setBackgroundPaint( new GradientPaint(new Point(0, 0), new Color(20, 20, 20), new Point(400, 200), Color.DARK_GRAY)); // customise the title position and font TextTitle t = chart.getTitle(); t.setHorizontalAlignment(HorizontalAlignment.LEFT); t.setPaint(new Color(240, 240, 240)); t.setFont(new Font("Arial", Font.BOLD, 26)); PiePlot plot = (PiePlot) chart.getPlot(); plot.setBackgroundPaint(null); plot.setInteriorGap(0.04); plot.setOutlineVisible(false); // use gradients and white borders for the section colours int itemIndex = 0; for (Object col : pieDataset.getKeys()) { plot.setSectionPaint(col.toString(), gradientPaints[itemIndex]); if (itemIndex == pieDataset.getItemCount() - 1) { itemIndex = 0; } itemIndex++; } plot.setBaseSectionOutlinePaint(Color.WHITE); plot.setSectionOutlinesVisible(true); plot.setBaseSectionOutlineStroke(new BasicStroke(2.0f)); // customise the section label appearance plot.setLabelFont(new Font("Courier New", Font.BOLD, 20)); plot.setLabelLinkPaint(Color.WHITE); plot.setLabelLinkStroke(new BasicStroke(2.0f)); plot.setLabelOutlineStroke(null); plot.setLabelPaint(Color.WHITE); plot.setLabelBackgroundPaint(null); // add a subtitle giving the data source TextTitle source = new TextTitle("Source: http://www.bbc.co.uk/news/business-15489523", new Font("Courier New", Font.PLAIN, 12)); source.setPaint(Color.WHITE); source.setPosition(RectangleEdge.BOTTOM); source.setHorizontalAlignment(HorizontalAlignment.RIGHT); chart.addSubtitle(source); return chart; }
From source file:com.polivoto.logica.RecibirVotos.java
public void actualizarConteo(int personasQueHanVotado) { /*//w w w. ja v a 2 s .c o m * Porcentaje */ if (votos >= poblacion) poblacion = votos = personasQueHanVotado; else votos = personasQueHanVotado; lblvotos_totales.setText(String.valueOf(personasQueHanVotado)); porcentaje = (votos * 100) / (poblacion == 0 ? 1 : poblacion); if (porcentaje >= 100.0 || (porcentaje % 1) == 0) decimales = new DecimalFormat("0"); else decimales = new DecimalFormat("0.00"); lblporcentaje.setText("" + decimales.format(porcentaje) + "%"); // Fuente de Datos data = new DefaultPieDataset(); data.setValue("SI", votos); data.setValue("NO", poblacion - votos); // Creando el Grafico chart = ChartFactory.createPieChart("", data, false, false, false); chart.setBackgroundPaint(Color.white); plot = (PiePlot) chart.getPlot(); plot.setBackgroundPaint(Color.white); plot.setLabelGenerator(null); plot.setOutlineVisible(false); plot.setSectionPaint("SI", new Color(0, 204, 0)); plot.setSectionPaint("NO", new Color(218, 24, 24)); // Crear el Panel del Grafico con ChartPanel chartPanel = new ChartPanel(chart, 161, 131, 161, 131, 161, 131, false, false, false, false, false, false); chartPanel.setEnabled(false); pnlgrafica.setLayout(new java.awt.BorderLayout()); pnlgrafica.removeAll(); pnlgrafica.add(chartPanel, BorderLayout.CENTER); pnlgrafica.validate(); }