List of usage examples for org.jfree.chart.plot PiePlot setURLGenerator
public void setURLGenerator(PieURLGenerator generator)
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);// w ww. j a v a2 s. co m return chart; }
From source file:com.manydesigns.portofino.chart.Chart1DGenerator.java
public JFreeChart generate(ChartDefinition chartDefinition, Persistence persistence, Locale locale) { DefaultPieDataset dataset = new DefaultPieDataset(); java.util.List<Object[]> result; String query = chartDefinition.getQuery(); logger.info(query);/*from w w w . j a va2s . c o m*/ Session session = persistence.getSession(chartDefinition.getDatabase()); result = QueryUtils.runSql(session, query); for (Object[] current : result) { ComparableWrapper key = new ComparableWrapper((Comparable) current[0]); dataset.setValue(key, (Number) current[1]); if (current.length > 2) { key.setLabel(current[2].toString()); } } JFreeChart chart = createChart(chartDefinition, dataset); chart.setAntiAlias(isAntiAlias()); // impostiamo il bordo invisibile // eventualmente e' il css a fornirne uno // eventualmente e' il css a fornirne uno chart.setBorderVisible(isBorderVisible()); // impostiamo il titolo TextTitle title = chart.getTitle(); title.setFont(titleFont); title.setMargin(10.0, 0.0, 0.0, 0.0); // ottieni il Plot PiePlot plot = (PiePlot) chart.getPlot(); String urlExpression = chartDefinition.getUrlExpression(); if (!StringUtils.isBlank(urlExpression)) { PieURLGenerator urlGenerator = new ChartPieUrlGenerator(urlExpression); plot.setURLGenerator(urlGenerator); } else { plot.setURLGenerator(null); } // il plot ha sfondo e bordo trasparente // (quindi si vede il colore del chart) plot.setBackgroundPaint(transparentColor); plot.setOutlinePaint(transparentColor); // Modifico il toolTip // hongliangpan add // :?{0} {1} {2} ? ,??? plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0}={1}({2})", NumberFormat.getNumberInstance(), new DecimalFormat("0.00%"))); // {0}={1}({2}) plot.setLegendLabelGenerator(new StandardPieSectionLabelGenerator("{0}")); // ?(0.0-1.0) // plot.setForegroundAlpha(1.0f); // imposta la distanza delle etichette dal plot plot.setLabelGap(0.03); // plot.setLabelGenerator(new MyPieSectionLabelGenerator()); // imposta il messaggio se non ci sono dati plot.setNoDataMessage(ElementsThreadLocals.getText("no.data.available")); plot.setCircular(true); plot.setBaseSectionOutlinePaint(Color.BLACK); DrawingSupplier supplier = new DesaturatedDrawingSupplier(plot.getDrawingSupplier()); plot.setDrawingSupplier(supplier); // ? plot.setForegroundAlpha(1.0f); // impostiamo il titolo della legenda String legendString = chartDefinition.getLegend(); Title subtitle = new TextTitle(legendString, legendFont, Color.BLACK, RectangleEdge.BOTTOM, HorizontalAlignment.CENTER, VerticalAlignment.CENTER, new RectangleInsets(0, 0, 0, 0)); subtitle.setMargin(0, 0, 5, 0); chart.addSubtitle(subtitle); // impostiamo la legenda LegendTitle legend = chart.getLegend(); legend.setBorder(0, 0, 0, 0); legend.setItemFont(legendItemFont); int legendMargin = 10; legend.setMargin(0.0, legendMargin, legendMargin, legendMargin); legend.setBackgroundPaint(transparentColor); // impostiamo un gradiente orizzontale Paint chartBgPaint = new GradientPaint(0, 0, new Color(255, 253, 240), 0, getHeight(), Color.WHITE); chart.setBackgroundPaint(chartBgPaint); return chart; }
From source file:org.pentaho.plugin.jfreereport.reportcharts.MultiPieChartExpression.java
protected void configureChart(final JFreeChart chart) { super.configureChart(chart); final Plot plot = chart.getPlot(); final MultiplePiePlot mpp = (MultiplePiePlot) plot; final JFreeChart pc = mpp.getPieChart(); configureSubChart(pc);//from w w w.j a va 2s .c om final PiePlot pp = (PiePlot) pc.getPlot(); if (StringUtils.isEmpty(getTooltipFormula()) == false) { pp.setToolTipGenerator(new FormulaPieTooltipGenerator(getRuntime(), getTooltipFormula())); } if (StringUtils.isEmpty(getUrlFormula()) == false) { pp.setURLGenerator(new FormulaPieURLGenerator(getRuntime(), getUrlFormula())); } if (shadowPaint != null) { pp.setShadowPaint(shadowPaint); } if (shadowXOffset != null) { pp.setShadowXOffset(shadowXOffset.doubleValue()); } if (shadowYOffset != null) { pp.setShadowYOffset(shadowYOffset.doubleValue()); } final CategoryDataset c = mpp.getDataset(); if (c != null) { final String[] colors = getSeriesColor(); final int keysSize = c.getColumnKeys().size(); for (int i = 0; i < colors.length; i++) { if (keysSize > i) { pp.setSectionPaint(c.getColumnKey(i), parseColorFromString(colors[i])); } } } if (StringUtils.isEmpty(getLabelFont()) == false) { pp.setLabelFont(Font.decode(getLabelFont())); } if (Boolean.FALSE.equals(getItemsLabelVisible())) { pp.setLabelGenerator(null); } else { final ExpressionRuntime runtime = getRuntime(); final Locale locale = runtime.getResourceBundleFactory().getLocale(); final FastDecimalFormat fastPercent = new FastDecimalFormat(FastDecimalFormat.TYPE_PERCENT, locale); final FastDecimalFormat fastInteger = new FastDecimalFormat(FastDecimalFormat.TYPE_INTEGER, locale); final DecimalFormat numFormat = new DecimalFormat(fastInteger.getPattern(), new DecimalFormatSymbols(locale)); numFormat.setRoundingMode(RoundingMode.HALF_UP); final DecimalFormat percentFormat = new DecimalFormat(fastPercent.getPattern(), new DecimalFormatSymbols(locale)); percentFormat.setRoundingMode(RoundingMode.HALF_UP); final StandardPieSectionLabelGenerator labelGen = new StandardPieSectionLabelGenerator( multipieLabelFormat, numFormat, percentFormat); pp.setLabelGenerator(labelGen); } }
From source file:com.sixrr.metrics.ui.charts.PieChartDialog.java
private JFreeChart createChart(PieDataset dataset) { final String title = getTitle(); final PiePlot plot = new PiePlot(dataset); plot.setInsets(new Insets(0, 5, 5, 5)); final int numItems = dataset.getItemCount(); int total = 0; for (int i = 0; i < numItems; i++) { final Number value = dataset.getValue(i); total += value.intValue();//from w w w. ja va2s .co m } final PieItemLabelGenerator tooltipGenerator = new PieChartTooltipGenerator(total); plot.setItemLabelGenerator(tooltipGenerator); plot.setURLGenerator(null); return new JFreeChart(title, JFreeChartConstants.DEFAULT_TITLE_FONT, plot, false); }
From source file:org.openfaces.component.chart.impl.plots.PiePlot3DAdapter.java
private void setupTooltipsAndUrls(PiePlot plot, final PieChartView chartView) { if (chartView.getTooltip() != null) { plot.setToolTipGenerator(new PieToolTipGenerator() { public String generateToolTip(PieDataset pieDataset, Comparable comparable) { return chartView.getTooltip(); }//w w w .j a va 2s . c om }); } else if (chartView.getDynamicTooltip() != null) { plot.setToolTipGenerator(new DynamicPieGenerator(chartView, chartView.getDynamicTooltip())); } if (chartView.getUrl() != null) { plot.setURLGenerator(new PieURLGenerator() { public String generateURL(PieDataset pieDataset, Comparable comparable, int i) { return chartView.getUrl(); } }); } else if (chartView.getDynamicUrl() != null) { plot.setURLGenerator(new DynamicPieGenerator(chartView, chartView.getDynamicUrl())); } }
From source file:org.pentaho.plugin.jfreereport.reportcharts.PieChartExpression.java
protected void configureChart(final JFreeChart chart) { super.configureChart(chart); final Plot plot = chart.getPlot(); final PiePlot pp = (PiePlot) plot; final PieDataset pieDS = pp.getDataset(); pp.setDirection(rotationClockwise ? Rotation.CLOCKWISE : Rotation.ANTICLOCKWISE); if ((explodeSegment != null) && (explodePct != null)) { configureExplode(pp);//from w w w. j a v a 2 s . com } if (StringUtils.isEmpty(getTooltipFormula()) == false) { pp.setToolTipGenerator(new FormulaPieTooltipGenerator(getRuntime(), getTooltipFormula())); } if (StringUtils.isEmpty(getUrlFormula()) == false) { pp.setURLGenerator(new FormulaPieURLGenerator(getRuntime(), getUrlFormula())); } pp.setIgnoreNullValues(ignoreNulls); pp.setIgnoreZeroValues(ignoreZeros); if (Boolean.FALSE.equals(getItemsLabelVisible())) { pp.setLabelGenerator(null); } else { final ExpressionRuntime runtime = getRuntime(); final Locale locale = runtime.getResourceBundleFactory().getLocale(); final FastDecimalFormat fastPercent = new FastDecimalFormat(FastDecimalFormat.TYPE_PERCENT, locale); final FastDecimalFormat fastInteger = new FastDecimalFormat(FastDecimalFormat.TYPE_INTEGER, locale); final DecimalFormat numFormat = new DecimalFormat(fastInteger.getPattern(), new DecimalFormatSymbols(locale)); numFormat.setRoundingMode(RoundingMode.HALF_UP); final DecimalFormat percentFormat = new DecimalFormat(fastPercent.getPattern(), new DecimalFormatSymbols(locale)); percentFormat.setRoundingMode(RoundingMode.HALF_UP); final StandardPieSectionLabelGenerator labelGen = new StandardPieSectionLabelGenerator(pieLabelFormat, numFormat, percentFormat); pp.setLabelGenerator(labelGen); final StandardPieSectionLabelGenerator legendGen = new StandardPieSectionLabelGenerator( pieLegendLabelFormat, numFormat, percentFormat); pp.setLegendLabelGenerator(legendGen); } if (StringUtils.isEmpty(getLabelFont()) == false) { pp.setLabelFont(Font.decode(getLabelFont())); } if (pieDS != null) { final String[] colors = getSeriesColor(); for (int i = 0; i < colors.length; i++) { if (i < pieDS.getItemCount()) { pp.setSectionPaint(pieDS.getKey(i), parseColorFromString(colors[i])); } else { break; } } } if (shadowPaint != null) { pp.setShadowPaint(shadowPaint); } if (shadowXOffset != null) { pp.setShadowXOffset(shadowXOffset.doubleValue()); } if (shadowYOffset != null) { pp.setShadowYOffset(shadowYOffset.doubleValue()); } pp.setCircular(circular); if (isShowBorder() == false || isChartSectionOutline() == false) { chart.setBorderVisible(false); chart.getPlot().setOutlineVisible(false); } }
From source file:com.qspin.qtaste.reporter.testresults.html.HTMLReportFormatter.java
private void generatePieChart() { if (currentTestSuite == null) { return;/*from w ww. j a v a 2 s. c om*/ } File testSummaryFile = new File(reportFile.getParentFile(), testSummaryFileName); File tempTestSummaryFile = new File(testSummaryFile.getPath() + ".tmp"); final DefaultPieDataset pieDataSet = new DefaultPieDataset(); pieDataSet.setValue("Passed", new Integer(currentTestSuite.getNbTestsPassed())); pieDataSet.setValue("Failed", new Integer(currentTestSuite.getNbTestsFailed())); pieDataSet.setValue("Tests in error", new Integer(currentTestSuite.getNbTestsNotAvailable())); pieDataSet.setValue("Not executed", new Integer(currentTestSuite.getNbTestsToExecute() - currentTestSuite.getNbTestsExecuted())); JFreeChart chart = null; final boolean drilldown = true; // create the chart... if (drilldown) { final PiePlot plot = new PiePlot(pieDataSet); Color[] colors = { new Color(100, 230, 40), new Color(210, 35, 35), new Color(230, 210, 40), new Color(100, 90, 40) }; PieRenderer renderer = new PieRenderer(colors); renderer.setColor(plot, (DefaultPieDataset) pieDataSet); plot.setURLGenerator(new StandardPieURLGenerator("pie_chart_detail.jsp")); plot.setLabelGenerator(new TestSectiontLabelPieGenerator()); chart = new JFreeChart("Test summary", JFreeChart.DEFAULT_TITLE_FONT, plot, true); } else { chart = ChartFactory.createPieChart("Test summary", // chart title pieDataSet, // data true, // include legend true, false); } chart.setBackgroundPaint(java.awt.Color.white); try { final ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection()); ChartUtilities.saveChartAsPNG(tempTestSummaryFile, chart, 600, 400, info); } catch (IOException e) { logger.error("Problem saving png chart", e); } testSummaryFile.delete(); if (!tempTestSummaryFile.renameTo(testSummaryFile)) { logger.error("Couldn't rename test summary file " + tempTestSummaryFile + " into " + testSummaryFile); } }
From source file:edu.dlnu.liuwenpeng.ChartFactory.ChartFactory.java
/** * Creates a chart that displays multiple pie plots. The chart object * returned by this method uses a {@link MultiplePiePlot} instance as the * plot. /*from w w w . j a v a2 s. c o m*/ * * @param title the chart title (<code>null</code> permitted). * @param dataset the dataset (<code>null</code> permitted). * @param order the order that the data is extracted (by row or by column) * (<code>null</code> not permitted). * @param legend include a legend? * @param tooltips generate tooltips? * @param urls generate URLs? * * @return A chart. */ public static JFreeChart createMultiplePieChart(String title, CategoryDataset dataset, TableOrder order, boolean legend, boolean tooltips, boolean urls) { if (order == null) { throw new IllegalArgumentException("Null 'order' argument."); } MultiplePiePlot plot = new MultiplePiePlot(dataset); plot.setDataExtractOrder(order); plot.setBackgroundPaint(null); plot.setOutlineStroke(null); if (tooltips) { PieToolTipGenerator tooltipGenerator = new StandardPieToolTipGenerator(); PiePlot pp = (PiePlot) plot.getPieChart().getPlot(); pp.setToolTipGenerator(tooltipGenerator); } if (urls) { PieURLGenerator urlGenerator = new StandardPieURLGenerator(); PiePlot pp = (PiePlot) plot.getPieChart().getPlot(); pp.setURLGenerator(urlGenerator); } JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend); return chart; }
From source file:edu.dlnu.liuwenpeng.ChartFactory.ChartFactory.java
/** * Creates a chart that displays multiple pie plots. The chart object * returned by this method uses a {@link MultiplePiePlot} instance as the * plot. //from ww w . ja v a 2 s.co m * * @param title the chart title (<code>null</code> permitted). * @param dataset the dataset (<code>null</code> permitted). * @param order the order that the data is extracted (by row or by column) * (<code>null</code> not permitted). * @param legend include a legend? * @param tooltips generate tooltips? * @param urls generate URLs? * * @return A chart. */ public static JFreeChart createMultiplePieChart3D(String title, CategoryDataset dataset, TableOrder order, boolean legend, boolean tooltips, boolean urls) { if (order == null) { throw new IllegalArgumentException("Null 'order' argument."); } MultiplePiePlot plot = new MultiplePiePlot(dataset); plot.setDataExtractOrder(order); plot.setBackgroundPaint(null); plot.setOutlineStroke(null); JFreeChart pieChart = new JFreeChart(new PiePlot3D(null)); TextTitle seriesTitle = new TextTitle("Series Title", new Font("SansSerif", Font.BOLD, 12)); seriesTitle.setPosition(RectangleEdge.BOTTOM); pieChart.setTitle(seriesTitle); pieChart.removeLegend(); pieChart.setBackgroundPaint(null); plot.setPieChart(pieChart); if (tooltips) { PieToolTipGenerator tooltipGenerator = new StandardPieToolTipGenerator(); PiePlot pp = (PiePlot) plot.getPieChart().getPlot(); pp.setToolTipGenerator(tooltipGenerator); } if (urls) { PieURLGenerator urlGenerator = new StandardPieURLGenerator(); PiePlot pp = (PiePlot) plot.getPieChart().getPlot(); pp.setURLGenerator(urlGenerator); } JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend); return chart; }
From source file:edu.dlnu.liuwenpeng.ChartFactory.ChartFactory.java
/** * Creates a pie chart with default settings. * <P> // w w w . j a v a 2s .c o m * The chart object returned by this method uses a {@link PiePlot} instance * as the plot. * * @param title the chart title (<code>null</code> permitted). * @param dataset the dataset for the chart (<code>null</code> permitted). * @param legend a flag specifying whether or not a legend is required. * @param tooltips configure chart to generate tool tips? * @param urls configure chart to generate URLs? * * @return A pie chart. */ public static JFreeChart createPieChart(String title, PieDataset dataset, boolean legend, boolean tooltips, boolean urls) { 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()); } if (urls) { plot.setURLGenerator(new StandardPieURLGenerator()); } return new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend); }