List of usage examples for org.jfree.data.general DefaultPieDataset setValue
public void setValue(Comparable key, double value)
From source file:org.lsug.quota.portlet.ServerQuotaPortlet.java
@Override public void serveResource(ResourceRequest resourceRequest, ResourceResponse resourceResponse) throws IOException, PortletException { String type = ParamUtil.getString(resourceRequest, "type", "currentSize"); StringBundler sb = new StringBundler(5); JFreeChart jFreeChart = null;/*from www. j a v a2s. c om*/ if (type.equals("currentSize")) { long classNameId = PortalUtil.getClassNameId(Company.class.getName()); String orderByCol = "quotaUsed"; String orderByType = "desc"; OrderByComparator orderByComparator = QuotaUtil.getQuotaOrderByComparator(orderByCol, orderByType); DefaultPieDataset pieDataset = new DefaultPieDataset(); try { List<Quota> listCompanyQuota = QuotaLocalServiceUtil.getQuotaByClassNameId(classNameId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, orderByComparator); for (Quota quota : listCompanyQuota) { if (quota.isEnabled()) { pieDataset.setValue(CompanyLocalServiceUtil.getCompany(quota.getClassPK()).getWebId(), quota.getQuotaUsed()); } } } catch (Exception e) { LOGGER.error(e); throw new PortletException(e); } sb.append(QuotaUtil.getResource(resourceRequest, "server-current-used-size-diagram-title")); jFreeChart = getCurrentSizeJFreeChart(sb.toString(), pieDataset); } OutputStream outputStream = null; resourceResponse.setContentType(ContentTypes.IMAGE_PNG); try { outputStream = resourceResponse.getPortletOutputStream(); ChartUtilities.writeChartAsPNG(outputStream, jFreeChart, 400, 200); } finally { if (outputStream != null) { outputStream.close(); } } }
From source file:com.itemanalysis.jmetrik.graph.piechart.PieChartPanel.java
public void updateDefaultPieDataset(TwoWayTable table) { DefaultPieDataset dataset = new DefaultPieDataset(); Iterator<Comparable<?>> rowIter = table.rowValuesIterator(); Iterator<Comparable<?>> colIter = null; Comparable<?> r = null; Comparable<?> c = null; while (rowIter.hasNext()) { r = rowIter.next();/* ww w . j av a 2 s .c om*/ colIter = table.colValuesIterator(); while (colIter.hasNext()) { c = colIter.next(); dataset.setValue(c.toString(), table.getCount(r, c)); } } PiePlot plot = (PiePlot) chart.getPlot(); plot.setDataset(dataset); }
From source file:edu.emory.library.tast.database.graphs.GraphPie.java
public JFreeChart createChart(Object[] data) { DefaultPieDataset pieDataset = new DefaultPieDataset(); JFreeChart chart = ChartFactory.createPieChart(null, pieDataset, false, true, false); chart.setBackgroundPaint(Color.white); List dataSeries = getDataSeries(); if (dataSeries.size() == 0) return null; Format formatter = getSelectedIndependentVariable().getFormat(); for (int i = 0; i < data.length; i++) { Object[] row = (Object[]) data[i]; String cat = formatter == null ? row[0].toString() : formatter.format(row[0]); pieDataset.setValue(cat, (Number) row[1]); }//from w w w. j a v a 2s .c o m return chart; }
From source file:Software_Jframes.chart.java
public void piechart(JDesktopPane jDesktopPane1, String pid) { DefaultPieDataset piedataset = new DefaultPieDataset(); try {/*from ww w .ja va 2s. c o m*/ ResultSet rs = db.statement() .executeQuery("select name,cost from project_level_payment where projectid='" + pid + "' "); while (rs.next()) { String cost = rs.getString("cost"); int cost_int1 = Integer.parseInt(cost); String name = rs.getString("name"); piedataset.setValue(name, new Integer(cost_int1)); } } catch (Exception e) { e.printStackTrace(); } JFreeChart chart = ChartFactory.createPieChart("Costs for Project", piedataset, true, true, true); PiePlot p = (PiePlot) chart.getPlot(); p.setBackgroundPaint(Color.white); ChartPanel panel = new ChartPanel(chart); jDesktopPane1.add(panel).setSize(440, 300); }
From source file:net.sourceforge.atunes.kernel.modules.statistics.StatsDialogController.java
/** * Sets the general chart.//w ww . ja va 2 s . co m */ private void setGeneralChart() { DefaultPieDataset dataset = new DefaultPieDataset(); int different = this.statisticsHandler.getDifferentAudioObjectsPlayed(); int total = this.repositoryHandler.getAudioFilesList().size(); dataset.setValue(I18nUtils.getString("SONGS_PLAYED"), different); dataset.setValue(I18nUtils.getString("SONGS_NEVER_PLAYED"), total - different); JFreeChart chart = ChartFactory.createPieChart3D(I18nUtils.getString("SONGS_PLAYED"), dataset, false, false, false); chart.setBackgroundPaint(GuiUtils.getBackgroundColor()); chart.getTitle().setPaint(GuiUtils.getForegroundColor()); chart.setPadding(new RectangleInsets(5, 0, 0, 0)); 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); ((PiePlot3D) chart.getPlot()).setOutlineVisible(false); ((PiePlot3D) chart.getPlot()).setBackgroundPaint(GuiUtils.getBackgroundColor()); getComponentControlled().getGeneralChart().setIcon(new ImageIcon(chart.createBufferedImage(710, 250))); }
From source file:de.suse.swamp.modules.scheduledjobs.Statistics.java
/** * Generating the frontpage graph that shows the total amount of different wf types */// w w w . j a v a2 s. c o m protected void generateFrontpageGraph() { // count the number of workflows of each type: List names = wfman.getWorkflowTemplateNames(); DefaultPieDataset dataset = new DefaultPieDataset(); int wfcount = 0; for (Iterator it = names.iterator(); it.hasNext();) { String template = (String) it.next(); PropertyFilter templatefilter = new PropertyFilter(); templatefilter.addWfTemplate(template); int count = wfman.getWorkflowIds(templatefilter, null).size(); if (count > 0) { dataset.setValue(template, new Double(count)); } wfcount += count; } // only generate graph if workflows exist if (wfcount > 0) { JFreeChart chart = ChartFactory.createPieChart3D("Workflows inside SWAMP", dataset, false, false, false); PiePlot3D plot = (PiePlot3D) chart.getPlot(); plot.setForegroundAlpha(0.6f); File image = new File(statPath + fs + "workflows.png"); if (image.exists()) image.delete(); try { ChartUtilities.saveChartAsPNG(image, chart, 500, 350); } catch (java.io.IOException exc) { Logger.ERROR("Error writing image to file: " + exc.getMessage()); } } }
From source file:clienteescritorio.MainFrame.java
private DefaultPieDataset getDataForChart() { DefaultPieDataset data = new DefaultPieDataset(); try {//from ww w . j a va 2 s.co m String datos = metodosRemotos.leerInfoForChart(); String[] lines = datos.split("\\r?\\n"); for (String line : lines) { String[] tokens = line.split("\\|"); int movimientos = Integer.parseInt(tokens[1].trim()); data.setValue(tokens[0] + " tiene " + movimientos + " movimientos", movimientos); } } catch (RemoteException ex) { ex.printStackTrace(); } return data; }
From source file:org.sonar.plugins.abacus.chart.PieChart3D.java
@Override protected Plot getPlot(ChartParameters params) { PiePlot3D plot = new PiePlot3D(); String[] colorsHex = params.getValues(PARAM_COLORS, ",", true); String[] serie = params.getValues(PARAM_VALUES, ";", true); DefaultPieDataset set = new DefaultPieDataset(); Color[] colors = COLORS;/* w ww. j a v a 2 s . c o m*/ if (colorsHex != null && colorsHex.length > 0) { colors = new Color[colorsHex.length]; for (int i = 0; i < colorsHex.length; i++) { colors[i] = Color.decode("#" + colorsHex[i]); } } String[] keyValue = null; for (int i = 0; i < serie.length; i++) { if (!StringUtils.isEmpty(serie[i])) { keyValue = StringUtils.split(serie[i], "="); set.setValue(keyValue[0], Double.parseDouble(keyValue[1])); plot.setSectionPaint(keyValue[0], colors[i]); } } plot.setDataset(set); plot.setStartAngle(360); plot.setCircular(true); plot.setDirection(Rotation.CLOCKWISE); plot.setNoDataMessage(DEFAULT_MESSAGE_NODATA); plot.setInsets(RectangleInsets.ZERO_INSETS); plot.setForegroundAlpha(1.0f); plot.setBackgroundAlpha(0.0f); plot.setIgnoreNullValues(true); plot.setIgnoreZeroValues(true); plot.setOutlinePaint(Color.WHITE); plot.setShadowPaint(Color.WHITE); plot.setDarkerSides(false); plot.setLabelFont(DEFAULT_FONT); plot.setLabelPaint(Color.BLACK); plot.setLabelBackgroundPaint(Color.WHITE); plot.setLabelOutlinePaint(Color.WHITE); plot.setLabelShadowPaint(Color.WHITE); plot.setLabelPadding(new RectangleInsets(1, 1, 1, 1)); plot.setInteriorGap(0.02); plot.setMaximumLabelWidth(0.15); return plot; }
From source file:org.sonar.plugins.scmstats.charts.PieChart3D.java
@Override protected Plot getPlot(ChartParameters params) { PiePlot3D plot = new PiePlot3D(); String[] colorsHex = params.getValues(PARAM_COLORS, ",", true); String[] serie = params.getValues(PARAM_VALUES, ";", true); DefaultPieDataset set = new DefaultPieDataset(); Color[] colors = COLORS;//from w w w .j av a 2 s. co m if (colorsHex != null && colorsHex.length > 0) { colors = new Color[colorsHex.length]; for (int i = 0; i < colorsHex.length; i++) { colors[i] = Color.decode("#" + colorsHex[i]); } } String[] keyValue = null; for (int i = 0; i < serie.length; i++) { if (!StringUtils.isEmpty(serie[i])) { keyValue = StringUtils.split(serie[i], "="); set.setValue(keyValue[0], Double.parseDouble(keyValue[1])); plot.setSectionPaint(keyValue[0], colors[i]); } } plot.setDataset(set); plot.setStartAngle(180); plot.setCircular(true); plot.setDirection(Rotation.CLOCKWISE); plot.setNoDataMessage(DEFAULT_MESSAGE_NODATA); plot.setInsets(RectangleInsets.ZERO_INSETS); plot.setForegroundAlpha(1.0f); plot.setBackgroundAlpha(0.0f); plot.setIgnoreNullValues(true); plot.setIgnoreZeroValues(true); plot.setOutlinePaint(Color.WHITE); plot.setShadowPaint(Color.GREEN); plot.setDarkerSides(true); plot.setLabelFont(DEFAULT_FONT); plot.setLabelPaint(Color.BLACK); plot.setLabelBackgroundPaint(Color.WHITE); plot.setLabelOutlinePaint(Color.WHITE); plot.setLabelShadowPaint(Color.GRAY); plot.setLabelPadding(new RectangleInsets(1, 1, 1, 1)); plot.setInteriorGap(0.01); plot.setMaximumLabelWidth(0.25); return plot; }
From source file:org.onesun.sdi.swing.app.views.DataServicesView.java
private void createControls() { copyDataButton.addActionListener(new ActionListener() { @Override//from w ww . j a v a2s .c om public void actionPerformed(ActionEvent e) { datasetModel = new DatasetModel(); final Metadata origMetadata = AppCommonsUI.PREVIEW_DATASET_MODEL.getMetadata(); Metadata metadata = new Metadata(); // copy metadata for (String key : origMetadata.keySet()) { metadata.put(key, origMetadata.get(key)); } final List<Map<String, String>> origData = AppCommonsUI.PREVIEW_DATASET_MODEL.getData(); List<Map<String, String>> data = new ArrayList<Map<String, String>>(); // copy data for (Map<String, String> datum : origData) { Map<String, String> record = new TreeMap<String, String>(); for (String key : datum.keySet()) { record.put(key, datum.get(key)); } data.add(record); } datasetModel.setMetadata(metadata); datasetModel.setData(data); dataTable.setModel(datasetModel); rowCountLabel.setText( "Rows: " + datasetModel.getRowCount() + ", Columns: " + datasetModel.getColumnCount()); JTableUtils.packColumns(dataTable, 2); rowCountLabel.invalidate(); dataTable.invalidate(); dataTable.validate(); scrollPane.invalidate(); } }); JPanel panel = new JPanel(new BorderLayout(5, 5)); panel.add(new JLabel("Enrichment Services"), BorderLayout.NORTH); dataServicesList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); dataServicesList.setListData(DataServicesFactory.getServiceNames()); dataServicesList.setPreferredSize(new Dimension(400, 300)); JScrollPane listScrollPane = new JScrollPane(dataServicesList); panel.add(listScrollPane, BorderLayout.CENTER); containerPanel.add(panel); panel = new JPanel(new BorderLayout(5, 5)); JPanel labelAndControlPanel = new JPanel(new BorderLayout(5, 5)); labelAndControlPanel.add(new JLabel("Columns to be enriched"), BorderLayout.CENTER); JPanel controlPanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 5, 5)); JButton selectButton = new JButton(AppIcons.getIcon("select")); controlPanel.add(selectButton); selectButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { boolean columnsAvailable = false; if (datasetModel != null) { Metadata metadata = datasetModel.getMetadata(); if (metadata != null) { columnsAvailable = true; int size = metadata.keySet().size(); String[] values = new String[size]; int index = 0; for (String key : metadata.keySet()) { values[index] = key; index++; } metadataSelectionDialog.setValues(values); } } if (columnsAvailable == true) { metadataSelectionDialog.setVisible(true); } else { JOptionPane.showMessageDialog(rootPanel, AppMessages.ERROR_NO_METADATA); return; } } }); JButton clearButton = new JButton(AppIcons.getIcon("clear")); clearButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { selectedColumnList.setListData(new String[] {}); selectedColumnList.invalidate(); } }); controlPanel.add(clearButton); labelAndControlPanel.add(controlPanel, BorderLayout.EAST); panel.add(labelAndControlPanel, BorderLayout.NORTH); selectedColumnList.setPreferredSize(new Dimension(400, 300)); listScrollPane = new JScrollPane(selectedColumnList); panel.add(listScrollPane, BorderLayout.CENTER); containerPanel.add(panel); executeButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { if (AppCommons.TASKLET.getConnectionProperties() == null) { JOptionPane.showMessageDialog(rootPanel, AppMessages.INFORMATION_CHOOSE_A_CONNECTION); return; } if (AppCommonsUI.PREVIEW_DATASET_MODEL == null || AppCommonsUI.PREVIEW_DATASET_MODEL.getRowCount() <= 0) { JOptionPane.showMessageDialog(rootPanel, AppMessages.ERROR_NO_DATA_TO_ENTRICH); return; } List<String> selectedServiceNames = dataServicesList.getSelectedValuesList(); if ((selectedServiceNames != null && selectedServiceNames.size() == 0) || (selectedColumnNames.length == 0)) { JOptionPane.showMessageDialog(rootPanel, AppMessages.ERROR_MISSING_DATA_SERVICE_AND_COLUMNS); return; } DefaultCusor.startWaitCursor(rootPanel); List<Map<String, String>> data = datasetModel.getData(); Metadata metadata = datasetModel.getMetadata(); for (String name : selectedServiceNames) { DataService service = DataServicesFactory.getDataService(name); if (service instanceof TextAnalysisService) { TextAnalysisService taService = (TextAnalysisService) service; List<Object> objects = new ArrayList<Object>(); for (Map<String, String> datum : data) { objects.add(datum); } taService.setData(objects); taService.setMetadata(metadata); taService.setColumns(selectedColumnNames); taService.execute(); } } rowCountLabel.setText("Rows: " + data.size() + ", Columns: " + metadata.size()); rowCountLabel.invalidate(); datasetModel = new DatasetModel(); datasetModel.setMetadata(metadata); datasetModel.setData(data); datasetModel.fireTableStructureChanged(); datasetModel.fireTableDataChanged(); dataTable.setModel(datasetModel); JTableUtils.packColumns(dataTable, 2); dataTable.invalidate(); dataTable.validate(); scrollPane.invalidate(); DefaultCusor.stopWaitCursor(rootPanel); } }); computeMetricsButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (datasetModel == null || datasetModel.getRowCount() == 0) { JOptionPane.showMessageDialog(rootPanel, AppMessages.ERROR_NO_DATA); return; } List<Map<String, String>> data = datasetModel.getData(); int upsetCount = 0; int happyCount = 0; int negativeCount = 0; int positiveCount = 0; for (Map<String, String> datum : data) { for (String k : datum.keySet()) { if (k.compareTo("uclassify_sentiment") == 0) { String text = datum.get(k); String[] tokens = text.replace("{", "").replace("}", "").split(", "); for (String token : tokens) { String[] nvp = token.split("="); Double score = Double.parseDouble(nvp[1]); if (nvp[0].compareToIgnoreCase("negative") == 0 && score > 50.0) { negativeCount++; } if (nvp[0].compareToIgnoreCase("positive") == 0 && score >= 50.0) { positiveCount++; } } } else if (k.compareTo("uclassify_mood") == 0) { String text = datum.get(k); String[] tokens = text.replace("{", "").replace("}", "").split(", "); for (String token : tokens) { String[] nvp = token.split("="); Double score = Double.parseDouble(nvp[1]); if (nvp[0].compareToIgnoreCase("upset") == 0 && score > 50.0) { upsetCount++; } if (nvp[0].compareToIgnoreCase("happy") == 0 && score >= 50.0) { happyCount++; } } } } } DefaultPieDataset moodDataset = new DefaultPieDataset(); moodDataset.setValue("upset", upsetCount); moodDataset.setValue("happy", happyCount); DefaultPieDataset sentimentDataset = new DefaultPieDataset(); sentimentDataset.setValue("negative", negativeCount); sentimentDataset.setValue("positive", positiveCount); JFreeChart moodChart = ChartFactory.createPieChart("How is mood?", moodDataset, true, true, true); JFreeChart sentimentChart = ChartFactory.createPieChart("How is sentiment?", sentimentDataset, true, true, true); ChartDialog cd = new ChartDialog(AppCommonsUI.MAIN_WINDOW, moodChart, sentimentChart); cd.setSize(new Dimension(900, 500)); cd.setVisible(true); } }); }