List of usage examples for org.jfree.chart.plot PiePlot setBackgroundPaint
public void setBackgroundPaint(Paint paint)
From source file:fr.inria.soctrace.framesoc.ui.piechart.view.StatisticsPieChartView.java
/** * Creates the chart.//from w w w . j a va 2 s. c o m * * @param dataset * the dataset. * @param loader * the pie chart loader * @param dataRequested * flag indicating if the data have been requested for the current loader and the * current interval * @return the pie chart */ private JFreeChart createChart(PieDataset dataset, String title, IPieChartLoader loader, boolean dataRequested) { JFreeChart chart = ChartFactory.createPieChart(title, dataset, HAS_LEGEND, HAS_TOOLTIPS, HAS_URLS); // legend if (HAS_LEGEND) { LegendTitle legend = chart.getLegend(); legend.setPosition(RectangleEdge.LEFT); } // plot PiePlot plot = (PiePlot) chart.getPlot(); plot.setSectionOutlinesVisible(false); plot.setLabelFont(new Font("SansSerif", Font.PLAIN, 12)); plot.setNoDataMessage( "No data available " + (dataRequested ? "in this time interval" : "yet. Press the Load button.")); plot.setCircular(true); plot.setLabelGenerator(null); // hide labels plot.setBackgroundPaint(Color.WHITE); plot.setOutlineVisible(false); plot.setShadowPaint(Color.WHITE); plot.setBaseSectionPaint(Color.WHITE); StandardPieToolTipGenerator g = (StandardPieToolTipGenerator) plot.getToolTipGenerator(); NumberFormat format = ValueLabelProvider.getActualFormat(loader.getFormat(), getTimeUnit()); StandardPieToolTipGenerator sg = new StandardPieToolTipGenerator(g.getLabelFormat(), format, g.getPercentFormat()); plot.setToolTipGenerator(sg); for (Object o : dataset.getKeys()) { String key = (String) o; plot.setSectionPaint(key, loader.getColor(key).getAwtColor()); } return chart; }
From source file:kolacer.Kolacer.java
private void upravPlot(PiePlot plot) { plot.setSectionOutlinesVisible(false); plot.setOutlinePaint(null);//from w ww . j a va 2s . com if (jRad_barvy_manual.isSelected()) { for (Udaj u : udaje) { plot.setSectionPaint(u.hodnota, u.barva); } } else if (jRad_barvy_auto.isSelected()) { Barvy.nastavBarvy(plot); } else if (jRad_barvy_gradient.isSelected()) { Barvy.nastavBarvy(plot, barvaGradA, barvaGradB); } if (!jCHB_popisky.isSelected()) plot.setLabelGenerator(null); else { plot.setLabelBackgroundPaint(new Color(0, 0, 0, 0)); plot.setLabelOutlinePaint(null); plot.setLabelShadowPaint(null); plot.setSimpleLabels(true); plot.setInsets(new RectangleInsets(5, 5, 5, 400)); plot.setLabelFont(popisekGrafuFont); //plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{1} hl. ({2})")); plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{1}")); } plot.setBackgroundPaint(null); plot.setShadowPaint(null); plot.setLegendLabelGenerator(new StandardPieSectionLabelGenerator("{1} ({2}) - {0}")); }
From source file:de.tor.tribes.ui.panels.MinimapPanel.java
private void renderChartInfo() { HashMap<Object, Marker> marks = new HashMap<>(); DefaultPieDataset dataset = buildDataset(marks); JFreeChart chart = ChartFactory.createPieChart(null, // chart title dataset, // data true, // include legend true, false);/*from w ww . ja v a 2 s .c o m*/ chart.setBackgroundPaint(null); //chart.setBorderStroke(null); chart.setBorderVisible(false); final PiePlot plot = (PiePlot) chart.getPlot(); // plot.setBackgroundPaint(null); // plot.setShadowPaint(null); for (Object o : marks.keySet()) { if (iCurrentView == ID_ALLY_CHART) { Ally a = (Ally) o; plot.setSectionPaint(a.getTag(), marks.get(a).getMarkerColor()); } else { Tribe t = (Tribe) o; plot.setSectionPaint(t.getName(), marks.get(t).getMarkerColor()); } } //plot.setCircular(true); // plot.setMaximumLabelWidth(30.0); /* * plot.setLabelGenerator(new StandardPieSectionLabelGenerator( "{0} = {2}", NumberFormat.getNumberInstance(), * NumberFormat.getPercentInstance())); */ // chart.getLegend().setVerticalAlignment(VerticalAlignment.CENTER); // chart.getLegend().setPosition(RectangleEdge.RIGHT); // plot.setMaximumLabelWidth(20.0); plot.setLabelGenerator(null); plot.setBackgroundPaint(Constants.DS_BACK); /* * plot.setInteriorGap(0.0); plot.setLabelGap(0.0); */ plot.setLegendLabelGenerator(new StandardPieSectionLabelGenerator("{0} = {2}", NumberFormat.getNumberInstance(), NumberFormat.getPercentInstance())); /* * plot.getL plot.setLabelFont(g2d.getFont().deriveFont(10.0f)); */ //plot.setLabelGenerator(null); //plot.setMaximumLabelWidth(30.0); //plot.getLabelDistributor().distributeLabels(10.0, 20.0); //chart.draw(g2d, new Rectangle2D.Float(20, 20, 100, 100)); // g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha)); plot.setOutlineVisible(false); mChartImage = chart.createBufferedImage(getWidth(), getHeight()); //chart.draw(g2d, new Rectangle2D.Float(50, 50, 400, 400)); //g2d.drawImage(bi, 30, 30, null); // g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha)); //bi = chart.createBufferedImage(240, 240); // g2d.drawImage(bi, 30, 30, null); }
From source file:com.appnativa.rare.ui.chart.jfreechart.ChartHandler.java
private void customizePiePlot(ChartDefinition cd, PiePlot plot, PieCollection pie) { PlotInformation pi = cd.getPlotInformation(); plot.setBackgroundPaint(null); plot.setOutlineVisible(false);/*from w ww . j ava2s . c o m*/ customizeBasicPlot(plot, pi); List<RenderableDataItem> rows = cd.getSeries(); int len = (rows == null) ? 0 : rows.size(); ChartDataItem di; iComponentPainter bp; Paint p = null; if (len > 0) { rows = rows.get(0).getItems(); len = rows.size(); } for (int i = 0; i < len; i++) { di = (ChartDataItem) rows.get(i); bp = di.getComponentPainter(); iPlatformPaint pp; if (bp == null) { p = di.getBackground(); } else if (bp.getBackgroundPainter() != null) { pp = bp.getBackgroundPainter().getPaint(100, 100); p = (pp == null) ? null : pp.getPaint(); } if (p == null) { p = getDefaultColor(i); } plot.setSectionPaint(di.getDomainValue().toString(), p); } if (pie.getExplodedPiece() != null) { plot.setExplodePercent(pie.getExplodedPiece(), 0.50); } plot.setLabelBackgroundPaint(null); plot.setLabelOutlinePaint(null); plot.setLabelShadowPaint(null); UIColor fg = cd.getTextColor(plotLabelColor); UIFont font = cd.getTextFont(plotLabelFont); plot.setLabelFont(font); plot.setLabelPaint(fg); if (cd.isShowPlotLabels()) { String format = (pi == null) ? null : pi.getLabelsFormat(); plot.setLabelGenerator(new PieLabelGenerator(cd, format)); } if (cd.isShowToolTips()) { plot.setToolTipGenerator(new PieToolTipLabelGenerator(cd, false)); } }
From source file:semaforo.Semaforo.java
public static void SemaforoGrafico(JFreeChart chart) { // set a custom background for the chart chart.setBackgroundPaint(new GradientPaint(new Point(0, 0), Color.BLACK, new Point(400, 200), Color.BLACK)); // customise the title position and font TextTitle t = chart.getTitle();//from w ww .jav a 2 s.co m t.setHorizontalAlignment(HorizontalAlignment.LEFT); t.setPaint(new Color(240, 240, 240)); t.setFont(new Font("Arial", Font.BOLD, 0)); PiePlot plot = null; plot = (PiePlot) chart.getPlot(); plot.setBackgroundPaint(null); plot.setInteriorGap(0.00); plot.setOutlineVisible(true); // use gradients and white borders for the section colours plot.setBaseSectionOutlinePaint(Color.BLACK); plot.setSectionOutlinesVisible(true); plot.setBaseSectionOutlineStroke(new BasicStroke(0.0f)); // customise the section label appearance plot.setLabelFont(new Font("Courier New", Font.BOLD, 0)); plot.setLabelLinkPaint(Color.BLACK); plot.setLabelLinkStroke(new BasicStroke(0.0f)); plot.setLabelOutlineStroke(null); plot.setLabelPaint(Color.BLACK); plot.setLabelBackgroundPaint(null); plot.setLabelBackgroundPaint(Color.BLACK); plot.setLabelShadowPaint(Color.BLACK); // add a subtitle giving the data source // Mostramos la grafica dentro del jPanel1 panel = new ChartPanel(chart); panel.setBackground(Color.BLACK); panel.repaint(); jPanel3.setLayout(null); jPanel3.setLayout(new java.awt.BorderLayout()); jPanel3.remove(panel); jPanel3.add(panel); jPanel3.repaint(); Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); jTabbedPane1.setPreferredSize(new Dimension(screenSize.width, screenSize.height)); }
From source file:semaforo.Semaforo.java
public static void editGrafico() { DecimalFormat df = new DecimalFormat(); df.setMaximumFractionDigits(2);/*from ww w . j a v a 2 s . co m*/ double cfd = 0.0; double bull = 0.0; double bear = 0.0; if (countCfd != 0) cfd = (countCfd * 100) / (countBear + countBull + countCfd); if (countBull != 0) bull = ((countBull * 100) / (countBear + countBull + countCfd)); if (countBear != 0) bear = ((countBear * 100) / (countBear + countBull + countCfd)); Semaforo.l1.setText("CFD (" + String.format("%.2f", cfd) + "%)"); Semaforo.l2.setText("BULL (" + String.format("%.2f", bull) + "%)"); Semaforo.l3.setText("BEAR (" + String.format("%.2f", bear) + "%)"); DefaultPieDataset pieDataset = new DefaultPieDataset(); pieDataset.setValue("CFD (" + cfd + "%)", new Integer((int) countCfd)); pieDataset.setValue("BULL (" + bull + "%)", new Integer((int) countBull)); pieDataset.setValue("BEAR (" + bear + "%)", new Integer((int) countBear)); JFreeChart chart = null; chart = ChartFactory.createPieChart("", // chart title pieDataset, // data false, // no legend false, // tooltips false // no URL generation ); // set a custom background for the chart chart.setBackgroundPaint(new GradientPaint(new Point(0, 0), Color.BLACK, new Point(400, 200), Color.BLACK)); // 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, 0)); PiePlot plot = null; plot = (PiePlot) chart.getPlot(); plot.setBackgroundPaint(null); plot.setInteriorGap(0.00); plot.setOutlineVisible(true); // use gradients and white borders for the section colours plot.setBaseSectionOutlinePaint(Color.BLACK); plot.setSectionOutlinesVisible(true); plot.setBaseSectionOutlineStroke(new BasicStroke(0.0f)); // customise the section label appearance plot.setLabelFont(new Font("Courier New", Font.BOLD, 0)); plot.setLabelLinkPaint(Color.BLACK); plot.setLabelLinkStroke(new BasicStroke(0.0f)); plot.setLabelOutlineStroke(null); plot.setLabelPaint(Color.BLACK); plot.setLabelBackgroundPaint(null); plot.setLabelBackgroundPaint(Color.BLACK); plot.setLabelShadowPaint(Color.BLACK); // add a subtitle giving the data source // Mostramos la grafica dentro del jPanel1 Semaforo.panel.setChart(chart); }
From source file:ro.nextreports.engine.chart.JFreeChartExporter.java
private JFreeChart createPieChart() throws QueryException { pieDataset = new DefaultPieDataset(); String chartTitle = replaceParameters(chart.getTitle().getTitle()); chartTitle = StringUtil.getI18nString(chartTitle, I18nUtil.getLanguageByName(chart, language)); JFreeChart jfreechart = ChartFactory.createPieChart(chartTitle, pieDataset, true, true, false); // hide border jfreechart.setBorderVisible(false);/* w w w . ja v a2s . c o m*/ // title setTitle(jfreechart); PiePlot plot = (PiePlot) jfreechart.getPlot(); plot.setForegroundAlpha(transparency); // a start angle used to create similarities between flash chart and this jfreechart plot.setStartAngle(330); // legend label will contain the text and the value plot.setLegendLabelGenerator(new StandardPieSectionLabelGenerator("{0} = {1}")); // no shadow plot.setShadowXOffset(0); plot.setShadowYOffset(0); DecimalFormat decimalformat; DecimalFormat percentageFormat; if (chart.getYTooltipPattern() == null) { decimalformat = new DecimalFormat("#"); percentageFormat = new DecimalFormat("0.00%"); } else { decimalformat = new DecimalFormat(chart.getYTooltipPattern()); percentageFormat = decimalformat; } boolean showValues = (chart.getShowYValuesOnChart() == null) ? false : chart.getShowYValuesOnChart(); if (showValues) { // label will contain also the percentage formatted with two decimals plot.setLabelGenerator( new StandardPieSectionLabelGenerator("{0} ({2})", decimalformat, percentageFormat)); } // chart background plot.setBackgroundPaint(chart.getBackground()); createChart(null, new Object[1]); // after chart creation we can set slices colors List<Comparable> keys = pieDataset.getKeys(); List<Color> colors = chart.getForegrounds(); for (int i = 0, size = colors.size(); i < keys.size(); i++) { plot.setSectionPaint(keys.get(i), colors.get(i % size)); plot.setLabelFont(chart.getFont()); } return jfreechart; }
From source file:com.naryx.tagfusion.cfm.tag.awt.cfCHART.java
private JFreeChart renderPieChart(cfSession _Session, cfCHARTInternalData chartData, List<cfCHARTSERIESData> series, String tipStyle, String drillDownUrl) throws cfmRunTimeException { // Retrieve the attributes of the chart String backgroundColorStr = getDynamic(_Session, "BACKGROUNDCOLOR").toString(); Color backgroundColor = convertStringToColor(backgroundColorStr); String foregroundColorStr = getDynamic(_Session, "FOREGROUNDCOLOR").toString(); Color foregroundColor = convertStringToColor(foregroundColorStr); String labelFormat = getDynamic(_Session, "LABELFORMAT").toString().toLowerCase(); if (!labelFormat.equals("number") && !labelFormat.equals("currency") && !labelFormat.equals("percent")) throw newRunTimeException( "The labelFormat value '" + labelFormat + "' is not supported with pie charts"); String pieSliceStyle = getDynamic(_Session, "PIESLICESTYLE").toString().toLowerCase(); String title = null;/*from w w w . j a va2s . c om*/ if (containsAttribute("TITLE")) title = getDynamic(_Session, "TITLE").toString(); Font font = getFont(_Session); cfCHARTSERIESData seriesData = series.get(0); boolean bShow3D = getDynamic(_Session, "SHOW3D").getBoolean(); if (bShow3D && !seriesData.getType().equals("pie")) throw newRunTimeException("Only bar, line, horizontal bar and pie charts can be displayed in 3D"); boolean bShowBorder = getDynamic(_Session, "SHOWBORDER").getBoolean(); boolean bShowLegend = true; // default to true for pie charts if (containsAttribute("SHOWLEGEND")) bShowLegend = getDynamic(_Session, "SHOWLEGEND").getBoolean(); // Get the plot for the chart and configure it PiePlot plot = getPiePlot(series, pieSliceStyle, bShow3D); setBackgroundImage(_Session, plot, chartData.getImageData()); plot.setBackgroundPaint(backgroundColor); plot.setLabelBackgroundPaint(backgroundColor); plot.setLabelShadowPaint(backgroundColor); // Set the labels color plot.setLabelPaint(convertStringToColor(seriesData.getDataLabelColor())); // Set the labels font plot.setLabelFont(getFont(seriesData.getDataLabelFont(), seriesData.getDataLabelFontBold(), seriesData.getDataLabelFontItalic(), seriesData.getDataLabelFontSize())); String dataLabelStyle = seriesData.getDataLabelStyle(); NumberFormat percentInstance = NumberFormat.getPercentInstance(); percentInstance.setMaximumFractionDigits(3); NumberFormat numberFormat = null; if (labelFormat.equals("number")) { // Only display the value in the Label as a number numberFormat = NumberFormat.getInstance(); if (dataLabelStyle.equals("none")) plot.setLabelGenerator(null); else if (dataLabelStyle.equals("value")) plot.setLabelGenerator(new org.jfree.chart.labels.StandardPieSectionLabelGenerator("{1}")); else if (dataLabelStyle.equals("rowlabel")) plot.setLabelGenerator( new org.jfree.chart.labels.StandardPieSectionLabelGenerator(seriesData.getSeriesLabel())); else if (dataLabelStyle.equals("columnlabel")) plot.setLabelGenerator(new org.jfree.chart.labels.StandardPieSectionLabelGenerator("{0}")); else if (dataLabelStyle.equals("pattern")) plot.setLabelGenerator( new org.jfree.chart.labels.StandardPieSectionLabelGenerator("{0} {1} ({2} of {3})")); else { String pattern = java.text.MessageFormat.format(dataLabelStyle, new Object[] { seriesData.getSeriesLabel(), "{0}", "{1}", "{2}", "{3}" }); plot.setLabelGenerator(new org.jfree.chart.labels.StandardPieSectionLabelGenerator(pattern)); } } else if (labelFormat.equals("currency")) { // Only display the value in the Label as a currency numberFormat = NumberFormat.getCurrencyInstance(); if (dataLabelStyle.equals("none")) plot.setLabelGenerator(null); else if (dataLabelStyle.equals("value")) plot.setLabelGenerator(new org.jfree.chart.labels.StandardPieSectionLabelGenerator("{1}", NumberFormat.getCurrencyInstance(), percentInstance)); else if (dataLabelStyle.equals("rowlabel")) plot.setLabelGenerator( new org.jfree.chart.labels.StandardPieSectionLabelGenerator(seriesData.getSeriesLabel())); else if (dataLabelStyle.equals("columnlabel")) plot.setLabelGenerator(new org.jfree.chart.labels.StandardPieSectionLabelGenerator("{0}")); else if (dataLabelStyle.equals("pattern")) plot.setLabelGenerator(new org.jfree.chart.labels.StandardPieSectionLabelGenerator( "{0} {1} ({2} of {3})", NumberFormat.getCurrencyInstance(), percentInstance)); else { String pattern = java.text.MessageFormat.format(dataLabelStyle, new Object[] { seriesData.getSeriesLabel(), "{0}", "{1}", "{2}", "{3}" }); plot.setLabelGenerator(new org.jfree.chart.labels.StandardPieSectionLabelGenerator(pattern, NumberFormat.getCurrencyInstance(), percentInstance)); } } else if (labelFormat.equals("percent")) { // Only display the value in the Label as a percent numberFormat = percentInstance; if (dataLabelStyle.equals("none")) plot.setLabelGenerator(null); else if (dataLabelStyle.equals("value")) plot.setLabelGenerator(new org.jfree.chart.labels.StandardPieSectionLabelGenerator("{1}", percentInstance, percentInstance)); else if (dataLabelStyle.equals("rowlabel")) plot.setLabelGenerator( new org.jfree.chart.labels.StandardPieSectionLabelGenerator(seriesData.getSeriesLabel())); else if (dataLabelStyle.equals("columnlabel")) plot.setLabelGenerator(new org.jfree.chart.labels.StandardPieSectionLabelGenerator("{0}")); else if (dataLabelStyle.equals("pattern")) plot.setLabelGenerator(new org.jfree.chart.labels.StandardPieSectionLabelGenerator( "{0} {1} ({2} of {3})", percentInstance, percentInstance)); else { String pattern = java.text.MessageFormat.format(dataLabelStyle, new Object[] { seriesData.getSeriesLabel(), "{0}", "{1}", "{2}", "{3}" }); plot.setLabelGenerator(new org.jfree.chart.labels.StandardPieSectionLabelGenerator(pattern, percentInstance, percentInstance)); } } if (!tipStyle.equals("none")) { plot.setToolTipGenerator(new StandardPieToolTipGenerator( StandardPieToolTipGenerator.DEFAULT_SECTION_LABEL_FORMAT, numberFormat, numberFormat)); } if (drillDownUrl != null) { plot.setURLGenerator(new com.newatlanta.bluedragon.PieURLGenerator(drillDownUrl, numberFormat)); } // Get the chart and configure it JFreeChart chart = new JFreeChart(null, null, plot, false); chart.setBorderVisible(bShowBorder); chart.setBackgroundPaint(backgroundColor); setTitle(chart, title, font, foregroundColor, chartData.getTitles()); setLegend(chart, bShowLegend, font, foregroundColor, backgroundColor, chartData.getLegendData()); return chart; }