List of usage examples for org.jfree.data.general DefaultPieDataset setValue
public void setValue(Comparable key, double value)
From source file:com.geometrycloud.happydonut.ui.ChartFilterPanel.java
/** * Carga la informacion para generar la grafica con el top de ventas. * * @param from desde donde buscar.// ww w. jav a 2 s . co m * @param to hasta donde buscar. * @return informacion de la grafica. */ private PieDataset chartDataset(LocalDate from, LocalDate to) { DefaultPieDataset dataset = new DefaultPieDataset(); RowList sales = DATABASE.table(SALES_TABLE_NAME).where(SALES_SALE_DATE, ">=", from.toString()) .where(SALES_SALE_DATE, "<=", to.toString()).get(SALES_PRIMARY_KEY, SALES_SALE_DATE); HashMap<String, Long> top = new HashMap<>(); for (Row sale : sales) { RowList details = DATABASE.table(SALE_DETAILS_TABLE_NAME) .where(SALE_DETAILS_SALE, "=", sale.value(SALES_PRIMARY_KEY)) .get(SALE_DETAILS_NAME, SALE_DETAILS_QUANTITY); String name; Long quantity; for (Row detail : details) { name = detail.string(SALE_DETAILS_NAME); quantity = detail.number(SALE_DETAILS_QUANTITY); if (top.containsKey(name)) { quantity += top.get(name); } top.put(name, quantity); } } top.forEach((k, v) -> dataset.setValue(k, v)); return dataset; }
From source file:simx.profiler.info.actor.ActorInstanceInfoTopComponent.java
/** * This method creates a pie chart and adds it to the target panel. * //from www . jav a 2 s . co m * @param data The data set that should be visualized by the pie chart. * @param targetPanel The panel where the pie chart should be added to. */ private void createPieChart(final DefaultPieDataset data, final javax.swing.JPanel targetPanel) { if (data == null) throw new IllegalArgumentException("The parameter 'data' must not be 'null'!"); if (targetPanel == null) throw new IllegalArgumentException("The parameter 'targetPanel' must not be 'null'!"); data.setValue("???", 100); final JFreeChart chart = ChartFactory.createPieChart("", data, false, false, false); final PiePlot plot = (PiePlot) chart.getPlot(); plot.setDirection(Rotation.CLOCKWISE); plot.setForegroundAlpha(0.5f); final ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new java.awt.Dimension(261, 157)); targetPanel.setLayout(new BorderLayout()); targetPanel.add(chartPanel, BorderLayout.CENTER); }
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;//from www. j ava 2 s . co m } 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:org.tiefaces.components.websheet.chart.ChartHelper.java
/** * create default category dataset for JfreeChart with giving chartData. * /*from www .j av a 2 s .co m*/ * @param chartData * contain information gathered from excel chart object. * @return DefaultCategoryDataset for jfreechart. */ private DefaultPieDataset createPieDataset(final ChartData chartData) { DefaultPieDataset dataset = new DefaultPieDataset(); List<ParsedCell> categoryList = chartData.getCategoryList(); for (ChartSeries chartSeries : chartData.getSeriesList()) { List<ParsedCell> valueList = chartSeries.getValueList(); for (int i = 0; i < categoryList.size(); i++) { try { String sCategory = getParsedCellValue(categoryList.get(i)); String sValue = getParsedCellValue(valueList.get(i)); dataset.setValue(sCategory, Double.parseDouble(sValue)); } catch (Exception ex) { LOG.log(Level.FINE, "error in creatPieDataset : " + ex.getLocalizedMessage(), ex); } } } return dataset; }
From source file:dbseer.gui.chart.DBSeerChartFactory.java
public static JFreeChart createPieChart(String chartName, DBSeerDataSet dataset) throws Exception { StatisticalPackageRunner runner = DBSeerGUI.runner; runner.eval("[title legends Xdata Ydata Xlabel Ylabel timestamp] = plotter.plot" + chartName + ";"); String title = runner.getVariableString("title"); Object[] legends = (Object[]) runner.getVariableCell("legends"); Object[] xCellArray = (Object[]) runner.getVariableCell("Xdata"); Object[] yCellArray = (Object[]) runner.getVariableCell("Ydata"); String xLabel = runner.getVariableString("Xlabel"); String yLabel = runner.getVariableString("Ylabel"); timestamp = runner.getVariableDouble("timestamp"); DefaultPieDataset pieDataSet = new DefaultPieDataset(); int numLegends = legends.length; int numXCellArray = xCellArray.length; int numYCellArray = yCellArray.length; int dataCount = 0; if (numXCellArray != numYCellArray) { JOptionPane.showMessageDialog(null, "The number of X dataset and Y dataset does not match.", "The number of X dataset and Y dataset does not match.", JOptionPane.ERROR_MESSAGE); return null; }// w w w . j a v a 2 s .com final java.util.List<String> transactionTypeNames = dataset.getTransactionTypeNames(); for (int i = 0; i < numYCellArray; ++i) { double[] xArray = (double[]) xCellArray[i]; runner.eval("yArraySize = size(Ydata{" + (i + 1) + "});"); runner.eval("yArray = Ydata{" + (i + 1) + "};"); double[] yArraySize = runner.getVariableDouble("yArraySize"); double[] yArray = runner.getVariableDouble("yArray"); int xLength = xArray.length; int row = (int) yArraySize[0]; int col = (int) yArraySize[1]; for (int c = 0; c < col; ++c) { if (c < transactionTypeNames.size()) { String name = transactionTypeNames.get(c); if (!name.isEmpty()) { // pieDataSet.setValue(name, new Double(yArray.getRealValue(0, c))); pieDataSet.setValue(name, yArray[c]); } else { // pieDataSet.setValue("Transaction Type " + (c+1), yArray.getRealValue(0, c)); pieDataSet.setValue("Transaction Type " + (c + 1), yArray[c]); } } } } JFreeChart chart = ChartFactory.createPieChart(title, pieDataSet, true, true, false); PiePlot plot = (PiePlot) chart.getPlot(); plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0}: {1} ({2})", new DecimalFormat("0"), new DecimalFormat("0%"))); plot.setLegendLabelGenerator(new PieSectionLabelGenerator() { @Override public String generateSectionLabel(PieDataset pieDataset, Comparable comparable) { return (String) comparable; } @Override public AttributedString generateAttributedSectionLabel(PieDataset pieDataset, Comparable comparable) { return null; } }); return chart; }
From source file:userinterface.CountryNetworkAdminRole.CountryReportsJPanel.java
public PieDataset createDataSetForPatientReports() { DefaultPieDataset dataset = new DefaultPieDataset(); HashMap<String, Integer> organDonorMap = new HashMap<>(); for (Patient patient : patientList) { if (organDonorMap.containsKey(patient.getOrganNeeded().getOrganName())) { Integer count = organDonorMap.get(patient.getOrganNeeded().getOrganName()); count++;//from ww w . ja v a2 s. c o m organDonorMap.put(patient.getOrganNeeded().getOrganName(), count); } else { organDonorMap.put(patient.getOrganNeeded().getOrganName(), 1); } } for (Map.Entry<String, Integer> entry : organDonorMap.entrySet()) { Integer noOfDonors = entry.getValue(); noOfDonors = (noOfDonors * 100) / patientList.size(); organDonorMap.put(entry.getKey(), noOfDonors); } for (Map.Entry<String, Integer> entry : organDonorMap.entrySet()) { dataset.setValue(entry.getKey() + " = " + entry.getValue(), entry.getValue()); } return dataset; }
From source file:userinterface.CountryNetworkAdminRole.CountryReportsJPanel.java
public PieDataset createDataSetForDonorReports() { DefaultPieDataset dataset = new DefaultPieDataset(); HashMap<String, Integer> organDonorMap = new HashMap<>(); for (Donor donor : donorList) { for (Organ organ : donor.getOrganDonateList()) { if (organDonorMap.containsKey(organ.getOrganName())) { Integer count = organDonorMap.get(organ.getOrganName()); count++;/* w w w.j av a 2 s . c o m*/ organDonorMap.put(organ.getOrganName(), count); } else { organDonorMap.put(organ.getOrganName(), 1); } } } for (Map.Entry<String, Integer> entry : organDonorMap.entrySet()) { Integer noOfDonors = entry.getValue(); noOfDonors = noOfDonors * 100 / donorList.size(); organDonorMap.put(entry.getKey(), noOfDonors); } for (Map.Entry<String, Integer> entry : organDonorMap.entrySet()) { dataset.setValue(entry.getKey() + " = " + entry.getValue(), entry.getValue()); } return dataset; }
From source file:ca.myewb.frame.servlet.GraphServlet.java
private JFreeChart getRankPie() { JFreeChart chart;/*w ww.j a va2s .com*/ DefaultPieDataset ds = new DefaultPieDataset(); int numRegular = Helpers.getGroup("Regular").getNumMembers(); int numAssociate = Helpers.getGroup("Associate").getNumMembers(); int numUsers = Helpers.getGroup("Org").getNumMembers(); ds.setValue("Regular Members", numRegular); ds.setValue("Associate Members", numAssociate); ds.setValue("Mailing list Members", numUsers - numAssociate - numRegular); chart = ChartFactory.createPieChart("Status breakdown for " + numUsers + " members", ds, false, false, false); PiePlot plot = ((PiePlot) chart.getPlot()); StandardPieItemLabelGenerator n = new StandardPieItemLabelGenerator("{0} = {1} ({2})", new DecimalFormat("0"), new DecimalFormat("0.0%")); plot.setLabelGenerator(n); return chart; }
From source file:org.cyberoam.iview.charts.CustomToolTipGeneratorForDiskUsage.java
/** * This method generates JFreeChart instance for 3D Pie chart with iView customization. * @param reportID specifies that for which report Chart is being prepared. * @param rsw specifies data set which would be used for the Chart * @param requeest used for Hyperlink generation from uri. * @return jfreechart instance with iView Customization. */// w w w .j a v a2 s. co m public static JFreeChart getChart(int reportID, ResultSetWrapper rsw, HttpServletRequest request) { boolean xFlag = false; ReportBean reportBean = ReportBean.getRecordbyPrimarykey(reportID); JFreeChart chart = null; try { ReportColumnBean reportColumnBean, reportColumnBeanX = null; GraphBean graphBean = null; DataLinkBean dataLinkBean = null; DefaultPieDataset dataset = new DefaultPieDataset(); graphBean = GraphBean.getRecordbyPrimarykey(reportBean.getGraphId());//Getting GraphBean reportColumnBeanX = ReportColumnBean.getRecordByPrimaryKey(reportBean.getReportId(), graphBean.getXColumnId());//getting ReportColumnBean For X Axis // String xColumnDBname = reportColumnBeanX.getDbColumnName(); if (reportColumnBeanX.getDataLinkId() != -1) { dataLinkBean = DataLinkBean.getRecordbyPrimarykey(reportColumnBeanX.getDataLinkId()); } reportColumnBean = ReportColumnBean.getRecordByPrimaryKey(reportBean.getReportId(), graphBean.getZColumnId()); rsw.beforeFirst(); reportColumnBean = ReportColumnBean.getRecordByPrimaryKey(reportBean.getReportId(), graphBean.getYColumnId()); String yColumnName = reportColumnBean.getColumnName(); if (dataLinkBean == null && reportColumnBean.getDataLinkId() != -1) { dataLinkBean = DataLinkBean.getRecordbyPrimarykey(reportColumnBean.getDataLinkId()); } String xData = null; while (rsw.next()) { xData = rsw.getString(reportColumnBeanX.getDbColumnName()); if (xData == null || "".equalsIgnoreCase(xData) || "null".equalsIgnoreCase(xData)) { xData = "N/A"; } else if (reportColumnBeanX.getColumnFormat() == TabularReportConstants.PROTOCOL_FORMATTING && xData.indexOf(':') != -1) { String data = data = ProtocolBean.getProtocolNameById(Integer.parseInt( rsw.getString(reportColumnBeanX.getDbColumnName()).substring(0, xData.indexOf(':')))); xData = data + rsw.getString(reportColumnBeanX.getDbColumnName()).substring(xData.indexOf(':'), xData.length()); } dataset.setValue(xData, new Long(rsw.getLong(reportColumnBean.getDbColumnName()))); } chart = ChartFactory.createPieChart3D("", // chart title dataset, // data true, // include legend true, // tooltips? false // URLs? ); /* *Setting additional customization to the chart. */ //Set the background color for the chart... chart.setBackgroundPaint(Color.white); //Get a reference to the plot for further customisation... PiePlot3D plot = (PiePlot3D) chart.getPlot(); plot.setBackgroundPaint(Color.white); plot.setBackgroundAlpha(0.0f); plot.setSectionOutlinesVisible(false); plot.setOutlineVisible(false); plot.setStartAngle(290); plot.setDepthFactor(0.1); plot.setDirection(Rotation.CLOCKWISE); plot.setNoDataMessage("No data to display"); plot.setSectionOutlinesVisible(false); plot.setSectionOutlinePaint(Color.white); plot.setOutlineVisible(false); plot.setExplodePercent(dataset.getKey(0), 0.3); plot.setLabelLinkPaint(Color.gray); plot.setLabelBackgroundPaint(Color.white); plot.setLabelFont(new Font("Arial", Font.CENTER_BASELINE, 10)); plot.setLabelOutlinePaint(Color.white); plot.setLabelShadowPaint(Color.white); LegendTitle legend = chart.getLegend(); legend.setItemFont(new Font("Arial", Font.CENTER_BASELINE, 10)); legend.setMargin(0, 0, 2, 0); legend.setHorizontalAlignment(HorizontalAlignment.CENTER); plot.setToolTipGenerator(new CustomToolTipGeneratorForPie3D("{0}: ({1} " + yColumnName + ", {2})")); //Setting Color try { plot.setSectionPaint(dataset.getKey(0), new Color(0, 0, 254)); plot.setSectionPaint(dataset.getKey(1), new Color(255, 0, 254)); plot.setSectionPaint(dataset.getKey(2), new Color(176, 176, 255)); plot.setSectionPaint(dataset.getKey(3), new Color(255, 170, 255)); plot.setSectionPaint(dataset.getKey(4), new Color(69, 153, 204)); } catch (Exception e) { } } catch (Exception e) { CyberoamLogger.appLog.debug("Pie3D.e:" + e, e); } return chart; }
From source file:org.cyberoam.iview.charts.CustomToolTipGeneratorForPie3D.java
/** * This method generates JFreeChart instance for 3D Pie chart with iView customization. * @param reportID specifies that for which report Chart is being prepared. * @param rsw specifies data set which would be used for the Chart * @param requeest used for Hyperlink generation from uri. * @return jfreechart instance with iView Customization. *//* ww w . ja v a2s . c o m*/ public static JFreeChart getChart(int reportID, ResultSetWrapper rsw, HttpServletRequest request) { boolean xFlag = false; ReportBean reportBean = ReportBean.getRecordbyPrimarykey(reportID); JFreeChart chart = null; try { ReportColumnBean reportColumnBean, reportColumnBeanX = null; GraphBean graphBean = null; DataLinkBean dataLinkBean = null; DefaultPieDataset dataset = new DefaultPieDataset(); graphBean = GraphBean.getRecordbyPrimarykey(reportBean.getGraphId());//Getting GraphBean reportColumnBeanX = ReportColumnBean.getRecordByPrimaryKey(reportBean.getReportId(), graphBean.getXColumnId());//getting ReportColumnBean For X Axis // String xColumnDBname = reportColumnBeanX.getDbColumnName(); if (reportColumnBeanX.getDataLinkId() != -1) { dataLinkBean = DataLinkBean.getRecordbyPrimarykey(reportColumnBeanX.getDataLinkId()); } reportColumnBean = ReportColumnBean.getRecordByPrimaryKey(reportBean.getReportId(), graphBean.getZColumnId()); rsw.beforeFirst(); reportColumnBean = ReportColumnBean.getRecordByPrimaryKey(reportBean.getReportId(), graphBean.getYColumnId()); String yColumnName = reportColumnBean.getColumnName(); if (dataLinkBean == null && reportColumnBean.getDataLinkId() != -1) { dataLinkBean = DataLinkBean.getRecordbyPrimarykey(reportColumnBean.getDataLinkId()); } String xData = null; while (rsw.next()) { xData = rsw.getString(reportColumnBeanX.getDbColumnName()); if (xData == null || "".equalsIgnoreCase(xData) || "null".equalsIgnoreCase(xData)) { xData = "N/A"; } else if (reportColumnBeanX.getColumnFormat() == TabularReportConstants.PROTOCOL_FORMATTING && xData.indexOf(':') != -1) { String data = data = ProtocolBean.getProtocolNameById(Integer.parseInt( rsw.getString(reportColumnBeanX.getDbColumnName()).substring(0, xData.indexOf(':')))); xData = data + rsw.getString(reportColumnBeanX.getDbColumnName()).substring(xData.indexOf(':'), xData.length()); } dataset.setValue(xData, new Long(rsw.getLong(reportColumnBean.getDbColumnName()))); } chart = ChartFactory.createPieChart3D("", // chart title dataset, // data true, // include legend true, // tooltips? false // URLs? ); /* *Setting additional customization to the chart. */ //Set the background color for the chart... chart.setBackgroundPaint(Color.white); //Get a reference to the plot for further customisation... PiePlot3D plot = (PiePlot3D) chart.getPlot(); plot.setBackgroundPaint(Color.white); plot.setBackgroundAlpha(0.0f); plot.setSectionOutlinesVisible(false); plot.setOutlineVisible(false); plot.setStartAngle(290); plot.setDepthFactor(0.1); plot.setDirection(Rotation.CLOCKWISE); plot.setNoDataMessage("No data to display"); plot.setSectionOutlinesVisible(false); plot.setSectionOutlinePaint(Color.white); plot.setOutlineVisible(false); plot.setExplodePercent(dataset.getKey(0), 0.3); plot.setLabelLinkPaint(Color.gray); plot.setLabelBackgroundPaint(Color.white); plot.setLabelFont(new Font("Arial", Font.CENTER_BASELINE, 10)); plot.setLabelOutlinePaint(Color.white); plot.setLabelShadowPaint(Color.white); LegendTitle legend = chart.getLegend(); legend.setItemFont(new Font("Arial", Font.CENTER_BASELINE, 10)); legend.setMargin(0, 0, 2, 0); legend.setHorizontalAlignment(HorizontalAlignment.CENTER); plot.setToolTipGenerator(new CustomToolTipGeneratorForPie3D("{0}: ({1} " + yColumnName + ", {2})")); //Setting Color try { plot.setSectionPaint(dataset.getKey(0), Pie3D.pieSections[0]); plot.setSectionPaint(dataset.getKey(1), Pie3D.pieSections[1]); plot.setSectionPaint(dataset.getKey(2), Pie3D.pieSections[2]); plot.setSectionPaint(dataset.getKey(3), Pie3D.pieSections[3]); plot.setSectionPaint(dataset.getKey(4), Pie3D.pieSections[4]); } catch (Exception e) { } } catch (Exception e) { CyberoamLogger.appLog.debug("Pie3D.e:" + e, e); } return chart; }