List of usage examples for org.jfree.chart.plot PiePlot setLegendItemShape
public void setLegendItemShape(Shape shape)
From source file:edu.jhuapl.graphs.controller.GraphController.java
public GraphObject createPieGraph(GraphDataInterface graphData, Encoding encoding) { GraphObject graph = null;// ww w . j av a 2 s. co m Map<String, Object> graphMetaData = new HashMap<String, Object>(); List<PointInterface> points = new ArrayList<PointInterface>(); setPieGraphMetaData(graphData, graphMetaData, points); // I'm ashamed of this code in so many ways String graphTitle = (String) graphMetaData.get(GraphSource.GRAPH_TITLE); try { // add the created chart properties JFreeChartGraphSource graphSource = new JFreeChartGraphSource(); graphSource.setData(Arrays.asList(new DataSeries(points, new HashMap<String, Object>()))); graphSource.setParams(graphMetaData); graphSource.initialize(); if (graphData.showLegend()) { PiePlot plot = (PiePlot) graphSource.getChart().getPlot(); // use rectangles as the legend shapes plot.setLegendItemShape(new Rectangle(7, 8)); // generate tooltip for the legend items in the following format: "lineSetLabels - count" if (graphData.percentBased()) { plot.setLegendLabelToolTipGenerator(new StandardPieSectionLabelGenerator("{0} - {1} ({2})", new DecimalFormat("#.##"), new DecimalFormat("#.##%"))); } else { plot.setLegendLabelToolTipGenerator(new StandardPieSectionLabelGenerator("{0} - {1} ({2})", new DecimalFormat("#"), new DecimalFormat("#.##%"))); } } // render the graph to get the image map RenderedGraph renderedGraph = graphSource.renderGraph(graphData.getGraphWidth(), graphData.getGraphHeight(), encoding); String extension = ".dat"; switch (encoding) { case JPEG: extension = ".jpg"; break; case PNG: case PNG_WITH_TRANSPARENCY: extension = ".png"; break; } String imageFileName = getCleanValue(graphTitle) + "_piegraph" + extension; // get the image map String imageMapName = "imageMap" + graphDataId; String imageMap = appendImageMapTarget(renderedGraph.getImageMap(imageMapName), graphData.getLineSetURLTarget()); try { // store away the graph data file graphDataHandler.putGraphData(graphData, graphDataId); graph = new GraphObject(graphSource, renderedGraph, imageFileName, imageMapName, imageMap, graphDataId); } catch (GraphException e) { System.out.println(e.getMessage()); e.printStackTrace(); } } catch (GraphException e) { System.out.println("Could not create pie graph " + graphTitle); e.printStackTrace(); } return graph; }
From source file:lucee.runtime.tag.Chart.java
private void chartPie() throws PageException, IOException { // do dataset DefaultPieDataset dataset = new DefaultPieDataset(); ChartSeriesBean csb = _series.get(0); ChartDataBean cdb;//from w w w. j a v a 2s. co m List datas = csb.getDatas(); if (sortxaxis) Collections.sort(datas); Iterator itt = datas.iterator(); while (itt.hasNext()) { cdb = (ChartDataBean) itt.next(); dataset.setValue(cdb.getItemAsString(), cdb.getValue()); } JFreeChart chart = show3d ? ChartFactory.createPieChart3D(title, dataset, false, true, true) : ChartFactory.createPieChart(title, dataset, false, true, true); Plot p = chart.getPlot(); PiePlot pp = (PiePlot) p; Font _font = getFont(); pp.setLegendLabelGenerator(new PieSectionLegendLabelGeneratorImpl(_font, chartwidth)); pp.setBaseSectionOutlinePaint(Color.GRAY); // border pp.setLegendItemShape(new Rectangle(7, 7)); pp.setLabelFont(new Font(font, 0, 11)); pp.setLabelLinkPaint(COLOR_333333); pp.setLabelLinkMargin(-0.05); pp.setInteriorGap(0.123); pp.setLabelGenerator(new PieSectionLabelGeneratorImpl(labelFormat)); databackgroundcolor = backgroundcolor; setBackground(chart, p); setBorder(chart, p); setLegend(chart, p, _font); set3d(p); setFont(chart, _font); setTooltip(chart); setScale(chart); // Slice Type and colors boolean doSclice = pieslicestyle == PIE_SLICE_STYLE_SLICED; Color[] colors = csb.getColorlist(); Iterator it = csb.getDatas().iterator(); int count = 0; while (it.hasNext()) { cdb = (ChartDataBean) it.next(); if (doSclice) pp.setExplodePercent(cdb.getItemAsString(), 0.13); if (count < colors.length) { pp.setSectionPaint(cdb.getItemAsString(), colors[count]); } count++; } writeOut(chart); }
From source file:org.tiefaces.components.websheet.chart.ChartHelper.java
/** * finalize the style for jfreechart. The default setting is different from * jfreechart and Excel. We try to minimize the difference. * /*from w w w . j av a 2 s . c o m*/ * @param chart * jfreechart. * @param chartData * contain information gathered from excel chart object. */ private void setupPieStyle(final JFreeChart chart, final ChartData chartData) { PiePlot plot = (PiePlot) chart.getPlot(); List<ChartSeries> seriesList = chartData.getSeriesList(); List<ParsedCell> categoryList = chartData.getCategoryList(); BasicStroke bLine = new BasicStroke(2.0f); for (int i = 0; i < seriesList.size(); i++) { ChartSeries chartSeries = seriesList.get(i); List<XColor> valueColorList = chartSeries.getValueColorList(); for (int index = 0; index < categoryList.size(); index++) { try { String sCategory = getParsedCellValue(categoryList.get(index)); Color cColor = ColorUtility.xssfClrToClr(valueColorList.get(index).getXssfColor()); plot.setSectionPaint(sCategory, cColor); plot.setSectionOutlineStroke(sCategory, bLine); } catch (Exception ex) { LOG.log(Level.FINE, "SetupPieStyle error = " + ex.getLocalizedMessage(), ex); } } } plot.setBackgroundPaint(ColorUtility.xssfClrToClr(chartData.getBgColor().getXssfColor())); // below are modifications for default setting in excel chart // to-do: need read setting from xml in future plot.setOutlineVisible(false); plot.setLegendItemShape(new Rectangle(TieConstants.DEFAULT_LEGENT_ITEM_SHAPE_WIDTH, TieConstants.DEFAULT_LEGENT_ITEM_SHAPE_HEIGHT)); chart.setBackgroundPaint(Color.WHITE); LegendTitle legend = chart.getLegend(); legend.setPosition(RectangleEdge.RIGHT); legend.setFrame(BlockBorder.NONE); }
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()); }/* w w w. j a v a 2s . co 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; }