List of usage examples for org.jfree.chart.plot PiePlot setForegroundAlpha
public void setForegroundAlpha(float alpha)
From source file:de.forsthaus.webui.customer.CustomerChartCtrl.java
/** * onClick button PieChart. <br>/*from ww w . j av a 2s . co m*/ * * @param event * @throws IOException */ public void onClick$button_CustomerChart_PieChart(Event event) throws InterruptedException, IOException { // logger.debug(event.toString()); div_chartArea.getChildren().clear(); // get the customer ID for which we want show a chart long kunId = getCustomer().getId(); // get a list of data List<ChartData> kunAmountList = getChartService().getChartDataForCustomer(kunId); if (kunAmountList.size() > 0) { DefaultPieDataset pieDataset = new DefaultPieDataset(); for (ChartData chartData : kunAmountList) { Calendar calendar = new GregorianCalendar(); calendar.setTime(chartData.getChartKunInvoiceDate()); int month = calendar.get(Calendar.MONTH) + 1; int year = calendar.get(Calendar.YEAR); String key = String.valueOf(month) + "/" + String.valueOf(year); BigDecimal bd = chartData.getChartKunInvoiceAmount().setScale(15, 3); String amount = String.valueOf(bd.doubleValue()); // fill the data pieDataset.setValue(key + " " + amount, new Double(chartData.getChartKunInvoiceAmount().doubleValue())); } String title = "Monthly amount for year 2009"; JFreeChart chart = ChartFactory.createPieChart(title, pieDataset, true, true, true); PiePlot plot = (PiePlot) chart.getPlot(); plot.setForegroundAlpha(0.5f); BufferedImage bi = chart.createBufferedImage(chartWidth, chartHeight, BufferedImage.TRANSLUCENT, null); byte[] bytes = EncoderUtil.encode(bi, ImageFormat.PNG, true); AImage chartImage = new AImage("Pie Chart", bytes); Image img = new Image(); img.setContent(chartImage); img.setParent(div_chartArea); } else { div_chartArea.getChildren().clear(); Label label = new Label(); label.setValue("This customer have no data for showing in a chart!"); label.setParent(div_chartArea); } }
From source file:edu.isistan.carcha.plugin.editors.TraceabilityEditor.java
/** * Creates the impact Pie Chart page. It allows users to select a Crosscutting Concern and see Design Decision type distribution */// ww w. ja v a2 s .com void impactPieChartPage() { ddDataset = new DefaultPieDataset(); impactDataset = new DefaultPieDataset(); JFreeChart ddChart = ChartFactory.createPieChart("Crosscutting Concerns", ddDataset, true, true, false); JFreeChart impactChart = ChartFactory.createPieChart("Design Decisions", impactDataset, true, true, false); PiePlot ddPlot = (PiePlot) ddChart.getPlot(); ddPlot.setStartAngle(290); ddPlot.setDirection(Rotation.CLOCKWISE); ddPlot.setForegroundAlpha(0.5f); PiePlot impactPlot = (PiePlot) impactChart.getPlot(); impactPlot.setStartAngle(290); impactPlot.setDirection(Rotation.CLOCKWISE); impactPlot.setForegroundAlpha(0.5f); PieSectionLabelGenerator gen = new StandardPieSectionLabelGenerator("{0} ({2})"); ddPlot.setLabelGenerator(gen); impactPlot.setLabelGenerator(gen); Composite composite = new Composite(getContainer(), SWT.NONE); FillLayout layout = new FillLayout(); composite.setLayout(layout); final ChartComposite cComposite = new ChartComposite(composite, SWT.NONE, ddChart, true); cComposite.addChartMouseListener(new ChartMouseListener() { @Override public void chartMouseClicked(ChartMouseEvent event) { String[] parts = event.getEntity().getToolTipText().split(":"); HashMap<String, Integer> values = PluginUtil.getDDDistributionForCrossCuttingConcern(cp, parts[0]); logger.info("Impact Pie Chart for: " + parts[0]); impactDataset.clear(); for (String key : values.keySet()) { impactDataset.setValue(key, values.get(key)); } } @Override public void chartMouseMoved(ChartMouseEvent event) { } }); new ChartComposite(composite, SWT.NONE, impactChart, true); int index = addPage(composite); setPageText(index, "Graph"); }
From source file:simx.profiler.info.actor.ActorInstanceInfoTopComponent.java
/** * This method creates a pie chart and adds it to the target panel. * /*from w ww. j a v a 2 s .c om*/ * @param data The data set that should be visualized by the pie chart. * @param targetPanel The panel where the pie chart should be added to. */ private void createPieChart(final DefaultPieDataset data, final javax.swing.JPanel targetPanel) { if (data == null) throw new IllegalArgumentException("The parameter 'data' must not be 'null'!"); if (targetPanel == null) throw new IllegalArgumentException("The parameter 'targetPanel' must not be 'null'!"); data.setValue("???", 100); final JFreeChart chart = ChartFactory.createPieChart("", data, false, false, false); final PiePlot plot = (PiePlot) chart.getPlot(); plot.setDirection(Rotation.CLOCKWISE); plot.setForegroundAlpha(0.5f); final ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new java.awt.Dimension(261, 157)); targetPanel.setLayout(new BorderLayout()); targetPanel.add(chartPanel, BorderLayout.CENTER); }
From source file:net.sf.eclipsecs.ui.stats.views.GraphStatsView.java
/** * Cre le graphe JFreeChart./*from ww w .ja v a 2 s .c o m*/ * * @param piedataset * : la source de donnes afficher * @return le diagramme */ private JFreeChart createChart(GraphPieDataset piedataset) { JFreeChart jfreechart = ChartFactory.createPieChart3D(null, piedataset, false, true, false); jfreechart.setAntiAlias(true); jfreechart.setTextAntiAlias(true); PiePlot pieplot3d = (PiePlot) jfreechart.getPlot(); pieplot3d.setInsets(new RectangleInsets(0, 0, 0, 0)); final double angle = 290D; pieplot3d.setStartAngle(angle); pieplot3d.setDirection(Rotation.CLOCKWISE); final float foreground = 0.5F; pieplot3d.setForegroundAlpha(foreground); pieplot3d.setNoDataMessage(Messages.GraphStatsView_noDataToDisplay); pieplot3d.setCircular(true); pieplot3d.setOutlinePaint(null); pieplot3d.setLabelFont(new Font("SansSerif", Font.PLAIN, 10)); pieplot3d.setLabelGap(0.02); pieplot3d.setLabelOutlinePaint(null); pieplot3d.setLabelShadowPaint(null); pieplot3d.setLabelBackgroundPaint(Color.WHITE); pieplot3d.setBackgroundPaint(Color.WHITE); pieplot3d.setInteriorGap(0.02); pieplot3d.setMaximumLabelWidth(0.20); return jfreechart; }
From source file:it.eng.spagobi.engines.chart.bo.charttypes.piecharts.SimplePie.java
public JFreeChart createChart(DatasetMap datasets) { Dataset dataset = (Dataset) datasets.getDatasets().get("1"); JFreeChart chart = null;/* www . j a v a 2s . c o m*/ if (!threeD) { chart = ChartFactory.createPieChart(name, (PieDataset) dataset, // data legend, // include legend true, false); chart.setBackgroundPaint(color); TextTitle title = chart.getTitle(); title.setToolTipText("A title tooltip!"); PiePlot plot = (PiePlot) chart.getPlot(); plot.setLabelFont(new Font(defaultLabelsStyle.getFontName(), Font.PLAIN, defaultLabelsStyle.getSize())); plot.setCircular(false); plot.setLabelGap(0.02); plot.setNoDataMessage("No data available"); if (percentage == false) { plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0} ({1})")); } else { plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0} ({2})")); } } else { chart = ChartFactory.createPieChart3D(name, (PieDataset) dataset, // data true, // include legend true, false); chart.setBackgroundPaint(color); TextTitle title = chart.getTitle(); title.setToolTipText("A title tooltip!"); PiePlot3D plot = (PiePlot3D) chart.getPlot(); plot.setDarkerSides(true); plot.setStartAngle(290); plot.setDirection(Rotation.CLOCKWISE); plot.setForegroundAlpha(1.0f); plot.setDepthFactor(0.2); plot.setLabelFont(new Font(defaultLabelsStyle.getFontName(), Font.PLAIN, defaultLabelsStyle.getSize())); // plot.setNoDataMessages("No data available"); plot.setCircular(false); plot.setLabelGap(0.02); plot.setNoDataMessage("No data available"); if (percentage == false) { plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0} ({1})")); } else { plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0} ({2})")); } } TextTitle title = setStyleTitle(name, styleTitle); chart.setTitle(title); if (subName != null && !subName.equals("")) { TextTitle subTitle = setStyleTitle(subName, styleSubTitle); chart.addSubtitle(subTitle); } return chart; }
From source file:org.jivesoftware.openfire.reporting.graph.GraphEngine.java
/** * Creates a Pie Chart based on map.//from w w w . ja v a 2 s. com * * @return the Pie Chart generated. */ public JFreeChart getPieChart(Map<String, Double> pieValues) { DefaultPieDataset dataset = new DefaultPieDataset(); for (String key : pieValues.keySet()) { dataset.setValue(key, pieValues.get(key)); } JFreeChart chart = ChartFactory.createPieChart3D(null, // chart title dataset, // data true, // include legend true, false); chart.setBackgroundPaint(Color.white); chart.setBorderVisible(false); chart.setBorderPaint(null); PiePlot plot = (PiePlot) chart.getPlot(); plot.setSectionOutlinesVisible(false); plot.setLabelFont(new Font("SansSerif", Font.BOLD, 12)); plot.setNoDataMessage("No data available"); plot.setCircular(true); plot.setLabelGap(0.02); plot.setOutlinePaint(null); plot.setLabelLinksVisible(false); plot.setLabelGenerator(null); plot.setLegendLabelGenerator(new StandardPieSectionLabelGenerator("{0}")); plot.setStartAngle(270); plot.setDirection(Rotation.ANTICLOCKWISE); plot.setForegroundAlpha(0.60f); plot.setInteriorGap(0.33); return 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);/*from w ww . ja v a 2s . co 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:org.sakaiproject.sitestats.impl.chart.ChartServiceImpl.java
private byte[] generatePieChart(String siteId, PieDataset dataset, int width, int height, boolean render3d, float transparency, boolean smallFontInDomainAxis) { JFreeChart chart = null;/*w w w .ja va2s . c o m*/ if (render3d) chart = ChartFactory.createPieChart3D(null, dataset, false, false, false); else chart = ChartFactory.createPieChart(null, dataset, false, false, false); PiePlot plot = (PiePlot) chart.getPlot(); // set start angle (135 or 150 deg so minor data has more space on the left) plot.setStartAngle(150D); // set transparency plot.setForegroundAlpha(transparency); // set background chart.setBackgroundPaint(parseColor(M_sm.getChartBackgroundColor())); plot.setBackgroundPaint(parseColor(M_sm.getChartBackgroundColor())); // fix border offset chart.setPadding(new RectangleInsets(5, 5, 5, 5)); plot.setInsets(new RectangleInsets(1, 1, 1, 1)); // set chart border plot.setOutlinePaint(null); chart.setBorderVisible(true); chart.setBorderPaint(parseColor("#cccccc")); // set antialias chart.setAntiAlias(true); BufferedImage img = chart.createBufferedImage(width, height); final ByteArrayOutputStream out = new ByteArrayOutputStream(); try { ImageIO.write(img, "png", out); } catch (IOException e) { LOG.warn("Error occurred while generating SiteStats chart image data", e); } return out.toByteArray(); }
From source file:org.jfree.chart.demo.JFreeChartDemoBase.java
/** * Creates and returns a sample pie chart. * * @return a sample pie chart.//from www . j ava 2s .c om */ public JFreeChart createPieChartTwo() { // create a default chart based on some sample data... final String title = this.resources.getString("pie.pie2.title"); final CategoryDataset data = DemoDatasetFactory.createCategoryDataset(); final Comparable category = (Comparable) data.getColumnKeys().get(1); final PieDataset extracted = DatasetUtilities.createPieDatasetForColumn(data, category); final JFreeChart chart = ChartFactory.createPieChart(title, extracted, true, true, false); // then customise it a little... chart.setBackgroundPaint(Color.lightGray); final PiePlot pie = (PiePlot) chart.getPlot(); pie.setLabelGenerator(new StandardPieItemLabelGenerator("{0} = {2}", NumberFormat.getNumberInstance(), NumberFormat.getPercentInstance())); pie.setBackgroundImage(JFreeChart.INFO.getLogo()); pie.setBackgroundPaint(Color.white); pie.setBackgroundAlpha(0.6f); pie.setForegroundAlpha(0.75f); 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);/* w ww . ja v a 2 s .com*/ 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; }