List of usage examples for org.jfree.chart.plot PiePlot3D setLabelGenerator
public void setLabelGenerator(PieSectionLabelGenerator generator)
From source file:com.globalsight.util.JfreeCharUtil.java
public static void drawPieChart3D(String title, Map<String, Double> datas, File OutFile) { PieDataset dataset = buildDatas(datas); JFreeChart chart = ChartFactory.createPieChart3D(title, dataset, true, true, false); PiePlot3D plot = (PiePlot3D) chart.getPlot(); plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0}={1}({2})", NumberFormat.getNumberInstance(), new DecimalFormat("0.00%"))); plot.setLegendLabelGenerator(new StandardPieSectionLabelGenerator("{0}={1}({2})")); chart.setBackgroundPaint(Color.white); plot.setForegroundAlpha(0.7f);/*from ww w . j a va 2s . com*/ plot.setCircular(true); TextTitle textTitle = new TextTitle(title); Font font = new Font(textTitle.getFont().getName(), Font.CENTER_BASELINE, 20); textTitle.setFont(font); chart.setTitle(textTitle); FileOutputStream fos_jpg = null; try { fos_jpg = new FileOutputStream(OutFile); ChartUtilities.writeChartAsJPEG(fos_jpg, 1, chart, 640, 480, null); fos_jpg.close(); } catch (Exception e) { s_logger.error(e.getMessage(), e); } }
From source file:de.aidger.view.utils.Charts.java
/** * Creates a 3D pie chart.//from w ww . j ava 2s. co m * * @param title * the diagram title * @param dataset * the dataset. * @param width * the width of the chart as image * @param height * the height of the chart as image * * @return the 3D pie chart as image */ public static ImageIcon createPieChart3D(String title, PieDataset dataset, int width, int height) { JFreeChart chart = ChartFactory.createPieChart3D(title, dataset, true, true, false); Font titleFont = UIManager.getFont("TitledBorder.font"); chart.setBackgroundPaint(null); chart.getLegend().setBackgroundPaint(null); chart.getTitle().setFont(new Font(titleFont.getName(), titleFont.getStyle(), 14)); chart.getTitle().setPaint(UIManager.getColor("TitledBorder.titleColor")); chart.setBorderPaint(null); chart.getLegend().setBorder(0, 0, 0, 0); PiePlot3D plot = (PiePlot3D) chart.getPlot(); plot.setStartAngle(290); plot.setForegroundAlpha(0.9f); plot.setDirection(Rotation.CLOCKWISE); plot.setNoDataMessage(_("No data to display.")); plot.setLabelGenerator(null); plot.setInsets(new RectangleInsets(10, 1, 5, 1)); plot.setBackgroundPaint(null); plot.setOutlineVisible(false); plot.setDarkerSides(true); return new ImageIcon(chart.createBufferedImage(width, height)); }
From source file:edu.coeia.charts.PieChartPanel.java
private static JFreeChart createChart(final PieDataset dataset, String str) { final JFreeChart chart = ChartFactory.createPieChart3D(str, // chart title dataset, // data true, // include legend true, false);//from w ww . ja va 2 s . c o m final PiePlot3D plot = (PiePlot3D) chart.getPlot(); plot.setStartAngle(290); plot.setDirection(Rotation.CLOCKWISE); plot.setForegroundAlpha(0.5f); StandardPieSectionLabelGenerator labelGenerator = new StandardPieSectionLabelGenerator("{0} {2}"); plot.setLabelGenerator(labelGenerator); plot.setNoDataMessage("No data to display"); return chart; }
From source file:com.ewcms.plugin.report.generate.service.chart.ChartGenerationService.java
/** * 3D//from w ww . ja v a 2 s . c o m * * @param title * @param titleFont * @param data ?? * @param order * @param legend * @param tooltips ???? * @param urls ??URL * @param urlGenerator * * @return */ public static JFreeChart create3DPieChart(String title, java.awt.Font titleFont, CategoryDataset data, TableOrder order, boolean legend, boolean tooltips, boolean urls, PieURLGenerator urlGenerator) { MultiplePiePlot plot = new MultiplePiePlot(data); plot.setDataExtractOrder(order); // plot.setOutlineStroke(null); JFreeChart pieChart = new JFreeChart(new PiePlot3D(null)); pieChart.setBackgroundPaint(null); plot.setPieChart(pieChart); PiePlot3D pp = (PiePlot3D) plot.getPieChart().getPlot(); pp.setBackgroundPaint(null); // pp.setInsets(new Insets(0, 5, 5, 5)); pp.setOutlineStroke(null); PieToolTipGenerator tooltipGenerator = null; if (tooltips) { tooltipGenerator = new StandardPieToolTipGenerator(); } if (!urls) { urlGenerator = null; } pp.setToolTipGenerator(tooltipGenerator); pp.setLabelGenerator(null); pp.setURLGenerator(urlGenerator); JFreeChart chart = new JFreeChart(title, titleFont, plot, legend); return chart; }
From source file:com.tonbeller.jpivot.chart.ChartFactory.java
/** * Creates a sample dataset for the demo. * // w ww . j ava 2 s . c om * @return A sample dataset. */ public static JFreeChart create3DPieChart(String title, java.awt.Font titleFont, CategoryDataset data, TableOrder order, boolean legend, boolean tooltips, boolean urls, PieURLGenerator urlGenerator) { MultiplePiePlot plot = new MultiplePiePlot(data); plot.setDataExtractOrder(order); //plot.setOutlineStroke(null); JFreeChart pieChart = new JFreeChart(new PiePlot3D(null)); pieChart.setBackgroundPaint(null); plot.setPieChart(pieChart); PiePlot3D pp = (PiePlot3D) plot.getPieChart().getPlot(); pp.setBackgroundPaint(null); //pp.setInsets(new Insets(0, 5, 5, 5)); // no outline around each piechart pp.setOutlineStroke(null); PieToolTipGenerator tooltipGenerator = null; if (tooltips) { tooltipGenerator = new StandardPieToolTipGenerator(); } if (!urls) { urlGenerator = null; } pp.setToolTipGenerator(tooltipGenerator); pp.setLabelGenerator(null); pp.setURLGenerator(urlGenerator); JFreeChart chart = new JFreeChart(title, titleFont, plot, legend); return chart; }
From source file:de.xirp.chart.ChartManager.java
/** * Returns a pie chart. The chart is generated from the given * {@link de.xirp.db.Record} and key array. The flag * <code>relative</code> indicated whether or not relative * values should be used./* w w w. j ava 2 s . c o m*/ * * @param record * The record containing the data. * @param keys * The keys to use. * @param relative * Flag indicating if relative values should be used. * @return A pie chart. * @see org.jfree.chart.JFreeChart * @see de.xirp.db.Record */ private static JFreeChart createPieChart(Record record, String[] keys, boolean relative) { String chartTitle = (relative ? I18n.getString("ChartManager.text.relative") //$NON-NLS-1$ : I18n.getString("ChartManager.text.absolute")) //$NON-NLS-1$ + I18n.getString("ChartManager.text.occurencesOfKey") + record.getName() + ": "; //$NON-NLS-1$ //$NON-NLS-2$ DefaultPieDataset dataset = new DefaultPieDataset(); Map<String, Long> values; values = ChartDatabaseUtil.getValuesForRecord(record, keys, relative); for (String s : values.keySet()) { dataset.setValue(s, values.get(s)); } JFreeChart chart; if (options.is(OptionName.THREE_D)) { chart = ChartFactory.createPieChart3D(chartTitle, dataset, true, true, false); PiePlot3D plot = (PiePlot3D) chart.getPlot(); plot.setStartAngle(290); plot.setDirection(Rotation.CLOCKWISE); plot.setForegroundAlpha(0.5f); plot.setNoDataMessage(NO_DATA_AVAILABLE); plot.setLabelGenerator(new CustomLabelGenerator(options)); } else { chart = ChartFactory.createPieChart(chartTitle, dataset, true, true, false); PiePlot plot = (PiePlot) chart.getPlot(); plot.setSectionOutlinesVisible(true); plot.setNoDataMessage(NO_DATA_AVAILABLE); plot.setCircular(false); plot.setLabelGap(0.02); plot.setLabelGenerator(new CustomLabelGenerator(options)); } exportAutomatically(null, chart); return chart; }
From source file:br.com.OCTur.view.GraficoController.java
@Override public void initialize(URL url, ResourceBundle rb) { fornecedor = new FornecedorDAO().pegarPorEmpresa(Sessao.pessoa.getEmpresa()); snCategoriasMaisVendida = new SwingNode(); snInteressePorArtesanato = new SwingNode(); snProdutosMaisAntigos = new SwingNode(); spCategoriaMaisVendida.setContent(snCategoriasMaisVendida); spInteressePorArtesanato.setContent(snInteressePorArtesanato); spProdutosMaisAntigos.setContent(snProdutosMaisAntigos); DefaultPieDataset dpdDados = new DefaultPieDataset(); for (CategoriaProduto categoriaProduto : new CategoriaProdutoDAO().pegarTodos()) { List<CompraItem> compraitem = new CompraItemDAO().pegarPorFonecedorCategoria(fornecedor, categoriaProduto);// w w w. j a v a 2 s. c o m dpdDados.setValue(categoriaProduto.toString(), compraitem.size()); } JFreeChart jFreeChart = ChartFactory.createPieChart3D( ControlTranducao.traduzirPalavra("CATEGORIASMAISVENDIDAS"), dpdDados, false, false, Locale.ROOT); PiePlot3D piePlot3D = (PiePlot3D) jFreeChart.getPlot(); piePlot3D.setLabelGenerator(new StandardPieSectionLabelGenerator("{0}\n{2}")); ChartPanel categoriaMaisVendida = new ChartPanel(jFreeChart); Platform.runLater(() -> { snCategoriasMaisVendida.setContent(categoriaMaisVendida); }); DefaultCategoryDataset dcdDados = new DefaultCategoryDataset(); for (int i = Calendar.getInstance().get(Calendar.YEAR) - 10; i < Calendar.getInstance() .get(Calendar.YEAR); i++) { dcdDados.addValue(new Random().nextDouble() * 100000, "Interesse", String.valueOf(i)); } jFreeChart = ChartFactory.createLineChart( ControlTranducao.traduzirPalavra("interesse") + " " + ControlTranducao.traduzirPalavra("artesanato"), "", "", dcdDados, PlotOrientation.VERTICAL, false, false, false); ChartPanel interesseArtesanato = new ChartPanel(jFreeChart); Platform.runLater(() -> { snInteressePorArtesanato.setContent(interesseArtesanato); }); produto = new ArrayList<>(); for (Produto produto : new ProdutoDAO().pegarPorFornecedor(fornecedor)) { if (new CompraItemDAO().pegarPorProduto(produto).isEmpty()) { List<Item> itens = new ItemDAO().pegarPorProduto(produto); if (!itens.isEmpty()) { Item item = itens.get(0); long quantidade = (new Date().getTime() - item.getDatacadastro().getTime()) / 1000 / 60 / 60 / 24; this.produto.add(new EntidadeGrafico<>(produto, quantidade)); } } } slMeta.setMax(produto.stream().mapToDouble(EntidadeGrafico::getValue).max().orElse(0)); slMeta.valueProperty() .addListener((ObservableValue<? extends Number> observable, Number oldValue, Number newValue) -> { produtosMaisAntigos(); }); Platform.runLater(() -> { produtosMaisAntigos(); }); }
From source file:systeminformation.Chart.java
public JFreeChart create3DPieChart(PieDataset dataset) { JFreeChart chart = ChartFactory.createPieChart3D("", dataset, true, true, true); PiePlot3D p = (PiePlot3D) chart.getPlot(); PieSectionLabelGenerator gen = new StandardPieSectionLabelGenerator("{0}: {1} ({2})", new DecimalFormat("0"), new DecimalFormat("0%")); p.setLabelGenerator(gen); // p.setSimpleLabels(true); p.setForegroundAlpha(0.5f);/*w w w. j a va 2s . c o m*/ p.setBackgroundAlpha(0.2f); chart.setBackgroundPaint(Color.white); chart.setAntiAlias(true); chart.setBorderVisible(true); return chart; }
From source file:room.utilization.PieChart.java
private JFreeChart createChart(PieDataset dataset) { JFreeChart chart = null;/*from ww w .ja v a 2s. c o m*/ PieSectionLabelGenerator pl = null; PiePlot3D plot = null; chart = ChartFactory.createPieChart3D(chartTitle, dataset, true, true, false); pl = new StandardPieSectionLabelGenerator("{0} = {2}"); plot = (PiePlot3D) chart.getPlot(); plot.setLabelGenerator(pl); plot.setLabelFont(new Font("Helvatica", Font.BOLD, 10)); return chart; }
From source file:org.jfree.chart.demo.PieChart3DDemo3.java
/** * Creates a sample chart./*from w w w . j a v a2s. c o m*/ * * @param dataset the dataset. * * @return A chart. */ private JFreeChart createChart(final PieDataset dataset) { final JFreeChart chart = ChartFactory.createPieChart3D("Pie Chart 3D Demo 3", // chart title dataset, // data true, // include legend true, false); final PiePlot3D plot = (PiePlot3D) chart.getPlot(); plot.setStartAngle(290); plot.setDirection(Rotation.CLOCKWISE); plot.setForegroundAlpha(0.5f); plot.setNoDataMessage("No data to display"); plot.setLabelGenerator(null); return chart; }