List of usage examples for org.jfree.chart.plot PiePlot setShadowYOffset
public void setShadowYOffset(double offset)
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 w ww .j ava 2 s .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: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 v a2s . 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:org.openfaces.component.chart.impl.configuration.ShadowConfigurator.java
public void configure(ConfigurablePlot plot, ChartView view) { PieChartView pieChartView = (PieChartView) view; PiePlot piePlot = (PiePlot) plot; piePlot.setShadowPaint(pieChartView.getShadowColor()); piePlot.setShadowXOffset(pieChartView.getShadowXOffset()); piePlot.setShadowYOffset(pieChartView.getShadowYOffset()); }
From source file:msi.gama.outputs.layers.charts.ChartJFreeChartOutputPie.java
@Override public void initChart(final IScope scope, final String chartname) { super.initChart(scope, chartname); final PiePlot pp = (PiePlot) chart.getPlot(); pp.setShadowXOffset(0);/*from ww w.j a v a 2s . c o m*/ pp.setShadowYOffset(0); if (!this.series_label_position.equals("none")) { pp.setLabelGenerator(new StandardPieSectionLabelGenerator("{0} = {1} ({2})")); if (axesColor != null) { pp.setLabelLinkPaint(axesColor); } pp.setLabelFont(getTickFont()); } if (this.series_label_position.equals("none")) { pp.setLabelLinksVisible(false); pp.setLabelGenerator(null); } if (textColor != null) { // pp.setLabelPaint(textColor); // not for Pie since the label background is always yellow for // now... } }
From source file:ch.zhaw.init.walj.projectmanagement.util.chart.PieChart.java
/** * creates the pie chart//from w ww . j a va2 s . c o m * @throws NumberFormatException * @throws IOException */ public void createChart() throws NumberFormatException, IOException { // create dataset with used and remaining budget DefaultPieDataset dataset = new DefaultPieDataset(); dataset.setValue("spent", con.getUsedBudget(project)); dataset.setValue("remaining", con.getRemainingBudget(project)); // create chart JFreeChart chart = ChartFactory.createPieChart("", dataset, false, false, false); // set color and style PiePlot plot = (PiePlot) chart.getPlot(); plot.setSectionPaint("remaining", new Color(0, 101, 166)); plot.setSectionPaint("spent", new Color(0, 62, 102)); plot.setLabelGenerator(null); plot.setBackgroundPaint(Color.WHITE); plot.setShadowXOffset(0); plot.setShadowYOffset(0); plot.setOutlineVisible(false); plot.setInteriorGap(0); // set size and save it as JPEG int width = 350; /* Width of the image */ int height = 350; /* Height of the image */ File pieChart = new File(path + "/Charts/BudgetProject" + project.getID() + ".jpg"); ChartUtilities.saveChartAsJPEG(pieChart, chart, width, height); }
From source file:org.talend.dataprofiler.chart.ChartDecorator.java
/** * //from w ww .ja v a 2s. co m * DOC qiongli Comment method "decoratePiePlot". * * @param chart */ private static void decoratePiePlot(JFreeChart chart) { Font font = new Font("sans-serif", Font.BOLD, BASE_TITLE_LABEL_SIZE);//$NON-NLS-1$ TextTitle textTitle = chart.getTitle(); // MOD msjian TDQ-5213 2012-5-7: fixed NPE if (textTitle != null) { textTitle.setFont(font); } setLegendFont(chart); // TDQ-5213~ PiePlot plot = (PiePlot) chart.getPlot(); font = new Font("Monospaced", Font.PLAIN, 10);//$NON-NLS-1$ plot.setLabelFont(font); plot.setNoDataMessage("No data available"); //$NON-NLS-1$ StandardPieSectionLabelGenerator standardPieSectionLabelGenerator = new StandardPieSectionLabelGenerator( ("{0}:{2}"), //$NON-NLS-1$ NumberFormat.getNumberInstance(), new DecimalFormat(PERCENT_FORMAT)); plot.setLabelGenerator(standardPieSectionLabelGenerator); plot.setLabelLinkPaint(Color.GRAY); plot.setLabelOutlinePaint(Color.WHITE); plot.setLabelGap(0.02D); plot.setOutlineVisible(false); plot.setMaximumLabelWidth(0.2D); plot.setCircular(false); // remove the shadow of the pie chart plot.setShadowXOffset(0); plot.setShadowYOffset(0); }
From source file:uk.ac.lkl.cram.ui.chart.LearningTypeChartMaker.java
/** * Create a chart from the provide pie dataset * * @return a Chart that can be rendered in a ChartPanel *///from ww w .j a v a2 s .c om @Override protected JFreeChart createChart() { //Create a pie chart from the chart factory with no title, a legend and tooltips JFreeChart chart = ChartFactory.createPieChart(null, (PieDataset) dataset, true, true, false); //Get the plot from the chart PiePlot plot = (PiePlot) chart.getPlot(); //Set the tooltip generator, to be "Practice (12%)" plot.setToolTipGenerator(new StandardPieToolTipGenerator( "<html><center>{0} ({2})<br/>Double-click for more</center></html>")); //Remove shadows from the plot plot.setShadowXOffset(0); plot.setShadowYOffset(0); //Remove the labels from the plot plot.setLabelGenerator(null); //Set the colours for the segments plot.setSectionPaint(ACQUISITION, ACQUISITION_COLOR); plot.setSectionPaint(COLLABORATION, COLLABORATION_COLOR); plot.setSectionPaint(DISCUSSION, DISCUSSION_COLOR); plot.setSectionPaint(INQUIRY, INQUIRY_COLOR); plot.setSectionPaint(PRACTICE, PRACTICE_COLOR); plot.setSectionPaint(PRODUCTION, PRODUCTION_COLOR); 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 av a2 s. c o m*/ 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:net.sf.fspdfs.chartthemes.spring.AegeanChartTheme.java
/** * */// w w w .j a va 2s . co m protected JFreeChart createPieChart() throws JRException { JFreeChart jfreeChart = super.createPieChart(); PiePlot piePlot = (PiePlot) jfreeChart.getPlot(); piePlot.setLabelBackgroundPaint(ChartThemesConstants.TRANSPARENT_PAINT); piePlot.setLabelShadowPaint(ChartThemesConstants.TRANSPARENT_PAINT); piePlot.setLabelOutlinePaint(ChartThemesConstants.TRANSPARENT_PAINT); piePlot.setShadowXOffset(0); piePlot.setShadowYOffset(0); PieDataset pieDataset = piePlot.getDataset(); if (pieDataset != null) { for (int i = 0; i < pieDataset.getItemCount(); i++) { piePlot.setSectionOutlinePaint(pieDataset.getKey(i), ChartThemesConstants.TRANSPARENT_PAINT); //makes pie colors darker //piePlot.setSectionPaint(pieDataset.getKey(i), GRADIENT_PAINTS[i]); } } piePlot.setCircular(true); return jfreeChart; }
From source file:com.polivoto.vistas.Charts.java
private JPanel hacerPiePanel(Pregunta pregunta, List<Opcion> opciones) { JPanel panel = new JPanel(new BorderLayout()); panel.setBackground(Color.white); DefaultPieDataset data = new DefaultPieDataset(); // Fuente de Datos for (Opcion opc : opciones) { data.setValue(opc.getNombre(), opc.getCantidad()); }//from w w w . j a va2 s . c o m // Creando el Grafico JFreeChart chart = ChartFactory.createPieChart("\n" + pregunta.getTitulo(), data, true, false, //TOOLTIPS false); chart.setBackgroundPaint(Color.white); chart.getTitle().setFont(new Font("Roboto", 0, 28)); // Crear el Panel del Grafico con ChartPanel ChartPanel chartPanel = new ChartPanel(chart); PiePlot plot = (PiePlot) chart.getPlot(); Rectangle bounds = panel.getBounds(); chartPanel.setBounds(bounds.x, bounds.y, bounds.height, bounds.height); panel.add(chartPanel); plot.setLabelGenerator(null); plot.setBackgroundPaint(Color.white); plot.setOutlineVisible(false); //StandardPieSectionLabelGenerator labels = new StandardPieSectionLabelGenerator("{0} = {1}"); //plot.setLabelGenerator(labels); plot.setBaseSectionOutlinePaint(Color.white); plot.setShadowXOffset(0); plot.setShadowYOffset(0); //#7cb5ec,#f45b5b,#90ed7d,#434348, //#f7a35c,#8085e9,#f15c80,#e4d354, //#2b908f,#91e8e1 Color[] colors = { new Color(124, 181, 236), new Color(244, 91, 91), new Color(144, 237, 125), new Color(67, 67, 72), new Color(247, 163, 92), new Color(128, 133, 233), new Color(241, 92, 128), new Color(228, 211, 84), new Color(43, 144, 143), new Color(145, 232, 225) }; PieRenderer renderer = new PieRenderer(colors); renderer.setColor(plot, data); LegendTitle legend = chart.getLegend(); legend.setPosition(RectangleEdge.RIGHT); Font nwfont = new Font("Roboto", 0, 18); legend.setItemFont(nwfont); legend.setFrame(new BlockBorder(0, 0, 0, 90, Color.white)); legend.setBackgroundPaint(Color.WHITE); legend.setItemLabelPadding(new RectangleInsets(8, 8, 8, 0)); //RectangleInsets padding = new RectangleInsets(5, 5, 5, 5); //legend.setItemLabelPadding(padding); plot.setLegendLabelGenerator(new StandardPieSectionLabelGenerator("{1} {0}")); plot.setLegendItemShape(new Rectangle(25, 25)); return panel; }