List of usage examples for org.jfree.data.general DefaultKeyedValuesDataset DefaultKeyedValuesDataset
DefaultKeyedValuesDataset
From source file:frequencyassignment.charts.Charts.java
public static void displayPie(String name, HashMap<String, Double> categoryValue) { DefaultPieDataset data = new DefaultKeyedValuesDataset(); for (Map.Entry<String, Double> entry : categoryValue.entrySet()) { data.setValue(entry.getKey(), entry.getValue()); }//from w ww . j a v a 2 s .c om JFreeChart chart = ChartFactory.createPieChart("Pie Chart", data, true, true, true); ChartFrame frame = new ChartFrame(name, chart); frame.pack(); frame.setVisible(true); }
From source file:org.jfree.data.general.DefaultKeyedValuesDatasetTest.java
/** * Confirm that cloning works./*from w ww . j a v a 2 s . co m*/ */ @Test public void testCloning() throws CloneNotSupportedException { DefaultKeyedValuesDataset d1 = new DefaultKeyedValuesDataset(); d1.setValue("V1", new Integer(1)); d1.setValue("V2", null); d1.setValue("V3", new Integer(3)); DefaultKeyedValuesDataset d2 = (DefaultKeyedValuesDataset) d1.clone(); assertTrue(d1 != d2); assertTrue(d1.getClass() == d2.getClass()); assertTrue(d1.equals(d2)); }
From source file:org.gvsig.symbology.fmap.symbols.PieChart3DSymbol.java
private void updateDataset() { if (dataset == null) dataset = new DefaultKeyedValuesDataset(); else/*from w w w .ja va2 s .co m*/ dataset.clear(); for (int i = 0; keys != null && i < keys.length; i++) { dataset.insertValue(i, keys[i], values[i]); } }
From source file:org.jfree.data.general.DefaultKeyedValuesDatasetTest.java
/** * Serialize an instance, restore it, and check for equality. *///from ww w .j av a 2 s .c o m public void testSerialization() { DefaultKeyedValuesDataset d1 = new DefaultKeyedValuesDataset(); d1.setValue("C1", new Double(234.2)); d1.setValue("C2", null); d1.setValue("C3", new Double(345.9)); d1.setValue("C4", new Double(452.7)); KeyedValuesDataset d2 = (KeyedValuesDataset) TestUtilities.serialised(d1); assertEquals(d1, d2); }
From source file:canreg.client.analysis.Tools.java
public static JFreeChart generateJChart(Collection<CancerCasesCount> casesCounts, String fileName, String header, FileTypes fileType, ChartType chartType, boolean includeOther, boolean legendOn, Double restCount, Double allCount, Color color, String labelsCategoryName) { JFreeChart chart;//from w ww .j a va2 s. c o m if (chartType == ChartType.PIE) { NumberFormat format = NumberFormat.getInstance(); format.setMaximumFractionDigits(1); DefaultPieDataset dataset = new DefaultKeyedValuesDataset(); int position = 0; for (CancerCasesCount count : casesCounts) { dataset.insertValue(position++, count.toString() + " (" + format.format(count.getCount() / allCount * 100) + "%)", count.getCount()); } if (includeOther) { dataset.insertValue(position++, "Other: " + restCount.intValue() + " (" + format.format(restCount / allCount * 100) + "%)", restCount); } chart = ChartFactory.createPieChart(header, dataset, legendOn, false, Locale.getDefault()); Tools.setPiePlotColours(chart, casesCounts.size() + 1, color.brighter()); } else { // assume barchart DefaultCategoryDataset dataset = new DefaultCategoryDataset(); for (CancerCasesCount count : casesCounts) { dataset.addValue(count.getCount(), count.getLabel(), count.toString()); } if (includeOther) { dataset.addValue(restCount.intValue(), "Other", "Other: " + restCount); } chart = ChartFactory.createStackedBarChart(header, labelsCategoryName, "Cases", dataset, PlotOrientation.HORIZONTAL, legendOn, true, false); Tools.setBarPlotColours(chart, casesCounts.size() + 1, color.brighter()); } return chart; }
From source file:graficoyoutube.Grafico.java
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed // TODO add your handling code here: ChartPanel panel;/*from w w w.ja va2 s . c om*/ JFreeChart chart = null; if (l.isSelected()) { //Graficas de Lineas int validar = 1; XYSplineRenderer renderer = new XYSplineRenderer(); XYSeriesCollection dataset = new XYSeriesCollection(); ValueAxis x = new NumberAxis(); ValueAxis y = new NumberAxis(); XYSeries serie = new XYSeries("Datos"); XYPlot plot; lineas.removeAll(); try { for (int fila = 0; fila <= datos.getRowCount(); fila++) { serie.add(Float.parseFloat(String.valueOf(datos.getValueAt(fila, 0))), Float.parseFloat(String.valueOf(datos.getValueAt(fila, 1)))); //JOptionPane.showMessageDialog(this,datos.getValueAt(fila, 0)+" ,"+ datos.getValueAt(fila, 1)); } } catch (Exception ex) { validar = 0; JOptionPane.showMessageDialog(this, ex.getMessage() + "\n" + validar); } if (validar == 1) { dataset.addSeries(serie); x.setLabel("Eje X"); y.setLabel("Eje Y"); plot = new XYPlot(dataset, x, y, renderer); chart = new JFreeChart(plot); chart.setTitle("Grafico de Lineas YouTube"); } else { JOptionPane.showMessageDialog(this, "Debe llenar la tabla con datos numericos"); } } else { if (b.isSelected()) { //Grafico de Barras DefaultCategoryDataset data = new DefaultCategoryDataset(); String producto1 = "Sopas"; String producto2 = "Soda"; String dia1 = "Dia 1"; String dia2 = "Dia 2"; String dia3 = "Dia 3"; String dia4 = "Dia 4"; data.addValue(18, producto1, dia1); data.addValue(15, producto1, dia2); data.addValue(14, producto1, dia3); data.addValue(1, producto1, dia4); data.addValue(50, producto2, dia1); data.addValue(45, producto2, dia2); data.addValue(31, producto2, dia3); data.addValue(10, producto2, dia4); chart = ChartFactory.createBarChart("Grafico de Barras YouTube", "Dia", "Cantidad", data, PlotOrientation.HORIZONTAL, true, true, true); CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setDomainGridlinesVisible(true); } else { //Grafico de Pastel DefaultPieDataset data = new DefaultKeyedValuesDataset(); data.setValue("Categoria 1", 20); data.setValue("Categoria 2", 60); data.setValue("Categoria 3", 20); chart = ChartFactory.createPieChart3D("Grafico de Pastel", data, true, true, true); } } panel = new ChartPanel(chart); panel.setBounds(5, 10, 410, 400); if (l.isSelected()) { //Lineas lineas.add(panel); lineas.repaint(); } else { if (b.isSelected()) { barras.add(panel); barras.repaint(); } else { pastel.add(panel); pastel.repaint(); } } }
From source file:org.sipfoundry.sipxconfig.site.cdr.CdrReports.java
private Image createCallDirectionCallsPieImage(List<CdrGraphBean> beans) { // Create a dataset DefaultKeyedValuesDataset data = new DefaultKeyedValuesDataset(); // Fill dataset with beans data for (CdrGraphBean directionCall : beans) { data.setValue(directionCall.getKey(), directionCall.getCount()); }// w w w . ja v a2 s . co m // Create a chart with the dataset JFreeChart chart = ChartFactory.createPieChart(EMPTY_TITLE, data, true, true, false); chart.setBackgroundPaint(Color.lightGray); chart.setTitle("Summary - " + getMessages().getMessage(TITLE_CALLDIRECTION_REPORT_KEY)); chart.getTitle().setPaint(Color.BLACK); PiePlot chartplot = (PiePlot) chart.getPlot(); chartplot.setCircular(true); chartplot.setLabelGenerator(new StandardPieSectionLabelGenerator(PIECHART_SECTIONLABEL_FORMAT)); // Create and return the image return chart.createBufferedImage(500, 220, BufferedImage.TYPE_INT_RGB, null); }