List of usage examples for org.jfree.chart.title LegendTitle setItemLabelPadding
public void setItemLabelPadding(RectangleInsets padding)
From source file:com.xpn.xwiki.plugin.charts.ChartCustomizer.java
public static void customizeLegend(LegendTitle legend, ChartParams params) { if (params.get(ChartParams.LEGEND_BACKGROUND_COLOR) != null) { legend.setBackgroundPaint(params.getColor(ChartParams.LEGEND_BACKGROUND_COLOR)); }// w w w . j ava 2s . c o m if (params.get(ChartParams.LEGEND_ITEM_FONT) != null) { legend.setItemFont(params.getFont(ChartParams.LEGEND_ITEM_FONT)); } if (params.get(ChartParams.LEGEND_ITEM_LABEL_PADDING) != null) { legend.setItemLabelPadding(params.getRectangleInsets(ChartParams.LEGEND_ITEM_LABEL_PADDING)); } if (params.get(ChartParams.LEGEND_ITEM_GRAPHIC_ANCHOR) != null) { legend.setLegendItemGraphicAnchor(params.getRectangleAnchor(ChartParams.LEGEND_ITEM_GRAPHIC_ANCHOR)); } if (params.get(ChartParams.LEGEND_ITEM_GRAPHIC_EDGE) != null) { legend.setLegendItemGraphicEdge(params.getRectangleEdge(ChartParams.LEGEND_ITEM_GRAPHIC_EDGE)); } if (params.get(ChartParams.LEGEND_ITEM_GRAPHIC_LOCATION) != null) { legend.setLegendItemGraphicAnchor(params.getRectangleAnchor(ChartParams.LEGEND_ITEM_GRAPHIC_LOCATION)); } if (params.get(ChartParams.LEGEND_ITEM_GRAPHIC_PADDING) != null) { legend.setLegendItemGraphicPadding(params.getRectangleInsets(ChartParams.LEGEND_ITEM_GRAPHIC_PADDING)); } }
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 v a 2 s. c om*/ // 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; }
From source file:com.polivoto.vistas.Charts.java
private void crearBarChart(Pregunta pregunta) { JPanel panel = new JPanel(new BorderLayout()); panel.setBackground(Color.white); panelGrafica.add(panel);/*ww w .j av a 2 s . co m*/ DefaultCategoryDataset data = new DefaultCategoryDataset(); // Fuente de Datos //Calcular el nmero N de perfiles. Si N=1, no discriminar por pestanas. //Si son N perfiles (N>2), hacer N+1 pestanas (la ltima representa la //suma de los resultados sin segregacin. int n = pregunta.obtenerCantidadDePerfiles(); System.out.println(" n " + n); if (n > 1) { for (int i = 0; i < n; i++) { List<Opcion> opciones = pregunta.obtenerResultadoPorPerfil(i).getOpciones(); for (Opcion opc : opciones) { data.setValue(opc.getCantidad(), opc.getNombre(), pregunta.obtenerResultadoPorPerfil(i).getPerfil()); } } } for (int i = 0; i < pregunta.obtenerCantidadDeOpciones(); i++) { Opcion opc = pregunta.obtenerOpcion(i); data.setValue(opc.getCantidad(), opc.getNombre(), "Todos"); } // Creando el Grafico JFreeChart chart = ChartFactory.createBarChart("\n" + pregunta.getTitulo() + "\n", "Perfil", "Total de votos", data, PlotOrientation.VERTICAL, true, // include legend true, // tooltips? false // URLs? ); //chart.setBackgroundPaint(Color.white); chart.getTitle().setFont(new Font("Roboto", 0, 28)); //chart.addSubtitle(new TextTitle("Titulo jajaja")); //chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 0, 1000, Color.white)); CategoryPlot plot = chart.getCategoryPlot(); plot.setBackgroundPaint(Color.white); plot.setRangeGridlinePaint(Color.DARK_GRAY); plot.setOutlineVisible(false); ChartPanel barChart = new ChartPanel(chart); barChart.setBounds(panel.getVisibleRect()); //barChart.setPreferredSize(panelGrafica.getSize()); //barChart.setBounds(panel.getVisibleRect()); //Colores de Barras Paint[] 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) }; ((org.jfree.chart.renderer.category.BarRenderer) plot.getRenderer()) .setBarPainter(new StandardBarPainter()); // Quita Efecto luz BarRenderer renderer = new BarRenderer(colors); renderer.setColor(plot, data); //Numeros sobre barras CategoryItemRenderer renderizar; renderizar = plot.getRenderer(); renderizar.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator()); renderizar.setBaseItemLabelsVisible(true); renderizar.setItemLabelFont(new Font("Roboto", 0, 18)); //Valores eje Y ValueAxis rangeAxis = plot.getRangeAxis(); rangeAxis.setLabelFont(new Font("Roboto", 0, 17)); rangeAxis.setTickLabelFont(new Font("Roboto", 0, 17)); //Diseo categorias org.jfree.chart.axis.CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setLabelFont(new Font("Roboto", 0, 17)); domainAxis.setTickLabelFont(new Font("Roboto", 0, 17)); /*domainAxis.setTickLabelPaint(new Color(160, 163, 165)); domainAxis.setCategoryLabelPositionOffset(4); domainAxis.setLowerMargin(0); domainAxis.setUpperMargin(0); domainAxis.setCategoryMargin(0.2); */ //Leyendas LegendTitle legend = chart.getLegend(); legend.setPosition(RectangleEdge.BOTTOM); Font nwfont = new Font("Roboto", 0, 18); legend.setItemFont(nwfont); legend.setBorder(0, 0, 0, 0); legend.setBackgroundPaint(Color.WHITE); legend.setItemLabelPadding(new RectangleInsets(8, 8, 8, 15)); /* plot.setLegendLabelGenerator(new StandardPieSectionLabelGenerator("{1} {0}")); plot.setLegendItemShape(new Rectangle(25, 25)); */ // Pintar panel.removeAll(); panel.add(barChart); panel.repaint(); panel.revalidate(); panelGrafica.repaint(); panelGrafica.revalidate(); }
From source file:lucee.runtime.tag.Chart.java
private void setLegend(JFreeChart chart, Plot plot, Font font) { if (!showlegend) return;/*from w ww . j av a 2s.com*/ Color bg = backgroundcolor == null ? databackgroundcolor : backgroundcolor; if (font == null) font = getFont(); LegendTitle legend = legendMultiLine ? new LegendTitle(plot, new ColumnArrangement(), new ColumnArrangement()) : new LegendTitle(plot); legend.setBackgroundPaint(bg); legend.setMargin(new RectangleInsets(1.0, 1.0, 1.0, 1.0)); legend.setFrame(new LineBorder()); legend.setPosition(RectangleEdge.BOTTOM); legend.setHorizontalAlignment(HorizontalAlignment.LEFT); legend.setWidth(chartwidth - 20);// geht nicht legend.setItemFont(font); legend.setItemPaint(foregroundcolor); //RectangleInsets labelPadding; legend.setItemLabelPadding(new RectangleInsets(2, 2, 2, 2)); legend.setBorder(0, 0, 0, 0); legend.setLegendItemGraphicLocation(RectangleAnchor.TOP_LEFT); legend.setLegendItemGraphicPadding(new RectangleInsets(8, 10, 0, 0)); chart.addLegend(legend); }