List of usage examples for org.jfree.data.general DefaultPieDataset setValue
public void setValue(Comparable key, double value)
From source file:co.edu.eam.ingesoft.desarrollo.vista.gui.ReportesEstadisticas.java
private void jCBProgramaItemStateChanged(java.awt.event.ItemEvent evt) {// GEN-FIRST:event_jCBProgramaItemStateChanged try {/*from w w w . ja va 2 s.c o m*/ ChartPanel panel; Programa programa = (Programa) jCBPrograma.getSelectedItem(); List<InformacionLaboral> listaInfoLab = controlador.listaEgresadosPorOcupacion(programa); jPanelEgresadosPorOcup.removeAll(); double empleado = 0; double desempleado = 0; double independiente = 0; double empresario = 0; int contadorEmpleado = 0; int contadordDesempleado = 0; int contadorIndependiente = 0; int contadorEmpresario = 0; for (int i = 0; i < listaInfoLab.size(); i++) { if (listaInfoLab.get(i).getSituacionActual().equals("Empleado")) { contadorEmpleado++; } else if (listaInfoLab.get(i).getSituacionActual().equals("Desempleado")) { contadordDesempleado++; } else if (listaInfoLab.get(i).getSituacionActual().equals("Independiente")) { contadorIndependiente++; } else if (listaInfoLab.get(i).getSituacionActual().equals("Empresario")) { contadorEmpresario++; } else { JOptionPane.showMessageDialog(null, "No hay empleados registrados"); } empleado = (contadorEmpleado * 100) / listaInfoLab.size(); desempleado = (contadordDesempleado * 100) / listaInfoLab.size(); independiente = (contadorIndependiente * 100) / listaInfoLab.size(); empresario = (contadorEmpresario * 100) / listaInfoLab.size(); } DefaultPieDataset ds = new DefaultPieDataset(); ds.setValue("Empleado: " + empleado + "%", empleado); ds.setValue("Desempleado: " + desempleado + "%", desempleado); ds.setValue("Independiente: " + independiente + "%", independiente); ds.setValue("Empresario: " + empresario + "%", empresario); JFreeChart jf = ChartFactory.createPieChart3D("Reporte de egresados por tipo de ocupacin", ds, true, true, true); panel = new ChartPanel(jf); panel.setBounds(20, 50, 720, 350); jPanelEgresadosPorOcup.add(panel); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:com.etest.view.tq.charts.GraphicalInventoryPieChart.java
public GraphicalInventoryPieChart(int curriculumId) { this.curriculumId = curriculumId; setModal(true);/* ww w . j av a2s . c o m*/ int percentage = 0; VerticalLayout v = new VerticalLayout(); DefaultPieDataset dataset = new DefaultPieDataset(); for (BloomsClass b : BloomsClass.values()) { percentage = (int) calculatePercentageOfItemsPerBloomsClass( rs.getTotalItemsBySubject(getCurriculumId()), rs.getTotalItemsByBloomsCass(getCurriculumId(), tq.getBloomsClassId(b.toString()))); dataset.setValue(b + " " + percentage + "%", percentage); } JFreeChart chart = ChartFactory.createPieChart( "Inventory of Items for " + cs.getCurriculumById(getCurriculumId()).getSubject(), dataset, true, true, false); // JFreeChartWrapper wrapper = new JFreeChartWrapper(chart){ // // @Override // public void attach(){ // super.attach(); // setResource("src", getSource()); // } // // }; v.addComponent(new ReportChartWrapper(chart, null, null)); v.setWidthUndefined(); v.setHeightUndefined(); setContent(v); getContent().setWidthUndefined(); getContent().setHeightUndefined(); center(); }
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 2s. 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:com.xpn.xwiki.plugin.charts.plots.PiePlotFactory.java
public Plot create(DataSource dataSource, ChartParams params) throws GenerateException, DataSourceException { DefaultPieDataset dataset = new DefaultPieDataset(); String dataSeries = params.getString(ChartParams.SERIES); if (dataSeries.equals("columns")) { for (int row = 0; row < dataSource.getRowCount(); row++) { if (dataSource.hasHeaderColumn()) { String category = dataSource.getHeaderColumnValue(row); dataset.setValue(category, dataSource.getCell(row, 0)); } else { dataset.setValue("Category " + (row + 1), dataSource.getCell(row, 0)); }/*from www .ja v a 2s. c om*/ } } else if (dataSeries.equals("rows")) { for (int column = 0; column < dataSource.getColumnCount(); column++) { if (dataSource.hasHeaderRow()) { String category = dataSource.getHeaderRowValue(column); dataset.setValue(category, dataSource.getCell(0, column)); } else { dataset.setValue("Category " + (column + 1), dataSource.getCell(0, column)); } } } else { throw new GenerateException("Invalid series parameter:" + dataSeries); } Class plotClass = params.getClass(ChartParams.RENDERER); PiePlot plot; if (plotClass != null) { try { Constructor ctor = plotClass.getConstructor(new Class[] { PieDataset.class }); plot = (PiePlot) ctor.newInstance(new Object[] { dataset }); } catch (Throwable e) { throw new GenerateException(e); } } else { plot = new PiePlot(dataset); } ChartCustomizer.customizePiePlot(plot, params); return plot; }
From source file:com.indicator_engine.controller.GraphController.java
@RequestMapping(value = "/jgraph", method = RequestMethod.GET) public void processGraphRequests(@RequestParam(value = "indicator", required = false) String indicatorName, @RequestParam(value = "runFromMemory", defaultValue = "false", required = false) String runFromMemory, @RequestParam(value = "bean", defaultValue = "false", required = false) String runFromContextBean, @RequestParam(value = "default", defaultValue = "false", required = false) String defaultRun, HttpServletResponse response) {/* w w w. j a va 2 s.com*/ response.setContentType("image/png"); if (defaultRun.equals("true")) { DefaultPieDataset dataSet = new DefaultPieDataset(); dataSet.setValue("One", new Double(43.2)); dataSet.setValue("Two", new Double(10.0)); dataSet.setValue("Three", new Double(27.5)); dataSet.setValue("Four", new Double(17.5)); dataSet.setValue("Five", new Double(11.0)); dataSet.setValue("Six", new Double(19.4)); JFreeChart chart = createPieChart(dataSet, "Sample Graph"); try { ChartUtilities.writeChartAsPNG(response.getOutputStream(), chart, 750, 400); response.getOutputStream().close(); } catch (IOException ex) { ex.printStackTrace(); } } else if (runFromContextBean.equals("true")) { EntitySpecification entitySpecificationBean = (EntitySpecification) appContext .getBean("entitySpecifications"); if (entitySpecificationBean.getSelectedChartType().equals("Pie")) { PieDataset pdSet = createDataSet(entitySpecificationBean); JFreeChart chart = createPieChart(pdSet, entitySpecificationBean.getQuestionName()); try { ChartUtilities.writeChartAsPNG(response.getOutputStream(), chart, 750, 400); response.getOutputStream().close(); } catch (IOException ex) { ex.printStackTrace(); } } else if (entitySpecificationBean.getSelectedChartType().equals("Bar")) { CategoryDataset dataset = createCategoryDataSet(entitySpecificationBean); JFreeChart chart = createBarChart(dataset, entitySpecificationBean.getQuestionName()); try { ChartUtilities.writeChartAsPNG(response.getOutputStream(), chart, 750, 400); response.getOutputStream().close(); } catch (IOException ex) { ex.printStackTrace(); } } } else if (runFromMemory.equals("true")) { EntitySpecification entitySpecificationBean = (EntitySpecification) appContext .getBean("entitySpecifications"); GLAIndicator glaIndicator = new GLAIndicator(); GLAIndicatorProps glaIndicatorProps = new GLAIndicatorProps(); for (Iterator<GenQuery> genQuery = entitySpecificationBean.getQuestionsContainer().getGenQueries() .iterator(); genQuery.hasNext();) { GenQuery agenQuery = genQuery.next(); if (agenQuery.getIndicatorName().equals(indicatorName)) { glaIndicator.setHql(agenQuery.getQuery()); glaIndicator.setIndicator_name(agenQuery.getIndicatorName()); glaIndicatorProps.setChartType(agenQuery.getGenIndicatorProps().getChartType()); glaIndicatorProps.setComposite(agenQuery.getGenIndicatorProps().isComposite()); glaIndicator.setGlaIndicatorProps(glaIndicatorProps); } } if (glaIndicator.getGlaIndicatorProps().getChartType().equals("Pie")) { PieDataset pdSet = createDataSet(glaIndicator); JFreeChart chart = createPieChart(pdSet, glaIndicator.getIndicator_name()); try { ChartUtilities.writeChartAsPNG(response.getOutputStream(), chart, 750, 400); response.getOutputStream().close(); } catch (IOException ex) { ex.printStackTrace(); } } else if (glaIndicator.getGlaIndicatorProps().getChartType().equals("Bar")) { CategoryDataset dataset = createCategoryDataSet(glaIndicator); JFreeChart chart = createBarChart(dataset, glaIndicator.getIndicator_name()); try { ChartUtilities.writeChartAsPNG(response.getOutputStream(), chart, 750, 400); response.getOutputStream().close(); } catch (IOException ex) { ex.printStackTrace(); } } } else { GLAIndicatorDao glaIndicatorBean = (GLAIndicatorDao) appContext.getBean("glaIndicator"); GLAQuestionDao glaQuestionBean = (GLAQuestionDao) appContext.getBean("glaQuestions"); long indicatorID = glaIndicatorBean.findIndicatorID(indicatorName); GLAIndicator glaIndicator = glaIndicatorBean.loadByIndicatorID(indicatorID); if (glaIndicator.getGlaIndicatorProps().getChartType().equals("Pie")) { PieDataset pdSet = createDataSet(glaIndicator); JFreeChart chart = createPieChart(pdSet, glaIndicator.getIndicator_name()); try { ChartUtilities.writeChartAsPNG(response.getOutputStream(), chart, 750, 400); glaIndicatorBean.updateStatistics(indicatorID); long questionID = glaIndicatorBean.findQuestionID(indicatorID); glaQuestionBean.updateStatistics(questionID); response.getOutputStream().close(); } catch (IOException ex) { ex.printStackTrace(); } } else if (glaIndicator.getGlaIndicatorProps().getChartType().equals("Bar")) { CategoryDataset dataset = createCategoryDataSet(glaIndicator); JFreeChart chart = createBarChart(dataset, glaIndicator.getIndicator_name()); try { ChartUtilities.writeChartAsPNG(response.getOutputStream(), chart, 750, 400); glaIndicatorBean.updateStatistics(indicatorID); long questionID = glaIndicatorBean.findQuestionID(indicatorID); glaQuestionBean.updateStatistics(questionID); response.getOutputStream().close(); } catch (IOException ex) { ex.printStackTrace(); } } } }
From source file:lu.uni.lassy.excalibur.examples.icrash.dev.web.java.views.AdminAuthView.java
private void drawGraph(String name, Integer[] responses) { DefaultPieDataset dataset = new DefaultPieDataset(); dataset.setValue("Answer 1", responses[0].doubleValue()); dataset.setValue("Answer 2", responses[1].doubleValue()); dataset.setValue("Answer 3", responses[2].doubleValue()); JFreeChart chart = ChartFactory.createPieChart3D(name, dataset, true, true, false); PiePlot3D plot = (PiePlot3D) chart.getPlot(); plot.setForegroundAlpha(0.5f);/*from ww w . j ava 2 s .c o m*/ plot.setCircular(true); final JFreeChartWrapper chartP = new JFreeChartWrapper(chart); GridLayout diagramLayout = new GridLayout(2, 2); diagramLayout.setSpacing(true); diagramLayout.setMargin(true); diagramLayout.setSizeFull(); diagramLayout.addComponent(chartP); diagramPanel.setContent(diagramLayout); }
From source file:msi.gama.outputs.layers.charts.ChartJFreeChartOutputPie.java
@Override protected void resetSerie(final IScope scope, final String serieid) { // TODO Auto-generated method stub final ChartDataSeries dataserie = chartdataset.getDataSeries(scope, serieid); final DefaultPieDataset serie = (DefaultPieDataset) jfreedataset.get(0); final ArrayList<Double> YValues = dataserie.getYValues(scope); if (YValues.size() > 0) { // TODO Hack to speed up, change!!! serie.setValue(serieid, YValues.get(YValues.size() - 1)); }/*w ww .jav a 2s .c om*/ this.resetRenderer(scope, serieid); }
From source file:net.sourceforge.atunes.kernel.controllers.stats.StatsDialogController.java
private void setGeneralChart() { DefaultPieDataset dataset = new DefaultPieDataset(); int different = HandlerProxy.getRepositoryHandler().getDifferentSongsPlayed(); int total = HandlerProxy.getRepositoryHandler().getSongs().size(); dataset.setValue(LanguageTool.getString("SONGS_PLAYED"), different); dataset.setValue(LanguageTool.getString("SONGS_NEVER_PLAYED"), total - different); JFreeChart chart = ChartFactory.createPieChart3D(LanguageTool.getString("SONGS_PLAYED"), dataset, false, false, false);/*www.j a v a2s . c om*/ chart.getTitle().setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11)); chart.setBackgroundPaint(new GradientPaint(0, 0, ColorDefinitions.GENERAL_NON_PANEL_TOP_GRADIENT_COLOR, 0, 200, ColorDefinitions.GENERAL_NON_PANEL_BOTTOM_GRADIENT_COLOR)); chart.setPadding(new RectangleInsets(5, 0, 0, 0)); chart.getPlot() .setBackgroundPaint(new GradientPaint(0, 0, ColorDefinitions.GENERAL_NON_PANEL_TOP_GRADIENT_COLOR, 0, 200, ColorDefinitions.GENERAL_NON_PANEL_BOTTOM_GRADIENT_COLOR)); DefaultDrawingSupplier drawingSupplier = new DefaultDrawingSupplier( new Paint[] { new Color(0, 1, 0, 0.6f), new Color(1, 0, 0, 0.6f) }, new Paint[] { new Color(0, 1, 0, 0.4f), new Color(1, 0, 0, 0.4f) }, DefaultDrawingSupplier.DEFAULT_STROKE_SEQUENCE, DefaultDrawingSupplier.DEFAULT_STROKE_SEQUENCE, DefaultDrawingSupplier.DEFAULT_SHAPE_SEQUENCE); chart.getPlot().setDrawingSupplier(drawingSupplier); ((StatsDialog) frameControlled).getGeneralChart() .setIcon(new ImageIcon(chart.createBufferedImage(710, 250))); }
From source file:GUI.MagasinStats.java
/** * Creates new form InterfaceEtatDesVehiculesDansUneAnne *///from w w w.j av a 2 s .com public MagasinStats() { initComponents(); CarDAO carDao = new CarDAO(); DefaultPieDataset chartData = new DefaultPieDataset(); for (Car car : carDao.findAllCars()) { ArticleDAO articleDao = new ArticleDAO(); chartData.setValue(car.getImmatriculation(), articleDao.sumArticlesByCar(car)); } // This will create the dataset PieDataset dataset = (PieDataset) chartData; // based on the dataset we create the chart JFreeChart chart = createChart(dataset, "Cars stats"); // we put the chart into a panel ChartPanel chartPanel = new ChartPanel(chart); // default size chartPanel.setPreferredSize(new java.awt.Dimension(500, 270)); // add it to our application setContentPane(chartPanel); }
From source file:GUILayer.CustomerStatsByGroup.java
protected PieDataset createTop10ProductsSold() { DefaultPieDataset result = new DefaultPieDataset(); ProductCtrl prdCtrl = new ProductCtrl(); ArrayList<Product> products = prdCtrl.getProducts(); Collections.sort(products, (Product o1, Product o2) -> o1.compareTo(o2)); for (Product pr : products) { int n = 0; if (n != 10) { result.setValue(pr.getName(), pr.getSoldProducts()); n++;/*from w w w .j ava 2s .c om*/ } } return result; }