List of usage examples for org.jfree.chart ChartFactory createPieChart3D
public static JFreeChart createPieChart3D(String title, PieDataset dataset, boolean legend, boolean tooltips, boolean urls)
From source file:UserInterface.ControlManagerRole.ControlManagerWorkAreaJPanel.java
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed // TODO add your handling code here: int co2Level = 0; int noxLevel = 0; int comboBoston = 0; int co2Level1 = 0; int noxLevel1 = 0; int comboNewYork = 0; for (Network network : system.getNetworkList()) { if (network.getName().equalsIgnoreCase("boston")) { for (Customer customer : network.getCustomerDirectory().getCustomerDirectory()) { for (Sensor sensor : customer.getSensorDirectory().getSensorDirectory()) { co2Level += sensor.getCurrentEmissionCO2(); noxLevel += sensor.getCurrentEmissionNOx(); }//from ww w. ja v a 2 s . co m } } } comboBoston = co2Level + noxLevel; for (Network network : system.getNetworkList()) { if (network.getName().equalsIgnoreCase("New York")) { for (Customer customer : network.getCustomerDirectory().getCustomerDirectory()) { for (Sensor sensor : customer.getSensorDirectory().getSensorDirectory()) { co2Level1 += sensor.getCurrentEmissionCO2(); noxLevel1 += sensor.getCurrentEmissionNOx(); } } } } comboNewYork = co2Level1 + noxLevel1; DefaultPieDataset dataset22 = new DefaultPieDataset(); dataset22.setValue("Fuel Emission by Boston", new Integer(comboBoston)); dataset22.setValue("Fuel Emission by New York ", new Integer(comboNewYork)); JFreeChart chart22 = ChartFactory.createPieChart3D("Comparison Chart ", // chart title dataset22, // data true, // include legend true, false); final PiePlot3D plot = (PiePlot3D) chart22.getPlot(); plot.setStartAngle(270); plot.setForegroundAlpha(0.60f); plot.setInteriorGap(0.02); ChartFrame frame33 = new ChartFrame("3D Pie Chart for EMission Comparisonbetween two networks", chart22); frame33.setVisible(true); frame33.setSize(500, 400); }
From source file:de.laures.cewolf.taglib.CewolfChartFactory.java
public static JFreeChart getChartInstance(String chartType, String title, String xAxisLabel, String yAxisLabel, Dataset data) throws ChartValidationException { // first check the dynamically registered chart types CewolfChartFactory factory = (CewolfChartFactory) factories.get(chartType); if (factory != null) { // custom factory found, use it return factory.getChartInstance(title, xAxisLabel, yAxisLabel, data); }/*from w w w .j a v a 2 s . c o m*/ switch (getChartTypeConstant(chartType)) { case XY: check(data, XYDataset.class, chartType); return ChartFactory.createXYLineChart(title, xAxisLabel, yAxisLabel, (XYDataset) data, PlotOrientation.VERTICAL, true, true, true); case PIE: check(data, PieDataset.class, chartType); return ChartFactory.createPieChart(title, (PieDataset) data, true, true, true); case AREA_XY: check(data, XYDataset.class, chartType); return ChartFactory.createXYAreaChart(title, xAxisLabel, yAxisLabel, (XYDataset) data, PlotOrientation.VERTICAL, true, false, false); case SCATTER: check(data, XYDataset.class, chartType); return ChartFactory.createScatterPlot(title, xAxisLabel, yAxisLabel, (XYDataset) data, PlotOrientation.VERTICAL, true, false, false); case AREA: check(data, CategoryDataset.class, chartType); return ChartFactory.createAreaChart(title, xAxisLabel, yAxisLabel, (CategoryDataset) data, PlotOrientation.VERTICAL, true, false, false); case HORIZONTAL_BAR: check(data, CategoryDataset.class, chartType); return ChartFactory.createBarChart(title, xAxisLabel, yAxisLabel, (CategoryDataset) data, PlotOrientation.HORIZONTAL, true, false, false); case HORIZONTAL_BAR_3D: check(data, CategoryDataset.class, chartType); return ChartFactory.createBarChart3D(title, xAxisLabel, yAxisLabel, (CategoryDataset) data, PlotOrientation.HORIZONTAL, true, false, false); case LINE: check(data, CategoryDataset.class, chartType); return ChartFactory.createLineChart(title, xAxisLabel, yAxisLabel, (CategoryDataset) data, PlotOrientation.VERTICAL, true, false, false); case STACKED_HORIZONTAL_BAR: check(data, CategoryDataset.class, chartType); return ChartFactory.createStackedBarChart(title, xAxisLabel, yAxisLabel, (CategoryDataset) data, PlotOrientation.HORIZONTAL, true, false, false); case STACKED_VERTICAL_BAR: check(data, CategoryDataset.class, chartType); return ChartFactory.createStackedBarChart(title, xAxisLabel, yAxisLabel, (CategoryDataset) data, PlotOrientation.VERTICAL, true, false, false); case STACKED_VERTICAL_BAR_3D: check(data, CategoryDataset.class, chartType); return ChartFactory.createStackedBarChart3D(title, xAxisLabel, yAxisLabel, (CategoryDataset) data, PlotOrientation.VERTICAL, true, false, false); case VERTICAL_BAR: check(data, CategoryDataset.class, chartType); return ChartFactory.createBarChart(title, xAxisLabel, yAxisLabel, (CategoryDataset) data, PlotOrientation.VERTICAL, true, false, false); case VERTICAL_BAR_3D: check(data, CategoryDataset.class, chartType); return ChartFactory.createBarChart3D(title, xAxisLabel, yAxisLabel, (CategoryDataset) data, PlotOrientation.VERTICAL, true, false, false); case TIME_SERIES: check(data, XYDataset.class, chartType); return ChartFactory.createTimeSeriesChart(title, xAxisLabel, yAxisLabel, (XYDataset) data, true, false, false); case CANDLE_STICK: check(data, OHLCDataset.class, chartType); return ChartFactory.createCandlestickChart(title, xAxisLabel, yAxisLabel, (OHLCDataset) data, true); case HIGH_LOW: check(data, OHLCDataset.class, chartType); return ChartFactory.createHighLowChart(title, xAxisLabel, yAxisLabel, (OHLCDataset) data, true); case GANTT: check(data, IntervalCategoryDataset.class, chartType); return ChartFactory.createGanttChart(title, xAxisLabel, yAxisLabel, (IntervalCategoryDataset) data, true, false, false); case WIND: check(data, WindDataset.class, chartType); return ChartFactory.createWindPlot(title, xAxisLabel, yAxisLabel, (WindDataset) data, true, false, false); //case SIGNAL : // check(data, SignalsDataset.class, chartType); // return ChartFactory.createSignalChart(title, xAxisLabel, yAxisLabel, (SignalsDataset) data, true); case VERRTICAL_XY_BAR: check(data, IntervalXYDataset.class, chartType); return ChartFactory.createXYBarChart(title, xAxisLabel, true, yAxisLabel, (IntervalXYDataset) data, PlotOrientation.VERTICAL, true, false, false); case PIE_3D: check(data, PieDataset.class, chartType); return ChartFactory.createPieChart3D(title, (PieDataset) data, true, false, false); case METER: check(data, ValueDataset.class, chartType); MeterPlot plot = new MeterPlot((ValueDataset) data); JFreeChart chart = new JFreeChart(title, plot); return chart; case STACKED_AREA: check(data, CategoryDataset.class, chartType); return ChartFactory.createStackedAreaChart(title, xAxisLabel, yAxisLabel, (CategoryDataset) data, PlotOrientation.VERTICAL, true, false, false); case BUBBLE: check(data, XYZDataset.class, chartType); return ChartFactory.createBubbleChart(title, xAxisLabel, yAxisLabel, (XYZDataset) data, PlotOrientation.VERTICAL, true, false, false); case AUSTER_CICLOS: check(data, IntervalCategoryDataset.class, chartType); return ChartFactory.createAusterCiclosChart((IntervalCategoryDataset) data); default: throw new UnsupportedChartTypeException(chartType + " is not supported."); } }
From source file:org.dcm4chee.dashboard.ui.report.display.DisplayReportDiagramPanel.java
@Override public void onBeforeRender() { super.onBeforeRender(); Connection jdbcConnection = null; try {//from w w w . j av a 2 s . c o m if (report == null) throw new Exception("No report given to render diagram"); jdbcConnection = DatabaseUtils.getDatabaseConnection(report.getDataSource()); ResultSet resultSet = DatabaseUtils.getResultSet(jdbcConnection, report.getStatement(), parameters); ResultSetMetaData metaData = resultSet.getMetaData(); JFreeChart chart = null; resultSet.beforeFirst(); // Line chart - 1 numeric value if (report.getDiagram() == 0) { if (metaData.getColumnCount() != 1) throw new Exception( new ResourceModel("dashboard.report.reportdiagram.image.render.error.1numvalues") .wrapOnAssignment(this).getObject()); DefaultCategoryDataset dataset = new DefaultCategoryDataset(); while (resultSet.next()) dataset.addValue(resultSet.getDouble(1), metaData.getColumnName(1), String.valueOf(resultSet.getRow())); chart = ChartFactory.createLineChart( new ResourceModel("dashboard.report.reportdiagram.image.label").wrapOnAssignment(this) .getObject(), new ResourceModel("dashboard.report.reportdiagram.image.row-label").wrapOnAssignment(this) .getObject(), metaData.getColumnName(1), dataset, PlotOrientation.VERTICAL, true, true, true); // XY Series chart - 2 numeric values } else if (report.getDiagram() == 1) { if (metaData.getColumnCount() != 2) throw new Exception( new ResourceModel("dashboard.report.reportdiagram.image.render.error.2numvalues") .wrapOnAssignment(this).getObject()); XYSeries series = new XYSeries(metaData.getColumnName(1) + " / " + metaData.getColumnName(2)); while (resultSet.next()) series.add(resultSet.getDouble(1), resultSet.getDouble(2)); chart = ChartFactory.createXYLineChart( new ResourceModel("dashboard.report.reportdiagram.image.label").wrapOnAssignment(this) .getObject(), metaData.getColumnName(1), metaData.getColumnName(2), new XYSeriesCollection(series), PlotOrientation.VERTICAL, true, true, true); // Category chart - 1 numeric value, 1 comparable value } else if (report.getDiagram() == 2) { if (metaData.getColumnCount() != 2) throw new Exception( new ResourceModel("dashboard.report.reportdiagram.image.render.error.2values") .wrapOnAssignment(this).getObject()); DefaultCategoryDataset dataset = new DefaultCategoryDataset(); while (resultSet.next()) dataset.setValue(resultSet.getDouble(1), metaData.getColumnName(1) + " / " + metaData.getColumnName(2), resultSet.getString(2)); chart = new JFreeChart( new ResourceModel("dashboard.report.reportdiagram.image.label").wrapOnAssignment(this) .getObject(), new CategoryPlot(dataset, new LabelAdaptingCategoryAxis(14, metaData.getColumnName(2)), new NumberAxis(metaData.getColumnName(1)), new CategoryStepRenderer(true))); // Pie chart - 1 numeric value, 1 comparable value (used as category) } else if ((report.getDiagram() == 3) || (report.getDiagram() == 4)) { if (metaData.getColumnCount() != 2) throw new Exception( new ResourceModel("dashboard.report.reportdiagram.image.render.error.2values") .wrapOnAssignment(this).getObject()); DefaultPieDataset dataset = new DefaultPieDataset(); while (resultSet.next()) dataset.setValue(resultSet.getString(2), resultSet.getDouble(1)); if (report.getDiagram() == 3) // Pie chart 2D chart = ChartFactory .createPieChart(new ResourceModel("dashboard.report.reportdiagram.image.label") .wrapOnAssignment(this).getObject(), dataset, true, true, true); else if (report.getDiagram() == 4) { // Pie chart 3D chart = ChartFactory .createPieChart3D(new ResourceModel("dashboard.report.reportdiagram.image.label") .wrapOnAssignment(this).getObject(), dataset, true, true, true); ((PiePlot3D) chart.getPlot()).setForegroundAlpha( Float.valueOf(new ResourceModel("dashboard.report.reportdiagram.image.alpha") .wrapOnAssignment(this).getObject())); } // Bar chart - 1 numeric value, 2 comparable values (used as category, series) } else if (report.getDiagram() == 5) { if ((metaData.getColumnCount() != 2) && (metaData.getColumnCount() != 3)) throw new Exception( new ResourceModel("dashboard.report.reportdiagram.image.render.error.3values") .wrapOnAssignment(this).getObject()); DefaultCategoryDataset dataset = new DefaultCategoryDataset(); while (resultSet.next()) dataset.setValue(resultSet.getDouble(1), resultSet.getString(2), resultSet.getString(metaData.getColumnCount())); chart = ChartFactory.createBarChart( new ResourceModel("dashboard.report.reportdiagram.image.label").wrapOnAssignment(this) .getObject(), metaData.getColumnName(2), metaData.getColumnName(1), dataset, PlotOrientation.VERTICAL, true, true, true); } int[] winSize = DashboardCfgDelegate.getInstance().getWindowSize("reportDiagramImage"); addOrReplace(new JFreeChartImage("diagram", chart, winSize[0], winSize[1])); final JFreeChart downloadableChart = chart; addOrReplace(new Link<Object>("diagram-download") { private static final long serialVersionUID = 1L; @Override public void onClick() { RequestCycle.get().setRequestTarget(new IRequestTarget() { public void respond(RequestCycle requestCycle) { WebResponse wr = (WebResponse) requestCycle.getResponse(); wr.setContentType("image/png"); wr.setHeader("content-disposition", "attachment;filename=diagram.png"); OutputStream os = wr.getOutputStream(); try { ImageIO.write(downloadableChart.createBufferedImage(800, 600), "png", os); os.close(); } catch (IOException e) { log.error(this.getClass().toString() + ": " + "respond: " + e.getMessage()); log.debug("Exception: ", e); } wr.close(); } @Override public void detach(RequestCycle arg0) { } }); } }.add(new Image("diagram-download-image", ImageManager.IMAGE_DASHBOARD_REPORT_DOWNLOAD) .add(new ImageSizeBehaviour()) .add(new TooltipBehaviour("dashboard.report.reportdiagram.", "image.downloadlink")))); addOrReplace(new Image("diagram-print-image", ImageManager.IMAGE_DASHBOARD_REPORT_PRINT) .add(new ImageSizeBehaviour()) .add(new TooltipBehaviour("dashboard.report.reportdiagram.", "image.printbutton"))); addOrReplace(new Label("error-message", "").setVisible(false)); addOrReplace(new Label("error-reason", "").setVisible(false)); } catch (Exception e) { log.error("Exception: " + e.getMessage()); addOrReplace(((DynamicDisplayPage) this.getPage()).new PlaceholderLink("diagram-download") .setVisible(false)); addOrReplace(new Image("diagram-print-image").setVisible(false)); addOrReplace(new Image("diagram").setVisible(false)); addOrReplace(new Label("error-message", new ResourceModel("dashboard.report.reportdiagram.statement.error").wrapOnAssignment(this) .getObject()) .add(new AttributeModifier("class", true, new Model<String>("message-error")))); addOrReplace(new Label("error-reason", e.getMessage()) .add(new AttributeModifier("class", true, new Model<String>("message-error")))); log.debug(getClass() + ": ", e); } finally { try { jdbcConnection.close(); } catch (Exception ignore) { } } }
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 w w.j ava 2 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 PieChart 3D. <br> * /*w ww . j a va2 s .c o m*/ * @param event * @throws IOException */ public void onClick$button_CustomerChart_PieChart3D(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.createPieChart3D(title, pieDataset, true, true, true); PiePlot3D plot = (PiePlot3D) 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("Pie Chart", bytes); Image img = new Image(); img.setContent(chartImage); img.setParent(this.div_chartArea); } else { div_chartArea.getChildren().clear(); Label label = new Label(); label.setValue("This customer have no data for showing in a chart!"); label.setParent(div_chartArea); } }
From source file:cachedataanalysis.FlowCache.java
public XYSeries exportReportChart() throws IOException { File outputHitRate = new File("report/" + name + "_" + policy + "_hitrate.txt"); FileWriter fw = new FileWriter(outputHitRate); XYSeries hitRateCount = new XYSeries(name + "(" + size + " entries)"); for (int i = 0; i < hitRateRecord.size(); i++) { hitRateCount.add(i, hitRateRecord.get(i)); fw.write(i + "," + hitRateRecord.get(i) + "\n"); fw.flush();/*from ww w .j a v a 2s . c o m*/ } fw.close(); XYSeriesCollection HitRateData = new XYSeriesCollection(); HitRateData.addSeries(hitRateCount); JFreeChart hitRateStat = ChartFactory.createXYLineChart( "Hit Rate variatoion throughout recording in " + name, "Seconds", "HitRate", HitRateData, PlotOrientation.VERTICAL, true, true, false); ChartUtilities.saveChartAsJPEG(new File("report/" + name + "_hitRate" + size + ".jpg"), hitRateStat, 1500, 900); //------------------------------- if (!fullReport) { return hitRateCount; } DefaultPieDataset hitProtoData = new DefaultPieDataset(); DefaultPieDataset missProtoData = new DefaultPieDataset(); CategoryTableXYDataset hitProtoDataRec = new CategoryTableXYDataset(); for (int i = 0; i < hitProtoRec.size(); i++) { if (i % 120 != 0) { continue; } HashMap<String, Integer> _map = hitProtoRec.get(i); for (String _str : _map.keySet()) { hitProtoDataRec.add(i, _map.get(_str), _str); } } CategoryTableXYDataset missProtoDataRec = new CategoryTableXYDataset(); for (int i = 0; i < missProtoRec.size(); i++) { if (i % 120 != 0) { continue; } HashMap<String, Integer> _map = missProtoRec.get(i); for (String _str : _map.keySet()) { missProtoDataRec.add(i, _map.get(_str), _str); } } XYSeries hitCountData = new XYSeries("Hit"); XYSeries allCountData = new XYSeries("All"); for (int i = 0; i < hitCount.size(); i++) { hitCountData.add(i, hitCount.get(i)); //hitRateCount.add(i,(float)hitCount.get(i)/(hitCount.get(i)+allCount.get(i))); } for (int i = 0; i < allCount.size(); i++) { allCountData.add(i, allCount.get(i)); } XYSeriesCollection CountStatData = new XYSeriesCollection(); CountStatData.addSeries(hitCountData); CountStatData.addSeries(allCountData); for (String protocol : hitProto.keySet()) { hitProtoData.setValue(protocol, hitProto.get(protocol)); } for (String protocol : missProto.keySet()) { missProtoData.setValue(protocol, missProto.get(protocol)); } JFreeChart hitStatRec = ChartFactory.createStackedXYAreaChart( "Hit Protocol Fraction throughout record in " + name, "Seconds", "Count", hitProtoDataRec); JFreeChart missStatRec = ChartFactory.createStackedXYAreaChart( "Miss Protocol Fraction throughout record in " + name, "Seconds", "Count", missProtoDataRec); JFreeChart hitStat = ChartFactory.createPieChart3D("Protocal Fraction of Hit Flows in " + name, hitProtoData, true, true, false); JFreeChart missStat = ChartFactory.createPieChart3D("Protocal Fraction of Miss Flows in " + name, missProtoData, true, true, false); JFreeChart countStat = ChartFactory.createXYAreaChart("Hit Count to All Packet lookup in " + name, "Seconds", "Count", CountStatData, PlotOrientation.VERTICAL, true, true, false); ChartUtilities.saveChartAsJPEG(new File("report/" + name + "_hitProto" + size + ".jpg"), hitStat, 1500, 900); ChartUtilities.saveChartAsJPEG(new File("report/" + name + "_missProto" + size + ".jpg"), missStat, 1500, 900); ChartUtilities.saveChartAsJPEG(new File("report/" + name + "_hitCount" + size + ".jpg"), countStat, 1500, 900); ChartUtilities.saveChartAsJPEG(new File("report/" + name + "_hitProtoRecord" + size + ".jpg"), hitStatRec, 1500, 900); ChartUtilities.saveChartAsJPEG(new File("report/" + name + "_missProtoRecord" + size + ".jpg"), missStatRec, 1500, 900); return hitRateCount; }
From source file:view.ViewReportUI.java
private JFreeChart createChart(PieDataset dataset, String hello) { //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. JFreeChart chart = ChartFactory.createPieChart3D("Expense Tracker", // chart title dataset, // data true, // include legend true, false);/*from www . j a v a 2 s .c om*/ PiePlot3D plot = (PiePlot3D) chart.getPlot(); plot.setStartAngle(290); plot.setDirection(Rotation.CLOCKWISE); plot.setForegroundAlpha(0.5f); return chart; }
From source file:co.edu.eam.ingesoft.egresados.vista.gui.VentanaReporteEgresadosOcupacion.java
private void btnGenerarActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_btnGenerarActionPerformed // TODO add your handling code here: System.out.println((Programa) cbPrograma.getSelectedItem()); ChartPanel panel;/*from w w w .j ava 2s . c om*/ try { Programa p = (Programa) cbPrograma.getSelectedItem(); List<InformacionLaboral> listaInfoLab = controlador.listarInformacionLaboralPorPrograma(p); jPPrimero.removeAll(); jPSegundo.removeAll(); double empleado = 0; double desempleado = 0; double independiente = 0; double empresario = 0; System.out.println((Programa) cbPrograma.getSelectedItem()); int contadorEmpleado = 0; int contadordDesempleado = 0; int contadorIndependiente = 0; int contadorEmpresario = 0; for (int i = 0; i < listaInfoLab.size(); i++) { if (listaInfoLab.get(i).getSituacionAct().equals(SituacionLaboralEnum.EMPLEADO)) { contadorEmpleado++; } else if (listaInfoLab.get(i).getSituacionAct().equals(SituacionLaboralEnum.DESEMPLEADO)) { contadordDesempleado++; } else if (listaInfoLab.get(i).getSituacionAct().equals(SituacionLaboralEnum.INDEPENDIENTE)) { contadorIndependiente++; } else if (listaInfoLab.get(i).getSituacionAct().equals(SituacionLaboralEnum.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, 280, 280); jPSegundo.removeAll(); jPSegundo.add(panel); jPSegundo.updateUI(); } catch (Exception e) { e.printStackTrace(); } }
From source file:Forms.SalesChart.java
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed DefaultPieDataset pieDataset = new DefaultPieDataset(); String conString = "jdbc:mysql://localhost:3306/nafis"; String username = "root"; String passward = ""; String sql = "SELECT * FROM sold"; try {/*from w w w . j a v a 2 s .com*/ Connection con = (Connection) DriverManager.getConnection(conString, username, passward); Statement s = (Statement) con.prepareStatement(sql); ResultSet rs = s.executeQuery(sql); HashMap<String, Integer> map = new HashMap<String, Integer>(); while (rs.next()) { String name = rs.getString(2); String stock = rs.getString(3); String type = rs.getString(8); Integer oldVal = map.get(type); //System.out.println(oldVal); if (oldVal == null) { map.put(type, Integer.parseInt(stock)); } else { map.put(type, oldVal + Integer.parseInt(stock)); } } for (HashMap.Entry m : map.entrySet()) { //System.out.println(m.getKey()+" "+m.getValue()); pieDataset.setValue(m.getKey() + "", Integer.parseInt(m.getValue() + "")); } } catch (Exception e) { e.printStackTrace(); } JFreeChart chart = ChartFactory.createPieChart3D("pie chart", pieDataset, true, true, false); PiePlot3D p = (PiePlot3D) chart.getPlot(); p.setStartAngle(0); p.setDirection(Rotation.CLOCKWISE); p.setForegroundAlpha(0.5f); p.getBackgroundPaint(); ChartFrame frame = new ChartFrame("Pie Chart", chart); frame.setLocationByPlatform(true); frame.setVisible(true); frame.setSize(750, 600); }
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 .ja v a2s . 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; }