List of usage examples for org.jfree.chart ChartFactory createRingChart
public static JFreeChart createRingChart(String title, PieDataset dataset, boolean legend, boolean tooltips, boolean urls)
From source file:br.com.OCTur.view.InfograficoController.java
private BufferedImage participacao() { DefaultPieDataset dpdDados = new DefaultPieDataset(); hoteis = new ArrayList<>(); for (Hotel hotel : new HotelDAO().pegarTodos()) { List<Reserva> reservas = new ReservaDAO().pegarPorHotelInicioFim(hotel, inicio, fim); double total = 0; for (Reserva reserva : reservas) { long dias = (reserva.getFim().getTime() - reserva.getInicio().getTime()) / 1000 / 60 / 60 / 24; if (dias <= 0) { dias = 1;//w w w.ja va2 s .c om } total += (reserva.getQuarto().getOrcamento().getPreco() * dias); } hoteis.add(new EntidadeGrafico<>(hotel, total)); } hoteis.sort((EntidadeGrafico<Hotel> o1, EntidadeGrafico<Hotel> o2) -> Double.compare(o1.getValue(), o2.getValue()) * -1); for (EntidadeGrafico<Hotel> entidadeGrafico : hoteis.subList(0, hoteis.size() > 4 ? 4 : hoteis.size())) { dpdDados.setValue(entidadeGrafico.toString(), entidadeGrafico.getValue()); } if (hoteis.size() > 4) { dpdDados.setValue("Outros", hoteis.subList(4, hoteis.size()).stream().mapToDouble(EntidadeGrafico::getValue).sum()); } JFreeChart jFreeChart = ChartFactory.createRingChart("", dpdDados, true, false, Locale.ROOT); PiePlot piePlot = (PiePlot) jFreeChart.getPlot(); piePlot.setLabelGenerator(new StandardPieSectionLabelGenerator("{2}")); return jFreeChart.createBufferedImage(175, 252); }
From source file:net.sf.jsfcomp.chartcreator.utils.ChartUtils.java
public static JFreeChart createChartWithPieDataSet(ChartData chartData) { PieDataset dataset = (PieDataset) chartData.getDatasource(); String type = chartData.getType(); boolean legend = chartData.isLegend(); JFreeChart chart = null;//from w ww.j a v a2 s .co m if (type.equalsIgnoreCase("pie")) { if (chartData.isChart3d()) { chart = ChartFactory.createPieChart3D("", dataset, legend, true, false); PiePlot3D plot = (PiePlot3D) chart.getPlot(); plot.setDepthFactor((float) chartData.getDepth() / 100); } else { chart = ChartFactory.createPieChart("", dataset, legend, true, false); } } else if (type.equalsIgnoreCase("ring")) { chart = ChartFactory.createRingChart("", dataset, legend, true, false); } PiePlot plot = (PiePlot) chart.getPlot(); plot.setStartAngle((float) chartData.getStartAngle()); if (chartData.getGenerateMap() != null) plot.setURLGenerator(new StandardPieURLGenerator("")); setPieSectionColors(chart, chartData); return chart; }
From source file:de.forsthaus.webui.customer.CustomerChartCtrl.java
/** * onClick button Ring Chart. <br> * //ww w . j av a2 s . co m * @param event * @throws IOException */ public void onClick$button_CustomerChart_RingChart(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.createRingChart(title, pieDataset, true, true, true); RingPlot plot = (RingPlot) 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("Ring Chart", bytes); Image img = new Image(); img.setContent(chartImage); img.setParent(this.div_chartArea); } else { div_chartArea.getChildren().clear(); final Label label = new Label(); label.setValue("This customer have no data for showing in a chart!"); label.setParent(div_chartArea); } }
From source file:org.adempiere.apps.graph.ChartBuilder.java
private JFreeChart createRingChart() { final JFreeChart chart = ChartFactory.createRingChart(chartModel.get_Translation(MChart.COLUMNNAME_Name), getPieDataset(), chartModel.isDisplayLegend(), true, true); return chart; }
From source file:msi.gama.outputs.layers.ChartLayerStatement.java
private void createChart(final IScope scope) { switch (type) { case SERIES_CHART: { chart = ChartFactory.createXYLineChart(getName(), "time", "", null, PlotOrientation.VERTICAL, true, false, false);//from www . j av a 2s . co m break; } case PIE_CHART: { if (style.equals(IKeyword.THREE_D)) { chart = ChartFactory.createPieChart3D(getName(), null, false, true, false); } else if (style.equals(IKeyword.RING)) { chart = ChartFactory.createRingChart(getName(), null, false, true, false); } else if (style.equals(IKeyword.EXPLODED)) { chart = ChartFactory.createPieChart(getName(), null, false, true, false); exploded = true; } else { chart = ChartFactory.createPieChart(getName(), null, false, true, false); } break; } case HISTOGRAM_CHART: { if (style.equals(IKeyword.THREE_D)) { chart = ChartFactory.createBarChart3D(getName(), null, null, null, PlotOrientation.VERTICAL, true, true, false); } else if (style.equals(IKeyword.STACK)) { chart = ChartFactory.createStackedBarChart(getName(), null, null, null, PlotOrientation.VERTICAL, true, true, false); } else { chart = ChartFactory.createBarChart(getName(), null, null, null, PlotOrientation.VERTICAL, true, true, false); } break; } case XY_CHART: chart = ChartFactory.createXYLineChart(getName(), "", "", null, PlotOrientation.VERTICAL, true, false, false); break; case SCATTER_CHART: chart = ChartFactory.createXYLineChart(getName(), "", "", null, PlotOrientation.VERTICAL, true, false, false); break; case BOX_WHISKER_CHART: { chart = ChartFactory.createBoxAndWhiskerChart(getName(), "Time", "Value", (BoxAndWhiskerCategoryDataset) dataset, true); chart.setBackgroundPaint(new Color(249, 231, 236)); break; } } Plot plot = chart.getPlot(); chart.getTitle().setFont(getTitleFont()); if (backgroundColor == null) { plot.setBackgroundPaint(null); chart.setBackgroundPaint(null); chart.setBorderPaint(null); if (chart.getLegend() != null) { chart.getLegend().setBackgroundPaint(null); } } else { Color bg = backgroundColor; chart.setBackgroundPaint(bg); plot.setBackgroundPaint(bg); chart.setBorderPaint(bg); if (chart.getLegend() != null) { chart.getLegend().setBackgroundPaint(bg); } } // chart.getLegend().setItemPaint(axesColor); // chart.getLegend().setBackgroundPaint(null); if (plot instanceof CategoryPlot) { final CategoryPlot pp = (CategoryPlot) chart.getPlot(); pp.setDomainGridlinePaint(axesColor); pp.setRangeGridlinePaint(axesColor); // plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); // plot.setDomainCrosshairVisible(true); pp.setRangeCrosshairVisible(true); } else if (plot instanceof XYPlot) { final XYPlot pp = (XYPlot) chart.getPlot(); pp.setDomainGridlinePaint(axesColor); pp.setRangeGridlinePaint(axesColor); pp.setDomainCrosshairPaint(axesColor); pp.setRangeCrosshairPaint(axesColor); pp.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); pp.setDomainCrosshairVisible(true); pp.setRangeCrosshairVisible(true); } }
From source file:edu.ucla.stat.SOCR.chart.ChartGenerator_JTable.java
private JFreeChart createPieChart(String titleLabel, PieDataset dataset) { // System.out.println("rotation="+rotation); if (dimension.equalsIgnoreCase("3D")) { JFreeChart chart = ChartFactory.createPieChart3D(titleLabel, // chart title dataset, // data true, // include legend true, false);/*w w w. jav a2s.co m*/ PiePlot3D plot = (PiePlot3D) chart.getPlot(); if (rotation.equalsIgnoreCase("clockwise")) { plot.setStartAngle(290); plot.setDirection(Rotation.CLOCKWISE); Rotator rotator = new Rotator(plot); rotator.start(); } else if (rotation.equalsIgnoreCase("counter_clockwise")) { plot.setStartAngle(290); plot.setDirection(Rotation.ANTICLOCKWISE); Rotator rotator = new Rotator(plot); rotator.start(); } plot.setForegroundAlpha(0.5f); plot.setNoDataMessage("No data to display"); return chart; } //end of 3D //2D ring if (rotation.equalsIgnoreCase("ring")) { JFreeChart chart = ChartFactory.createRingChart(titleLabel, // chart title dataset, // data false, // include legend true, false); RingPlot plot = (RingPlot) chart.getPlot(); plot.setLabelFont(new Font("SansSerif", Font.PLAIN, 12)); plot.setNoDataMessage("No data available"); plot.setCircular(false); plot.setLabelGap(0.02); return chart; } //2D JFreeChart chart = ChartFactory.createPieChart(titleLabel, // chart title dataset, // data true, // include legend true, false); TextTitle title = chart.getTitle(); title.setToolTipText("A title tooltip!"); PiePlot plot = (PiePlot) chart.getPlot(); if (rotation.equalsIgnoreCase("clockwise")) { plot.setStartAngle(290); plot.setDirection(Rotation.CLOCKWISE); Rotator rotator = new Rotator(plot); rotator.start(); } else if (rotation.equalsIgnoreCase("counter_clockwise")) { plot.setStartAngle(290); plot.setDirection(Rotation.ANTICLOCKWISE); Rotator rotator = new Rotator(plot); rotator.start(); } plot.setLabelFont(new Font("SansSerif", Font.PLAIN, 12)); plot.setNoDataMessage("No data available"); plot.setCircular(false); plot.setLabelGap(0.02); return chart; }