/** * Updates the data set for both charts with the contents of the supplied Hashtable. The Hashtable * is expected to contain the following items: * * <ul> * <li>down - The number of links currently in a down state * <li>up - The number of links currently in an up state * <li>unknown - The number of links currently in an unknown state * </ul> * * @param linkStats The hashtable containing the entries indicating current link statistics. */ public void updateData(Hashtable<String, Integer> linkStats) { dpdCurrentData.insertValue(0, "Link Down", linkStats.get("down")); dpdCurrentData.insertValue(1, "Link Up", linkStats.get("up")); dpdCurrentData.insertValue(2, "Link State Unknown", linkStats.get("unknown")); dcdPreviousData.addValue( linkStats.get("down"), "Link Down", Calendar.getInstance().getTime().toString()); dcdPreviousData.addValue( linkStats.get("up"), "Link Up", Calendar.getInstance().getTime().toString()); dcdPreviousData.addValue( linkStats.get("unknown"), "Link State Unknown", Calendar.getInstance().getTime().toString()); }
private static PieDataset createDataset(String[] name, double[] number) { DefaultPieDataset result = new DefaultPieDataset(); for (int i = 0; i < name.length; i++) { result.setValue(name[i], number[i]); } return result; }
/** Some checks for the getLegendItems() method. */ @Test public void testGetLegendItems() { DefaultPieDataset dataset = new DefaultPieDataset(); dataset.setValue("Item 1", 1.0); dataset.setValue("Item 2", 2.0); dataset.setValue("Item 3", 0.0); dataset.setValue("Item 4", null); PiePlot plot = new PiePlot(dataset); plot.setIgnoreNullValues(false); plot.setIgnoreZeroValues(false); List<LegendItem> items = plot.getLegendItems(); assertEquals(4, items.size()); // check that null items are ignored if requested plot.setIgnoreNullValues(true); items = plot.getLegendItems(); assertEquals(3, items.size()); // check that zero items are ignored if requested plot.setIgnoreZeroValues(true); items = plot.getLegendItems(); assertEquals(2, items.size()); // check that negative items are always ignored dataset.setValue("Item 5", -1.0); items = plot.getLegendItems(); assertEquals(2, items.size()); }
/** * 创建一个饼图表的数据集 * * @return */ private PieDataset getPieDataset() { DefaultPieDataset dataset = new DefaultPieDataset(); dataset.setValue("JAVA从入门到精通(第2版)", 500); dataset.setValue("视频学JAVA", 800); dataset.setValue("JAVA全能速查宝典", 1000); return dataset; }
// create data set for JFreeChart pie chart private PieDataset createChartDataSet( double proportion1, double proportion2, String key1, String key2) { DefaultPieDataset dataSet = new DefaultPieDataset(); dataSet.setValue(key1, proportion1); dataSet.setValue(key2, proportion2); return dataSet; }
/** * Cria um grafico de pizza com os dados fornecidos * * @param titulo <code>String</code> com o titulo do grafico * @param listaNomesValores {@code List<NomeValor>} lista com os nomes e valores para o grafico * @param legendasAdicionais <code>String...</code> com as legendas adicionais * @param graficoEm3D <code>boolean</code> com <code>true</code> se o grafico é em 3D ou não. */ public GraficoPizza( String titulo, List<NomeValor> listaNomesValores, boolean graficoEm3D, final String... legendasAdicionais) { // Cria um dataSet para inserir os dados que serão passados para a criação do grafico tipo Pie DefaultPieDataset pieDataset = new DefaultPieDataset(); this.graficoEm3D = graficoEm3D; // Adiciona os dados ao dataSet deve somar um total de 100% double valorUmPorCentoVotos = this.valorUmVotoEmPorCento(listaNomesValores); String valor; for (NomeValor nomesValores : listaNomesValores) { valor = String.format("%.2f%%", nomesValores.getValor() * valorUmPorCentoVotos); pieDataset.setValue(nomesValores.getNome() + "(" + valor + ")", nomesValores.getValor()); } // Cria um objeto JFreeChart passando os seguintes parametros if (!this.graficoEm3D) { this.grafico = ChartFactory.createPieChart( titulo, // Titulo do grafico pieDataset, // DataSet true, // Para mostrar ou não a legenda true, // Para mostrar ou não os tooltips false); } else { // em 3D this.grafico = ChartFactory.createPieChart3D( titulo, // Titulo do grafico pieDataset, // DataSet true, // Para mostrar ou não a legenda true, // Para mostrar ou não os tooltips false); } if (this.grafico != null) { LegendTitle legenda = new LegendTitle( new LegendItemSource() { @Override public LegendItemCollection getLegendItems() { LegendItemCollection legenda = new LegendItemCollection(); for (String texto : legendasAdicionais) { legenda.add(new LegendItem(texto)); } return legenda; } }); float larguraBordaLegenda = 0.6F; legenda.setBorder( larguraBordaLegenda, larguraBordaLegenda, larguraBordaLegenda, larguraBordaLegenda); legenda.setPosition(RectangleEdge.BOTTOM); legenda.setHorizontalAlignment(HorizontalAlignment.LEFT); this.grafico.addLegend(legenda); } }
private static PieDataset createDataset() { DefaultPieDataset defaultpiedataset = new DefaultPieDataset(); defaultpiedataset.setValue("Network", new Double(43.200000000000003D)); defaultpiedataset.setValue("Database", new Double(10D)); defaultpiedataset.setValue("Operating System", new Double(17.5D)); defaultpiedataset.setValue("Software Engineering", new Double(32.5D)); defaultpiedataset.setValue("Programming Language", new Double(12.5D)); return defaultpiedataset; }
private PieDataset createSampleDataSet() { final DefaultPieDataset result = new DefaultPieDataset(); result.setValue("Java", new Double(43.2)); result.setValue("Visual Basic", new Double(10.0)); result.setValue("C/C++", new Double(17.5)); result.setValue("PHP", new Double(32.5)); result.setValue("Perl", new Double(1.0)); return result; }
public static DefaultPieDataset getPieDataset(String chartName, DBSeerDataSet dataset) { 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; } 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, yArray[c]); } else { pieDataSet.setValue("Transaction Type " + (c + 1), yArray[c]); } } } } return pieDataSet; }
/** * Creates a sample dataset. * * @return a sample dataset. */ private static DefaultPieDataset createDataset() { DefaultPieDataset dataset = new DefaultPieDataset(); dataset.setValue("Section A", new Double(43.2)); dataset.setValue("Section B", new Double(10.0)); dataset.setValue("Section C", new Double(27.5)); dataset.setValue("Section D", new Double(17.5)); dataset.setValue("Section E", new Double(11.0)); dataset.setValue("Section F", new Double(19.4)); return dataset; }
/** * Creates a sample dataset. * * @return A sample dataset. */ private static PieDataset createDataset() { 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)); return dataset; }
/** Create dataset. */ private PieDataset createDataset() { DefaultPieDataset dataset = new DefaultPieDataset(); Map<Comparable<?>, Double> values = data.getValues(); for (Comparable<?> key : values.keySet()) { dataset.setValue(key, values.get(key)); } return dataset; }
public DefaultPieDataset getDataSet() { DefaultPieDataset dataset = new DefaultPieDataset(); for (int i = 0; i < this.collect.size(); i++) { dataset.setValue(this.collect.get(i).getKey(), this.collect.get(i).getValue()); } return dataset; }
@Override protected Dataset getDataset() { DefaultPieDataset result = new DefaultPieDataset(); for (String key : keySet) { List<V> values = getDataRow(key); for (int i = 0; i < values.size(); i++) { result.setValue(getHeader(i), (Number) values.get(i)); } } return result; }
public static JPanel createCustomDemoPanel(Map<String, Double> map) { // set model DefaultPieDataset defaultpiedataset = new DefaultPieDataset(); for (String key : map.keySet()) { defaultpiedataset.setValue(key, map.get(key)); } // assign to view JFreeChart jfreechart = createChart(createDataset()); Rotator rotator = new Rotator((PiePlot3D) jfreechart.getPlot()); rotator.start(); return new ChartPanel(jfreechart); }
public MouseListenerDemo1(String s) { super(s); DefaultPieDataset defaultpiedataset = new DefaultPieDataset(); defaultpiedataset.setValue("Java", new Double(43.200000000000003D)); defaultpiedataset.setValue("Visual Basic", new Double(0.0D)); defaultpiedataset.setValue("C/C++", new Double(17.5D)); org.jfree.chart.JFreeChart jfreechart = ChartFactory.createPieChart("Pie Chart Demo 1", defaultpiedataset, true, true, false); ChartPanel chartpanel = new ChartPanel(jfreechart, false, false, false, false, false); chartpanel.addChartMouseListener(this); chartpanel.setPreferredSize(new Dimension(500, 270)); setContentPane(chartpanel); }
/** Draws a pie chart where the label generator returns null. */ @Test public void testDrawWithNullLegendLabels() { DefaultPieDataset dataset = new DefaultPieDataset(); dataset.setValue("L1", 12.0); dataset.setValue("L2", 11.0); JFreeChart chart = ChartFactory.createPieChart("Test", dataset); PiePlot plot = (PiePlot) chart.getPlot(); plot.setLegendLabelGenerator(new NullLegendLabelGenerator()); BufferedImage image = new BufferedImage(200, 100, BufferedImage.TYPE_INT_RGB); Graphics2D g2 = image.createGraphics(); chart.draw(g2, new Rectangle2D.Double(0, 0, 200, 100), null, null); g2.dispose(); }
/** Some checks for the getIndex() method. */ public void testGetIndex() { DefaultPieDataset d = new DefaultPieDataset(); d.setValue("A", 1.0); d.setValue("B", 2.0); assertEquals(0, d.getIndex("A")); assertEquals(1, d.getIndex("B")); assertEquals(-1, d.getIndex("XX")); boolean pass = false; try { d.getIndex(null); } catch (IllegalArgumentException e) { pass = true; } assertTrue(pass); }
private PdfPCell createKPGSPieChartCell(KeyValue[] values, String title) throws IOException, BadElementException { DefaultPieDataset dataset = new DefaultPieDataset(); for (int n = 0; n < values.length; n++) { dataset.setValue(values[n].getKey(), new Double(values[n].getValue()).doubleValue()); } // create chart final JFreeChart chart = ChartFactory.createPieChart( title, // chart title dataset, // data true, // legend false, // tooltips false // urls ); // customize chart PiePlot plot = (PiePlot) chart.getPlot(); plot.setBackgroundPaint(java.awt.Color.WHITE); if (values.length > 0) { if (values[0].getKey().equalsIgnoreCase("?") && values.length > 1) { plot.setExplodePercent(values[1].getKey(), 0.2); } else { plot.setExplodePercent(values[0].getKey(), 0.2); } } plot.setLegendLabelGenerator(new KPGSLegendGenerator()); plot.setLabelGenerator(new KPGSLabelGenerator(values)); plot.setOutlineVisible(false); chart.setAntiAlias(true); LegendTitle legendTitle = (LegendTitle) chart.getSubtitle(0); legendTitle.setFrame(BlockBorder.NONE); legendTitle.setBackgroundPaint(null); ByteArrayOutputStream os = new ByteArrayOutputStream(); ChartUtilities.writeChartAsPNG( os, chart, MedwanQuery.getInstance().getConfigInt("stats.piechartwidth", 640), MedwanQuery.getInstance().getConfigInt("stats.piechartheight", 480)); cell = new PdfPCell(); cell.setColspan(50); cell.setImage(Image.getInstance(os.toByteArray())); cell.setBorder(PdfPCell.NO_BORDER); cell.setPaddingLeft(5); cell.setPaddingRight(5); return cell; }
/** * Handles actions. * * @param e the action event. */ public void actionPerformed(ActionEvent e) { String cmd = e.getActionCommand(); if ("BY_KEY".equals(cmd)) { if (!this.ascendingByKey) { this.dataset.sortByKeys(SortOrder.ASCENDING); this.ascendingByKey = true; } else { this.dataset.sortByKeys(SortOrder.DESCENDING); this.ascendingByKey = false; } } else if ("BY_VALUE".equals(cmd)) { if (!this.ascendingByValue) { this.dataset.sortByValues(SortOrder.ASCENDING); this.ascendingByValue = true; } else { this.dataset.sortByValues(SortOrder.DESCENDING); this.ascendingByValue = false; } } else if ("RANDOM".equals(cmd)) { // we create a new dataset here - that's a bit wasteful, // but the DefaultPieDataset will need new methods before we // can shuffle it 'in place'... List keys = new ArrayList(this.dataset.getKeys()); Collections.shuffle(keys); DefaultPieDataset pd = new DefaultPieDataset(); Iterator iterator = keys.iterator(); while (iterator.hasNext()) { Comparable key = (Comparable) iterator.next(); pd.setValue(key, this.dataset.getValue(key)); } PiePlot plot = (PiePlot) this.chart.getPlot(); plot.setDataset(pd); this.dataset = pd; } else if ("LABELS".equals(cmd)) { PiePlot plot = (PiePlot) this.chart.getPlot(); boolean simple = plot.getSimpleLabels(); if (simple) { plot.setInteriorGap(0.05); plot.setSimpleLabels(false); } else { plot.setInteriorGap(0.01); plot.setSimpleLabels(true); } } }
public void setColor(PiePlot plot, DefaultPieDataset dataset) { List<Comparable> keys = dataset.getKeys(); int aInt; for (int i = 0; i < keys.size(); i++) { aInt = i % this.color.length; plot.setSectionPaint(keys.get(i), this.color[aInt]); } }
/** Confirm that cloning works. */ public void testCloning() { DefaultPieDataset d1 = new DefaultPieDataset(); d1.setValue("V1", new Integer(1)); d1.setValue("V2", null); d1.setValue("V3", new Integer(3)); DefaultPieDataset d2 = null; try { d2 = (DefaultPieDataset) d1.clone(); } catch (CloneNotSupportedException e) { System.err.println("Failed to clone."); } assertTrue(d1 != d2); assertTrue(d1.getClass() == d2.getClass()); assertTrue(d1.equals(d2)); }
/** * Description: * * @param view */ public NodeStatusController(NodeStatusPanel view) { super(); this.view = view; dataset = new DefaultPieDataset(); StateLongTypeViz[] states = StateLongTypeViz.values(); for (int i = 0; i < states.length; i++) { dataset.setValue(states[i].getName(), 0); } view.setDataset(dataset, StateLongTypeViz.colors); }
public static JFreeChart generatePieChart(JSONArray IndividualPDFChart) { DefaultPieDataset dataSet = new DefaultPieDataset(); for (int i = 0; i < IndividualPDFChart.size(); i++) { JSONObject jsonChart = IndividualPDFChart.getJSONObject(i); dataSet.setValue( jsonChart.getString(PDFConstants.PieData1), Double.parseDouble(jsonChart.getString(PDFConstants.PieData2))); } JFreeChart chart = ChartFactory.createPieChart(PDFConstants.PieChartTitle, dataSet, true, true, false); // PiePlot3D plot = (PiePlot3D) chart.getPlot(); // plot.setStartAngle(290); // plot.setDirection(Rotation.CLOCKWISE); // plot.setForegroundAlpha(0.5f); // return chart; }
private DefaultPieDataset createDataset( List<Map<String, Object>> dataList, String nameField, String valueField) { DefaultPieDataset dataset = new DefaultPieDataset(); if (dataList.size() == 0) return dataset; Map<String, Object> firstMap = dataList.get(0); if (!firstMap.containsKey(nameField) || !firstMap.containsKey(valueField)) throw new RuntimeException("配置的名称字段或者值字段在数据源中不存在,请检查配置的字段名称是否正确,或者数据源配置是否正确!"); String nameKey = null; Number value = 0; for (Map<String, Object> data : dataList) { nameKey = (String) data.get(nameField); value = (Number) data.get(valueField); dataset.setValue(nameKey, value); } return dataset; }
public void carregarGrafico() { Caixa caixa; if (this.frame.getCbxResCaixa() != null) { caixa = this.frame.getCbxResCaixa(); } else { this.frame.setGrafico(null); return; } DefaultPieDataset grafico = new DefaultPieDataset(); ArrayList<Object[]> dadosGrafico = this.lancamentoDAO.selectLancamentosGrafico( caixa.getCodCaixa(), DateTools.parseDateToInteger(this.perDataIni), DateTools.parseDateToInteger(this.perDataFim), this.frame.getCkbResumoCaixa()); if (dadosGrafico.isEmpty()) { this.frame.setGrafico(null); return; } for (Object[] item : dadosGrafico) { String conta = (String) item[0]; Double valor = (Double) item[1]; grafico.setValue(conta, valor); } JFreeChart chart = ChartFactory.createPieChart("", grafico); chart.removeLegend(); chart.removeSubtitle(null); this.frame.setGrafico(chart); }
private BufferedImage generarGraficoTorta( String titulo, double[] valores, String[] funciones, int anchoImagen, int altoImagen) { if (valores.length != funciones.length) { return null; } DefaultPieDataset pieDataset = new DefaultPieDataset(); for (int i = 0; i < valores.length; i++) { pieDataset.setValue(funciones[i], valores[i]); } JFreeChart chart = ChartFactory.createPieChart(titulo, pieDataset, true, true, false); chart.setBackgroundPaint(null); chart.getTitle().setPaint(LookAndFeelEntropy.COLOR_FUENTE_TITULO_PANEL); chart.getTitle().setFont(LookAndFeelEntropy.FUENTE_TITULO_GRANDE); chart.setBorderVisible(false); chart.getLegend().setItemFont(LookAndFeelEntropy.FUENTE_REGULAR); chart.getLegend().setBackgroundPaint(LookAndFeelEntropy.COLOR_TABLA_PRIMARIO); PiePlot plot = (PiePlot) chart.getPlot(); plot.setBackgroundPaint(null); plot.setBackgroundImageAlpha(0.0f); plot.setSimpleLabels(true); plot.setOutlineVisible(false); for (int i = 0; i < valores.length; i++) { plot.setSectionPaint( funciones[i], generarColorAleatorio(Color.ORANGE)); // LookAndFeelEntropy.COLOR_FUENTE_TITULO_PANEL)); plot.setExplodePercent(funciones[i], 0.10); } PieSectionLabelGenerator gen = new StandardPieSectionLabelGenerator( "{0}: {1} ({2})", new DecimalFormat("0"), new DecimalFormat("0%")); plot.setLabelGenerator(gen); this.lastChart = chart; // Generamos una imagen return chart.createBufferedImage(anchoImagen, altoImagen); }
/** Some checks for the getKey(int) method. */ public void testGetKey() { DefaultPieDataset d = new DefaultPieDataset(); d.setValue("A", 1.0); d.setValue("B", 2.0); assertEquals("A", d.getKey(0)); assertEquals("B", d.getKey(1)); boolean pass = false; try { d.getKey(-1); } catch (IndexOutOfBoundsException e) { pass = true; } assertTrue(pass); pass = false; try { d.getKey(2); } catch (IndexOutOfBoundsException e) { pass = true; } assertTrue(pass); }
private void taxPie( Rectangle rct, double totalValue, double tax, String taxLabel, String netLabel) { double taxPercent = (tax / totalValue) * 100; double netValuePercent = 100 - taxPercent; DefaultPieDataset dataset = new DefaultPieDataset(); dataset.setValue(taxLabel, taxPercent); dataset.setValue(netLabel, netValuePercent); PiePlot3D plot = new PiePlot3D(dataset); plot.setLabelGenerator(new StandardPieItemLabelGenerator()); plot.setInsets(new Insets(0, 5, 5, 5)); plot.setToolTipGenerator(new CustomToolTipGenerator()); plot.setLabelGenerator(new CustomLabelGenerator()); plot.setSectionPaint(0, new Color(pgRed)); plot.setSectionPaint(1, new Color(pgGreen)); plot.setForegroundAlpha(.6f); plot.setOutlinePaint(Color.white); plot.setBackgroundPaint(Color.white); JFreeChart chart = new JFreeChart("Asset Distribution", JFreeChart.DEFAULT_TITLE_FONT, plot, true); chart.setBackgroundPaint(Color.white); chart.setAntiAlias(true); Rectangle page = rct; try { Image img = Image.getInstance( chart.createBufferedImage((int) page.getWidth(), (int) page.getHeight()), null); drawDiagram(img, rct, 0, 72); } catch (Exception e) { System.out.println(e.getMessage()); } }
private static PieDataset createDataset(StateBean sb) { DefaultPieDataset localDefaultPieDataset = new DefaultPieDataset(); localDefaultPieDataset.setValue("正常", sb.getOk()); localDefaultPieDataset.setValue("危险", sb.getWarn()); localDefaultPieDataset.setValue("错误", sb.getError()); localDefaultPieDataset.setValue("禁止", sb.getDisable()); localDefaultPieDataset.setValue("无监测数据", sb.getBad()); return localDefaultPieDataset; }