org.jfree.data.category.DefaultCategoryDataset Java Examples
The following examples show how to use
org.jfree.data.category.DefaultCategoryDataset.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CategoryPlotTest.java From buffer_bci with GNU General Public License v3.0 | 6 votes |
@Test public void testMapDatasetToRangeAxis() { CategoryDataset dataset = new DefaultCategoryDataset(); CategoryAxis xAxis = new CategoryAxis("X"); NumberAxis yAxis = new NumberAxis("Y"); CategoryItemRenderer renderer = new BarRenderer(); CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer); NumberAxis yAxis2 = new NumberAxis("Y2"); plot.setRangeAxis(22, yAxis2); // add a second dataset DefaultCategoryDataset dataset2 = new DefaultCategoryDataset(); dataset2.setValue(1, "R1", "C1"); plot.setDataset(99, dataset); assertEquals(yAxis, plot.getRangeAxisForDataset(99)); // now map the dataset to the second xAxis plot.mapDatasetToRangeAxis(99, 22); assertEquals(yAxis2, plot.getRangeAxisForDataset(99)); }
Example #2
Source File: CategoryPlotTest.java From buffer_bci with GNU General Public License v3.0 | 6 votes |
@Test public void testDomainMarkerIndices() { CategoryDataset dataset = new DefaultCategoryDataset(); CategoryAxis xAxis = new CategoryAxis("X"); NumberAxis yAxis = new NumberAxis("Y"); CategoryItemRenderer renderer = new BarRenderer(); CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer); // add a second dataset, plotted against a second x axis DefaultCategoryDataset dataset2 = new DefaultCategoryDataset(); dataset2.setValue(1, "R1", "C1"); plot.setDataset(99, dataset); CategoryAxis xAxis2 = new CategoryAxis("X2"); plot.setDomainAxis(1, xAxis2); LineAndShapeRenderer renderer2 = new LineAndShapeRenderer(); plot.setRenderer(99, renderer2); plot.mapDatasetToDomainAxis(99, 1); CategoryMarker xMarker1 = new CategoryMarker(123); plot.addDomainMarker(99, xMarker1, Layer.FOREGROUND); assertTrue(plot.getDomainMarkers(99, Layer.FOREGROUND).contains( xMarker1)); }
Example #3
Source File: CategoryPlotTest.java From ccu-historian with GNU General Public License v3.0 | 6 votes |
@Test public void testMapDatasetToDomainAxis() { CategoryDataset dataset = new DefaultCategoryDataset(); CategoryAxis xAxis = new CategoryAxis("X"); NumberAxis yAxis = new NumberAxis("Y"); CategoryItemRenderer renderer = new BarRenderer(); CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer); CategoryAxis xAxis2 = new CategoryAxis("X2"); plot.setDomainAxis(11, xAxis2); // add a second dataset DefaultCategoryDataset dataset2 = new DefaultCategoryDataset(); dataset2.setValue(1, "R1", "C1"); plot.setDataset(99, dataset); assertEquals(xAxis, plot.getDomainAxisForDataset(99)); // now map the dataset to the second xAxis plot.mapDatasetToDomainAxis(99, 11); assertEquals(xAxis2, plot.getDomainAxisForDataset(99)); }
Example #4
Source File: DefaultCategoryDatasetTests.java From astor with GNU General Public License v2.0 | 6 votes |
/** * Some tests for the getRowCount() method. */ public void testGetRowCount() { DefaultCategoryDataset d = new DefaultCategoryDataset(); assertTrue(d.getRowCount() == 0); d.addValue(1.0, "R1", "C1"); assertTrue(d.getRowCount() == 1); d.addValue(1.0, "R2", "C1"); assertTrue(d.getRowCount() == 2); d.addValue(2.0, "R2", "C1"); assertTrue(d.getRowCount() == 2); // a row of all null values is still counted... d.setValue(null, "R2", "C1"); assertTrue(d.getRowCount() == 2); }
Example #5
Source File: StackedBarRendererTest.java From openstock with GNU General Public License v3.0 | 6 votes |
/** * Some checks for the findRangeBounds() method. */ @Test public void testFindRangeBounds() { StackedBarRenderer r = new StackedBarRenderer(); assertNull(r.findRangeBounds(null)); // an empty dataset should return a null range DefaultCategoryDataset dataset = new DefaultCategoryDataset(); assertNull(r.findRangeBounds(dataset)); dataset.addValue(1.0, "R1", "C1"); assertEquals(new Range(0.0, 1.0), r.findRangeBounds(dataset)); dataset.addValue(-2.0, "R1", "C2"); assertEquals(new Range(-2.0, 1.0), r.findRangeBounds(dataset)); dataset.addValue(null, "R1", "C3"); assertEquals(new Range(-2.0, 1.0), r.findRangeBounds(dataset)); dataset.addValue(2.0, "R2", "C1"); assertEquals(new Range(-2.0, 3.0), r.findRangeBounds(dataset)); dataset.addValue(null, "R2", "C2"); assertEquals(new Range(-2.0, 3.0), r.findRangeBounds(dataset)); }
Example #6
Source File: LogAxisTests.java From astor with GNU General Public License v2.0 | 6 votes |
/** * A simple test for the auto-range calculation looking at a * LogAxis used as the range axis for a CategoryPlot. */ public void testAutoRange1() { DefaultCategoryDataset dataset = new DefaultCategoryDataset(); dataset.setValue(100.0, "Row 1", "Column 1"); dataset.setValue(200.0, "Row 1", "Column 2"); JFreeChart chart = ChartFactory.createBarChart( "Test", "Categories", "Value", dataset, PlotOrientation.VERTICAL, false, false, false ); CategoryPlot plot = (CategoryPlot) chart.getPlot(); LogAxis axis = new LogAxis("Log(Y)"); plot.setRangeAxis(axis); assertEquals(0.0, axis.getLowerBound(), EPSILON); assertEquals(2.6066426411261268E7, axis.getUpperBound(), EPSILON); }
Example #7
Source File: LevelRendererTest.java From SIMVA-SoS with Apache License 2.0 | 6 votes |
/** * Draws the chart with a <code>null</code> info object to make sure that * no exceptions are thrown (particularly by code in the renderer). */ @Test public void testDrawWithNullInfo() { try { DefaultCategoryDataset dataset = new DefaultCategoryDataset(); dataset.addValue(1.0, "S1", "C1"); CategoryPlot plot = new CategoryPlot(dataset, new CategoryAxis("Category"), new NumberAxis("Value"), new LevelRenderer()); JFreeChart chart = new JFreeChart(plot); /* BufferedImage image = */ chart.createBufferedImage(300, 200, null); } catch (NullPointerException e) { fail("No exception should be thrown."); } }
Example #8
Source File: DatasetUtilitiesTests.java From astor with GNU General Public License v2.0 | 6 votes |
/** * A simple check for the findMaximumStackedRangeValue() method. */ public void testFindMaximumStackedRangeValue() { DefaultCategoryDataset dataset = new DefaultCategoryDataset(); // an empty dataset should return a null max Number max = DatasetUtilities.findMaximumStackedRangeValue(dataset); assertNull(max); dataset.addValue(1.0, "R1", "C1"); max = DatasetUtilities.findMaximumStackedRangeValue(dataset); assertEquals(1.0, max.doubleValue(), EPSILON); dataset.addValue(2.0, "R2", "C1"); max = DatasetUtilities.findMaximumStackedRangeValue(dataset); assertEquals(3.0, max.doubleValue(), EPSILON); dataset.addValue(-3.0, "R3", "C1"); max = DatasetUtilities.findMaximumStackedRangeValue(dataset); assertEquals(3.0, max.doubleValue(), EPSILON); dataset.addValue(Double.NaN, "R4", "C1"); max = DatasetUtilities.findMaximumStackedRangeValue(dataset); assertEquals(3.0, max.doubleValue(), EPSILON); }
Example #9
Source File: ChartJFreeChartOutputHistogram.java From gama with GNU General Public License v3.0 | 6 votes |
@Override public void createChart(final IScope scope) { super.createChart(scope); jfreedataset.add(0, new DefaultCategoryDataset()); PlotOrientation orientation = PlotOrientation.VERTICAL; if (reverse_axes) { orientation = PlotOrientation.HORIZONTAL; } if (style.equals(IKeyword.THREE_D)) { chart = ChartFactory.createBarChart(getName(), null, null, null, orientation, true, true, false); } else if (style.equals(IKeyword.STACK)) { chart = ChartFactory.createStackedBarChart(getName(), null, null, null, orientation, true, true, false); } else { chart = ChartFactory.createBarChart(getName(), null, null, null, orientation, true, true, false); } }
Example #10
Source File: MultiplePiePlotTests.java From astor with GNU General Public License v2.0 | 6 votes |
/** * Fetches the legend items and checks the values. */ public void testGetLegendItems() { DefaultCategoryDataset dataset = new DefaultCategoryDataset(); dataset.addValue(35.0, "S1", "C1"); dataset.addValue(45.0, "S1", "C2"); dataset.addValue(55.0, "S2", "C1"); dataset.addValue(15.0, "S2", "C2"); MultiplePiePlot plot = new MultiplePiePlot(dataset); JFreeChart chart = new JFreeChart(plot); LegendItemCollection legendItems = plot.getLegendItems(); assertEquals(2, legendItems.getItemCount()); LegendItem item1 = legendItems.get(0); assertEquals("S1", item1.getLabel()); assertEquals("S1", item1.getSeriesKey()); assertEquals(0, item1.getSeriesIndex()); assertEquals(dataset, item1.getDataset()); assertEquals(0, item1.getDatasetIndex()); LegendItem item2 = legendItems.get(1); assertEquals("S2", item2.getLabel()); assertEquals("S2", item2.getSeriesKey()); assertEquals(1, item2.getSeriesIndex()); assertEquals(dataset, item2.getDataset()); assertEquals(0, item2.getDatasetIndex()); }
Example #11
Source File: LevelRendererTest.java From openstock with GNU General Public License v3.0 | 6 votes |
/** * A check for the datasetIndex and seriesIndex fields in the LegendItem * returned by the getLegendItem() method. */ @Test public void testGetLegendItemSeriesIndex() { DefaultCategoryDataset dataset0 = new DefaultCategoryDataset(); dataset0.addValue(21.0, "R1", "C1"); dataset0.addValue(22.0, "R2", "C1"); DefaultCategoryDataset dataset1 = new DefaultCategoryDataset(); dataset1.addValue(23.0, "R3", "C1"); dataset1.addValue(24.0, "R4", "C1"); dataset1.addValue(25.0, "R5", "C1"); LevelRenderer r = new LevelRenderer(); CategoryPlot plot = new CategoryPlot(dataset0, new CategoryAxis("x"), new NumberAxis("y"), r); plot.setDataset(1, dataset1); /*JFreeChart chart =*/ new JFreeChart(plot); LegendItem li = r.getLegendItem(1, 2); assertEquals("R5", li.getLabel()); assertEquals(1, li.getDatasetIndex()); assertEquals(2, li.getSeriesIndex()); }
Example #12
Source File: CategoryPlotTest.java From SIMVA-SoS with Apache License 2.0 | 6 votes |
@Test public void testMapDatasetToDomainAxis() { CategoryDataset dataset = new DefaultCategoryDataset(); CategoryAxis xAxis = new CategoryAxis("X"); NumberAxis yAxis = new NumberAxis("Y"); CategoryItemRenderer renderer = new BarRenderer(); CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer); CategoryAxis xAxis2 = new CategoryAxis("X2"); plot.setDomainAxis(11, xAxis2); // add a second dataset DefaultCategoryDataset dataset2 = new DefaultCategoryDataset(); dataset2.setValue(1, "R1", "C1"); plot.setDataset(99, dataset); assertEquals(xAxis, plot.getDomainAxisForDataset(99)); // now map the dataset to the second xAxis plot.mapDatasetToDomainAxis(99, 11); assertEquals(xAxis2, plot.getDomainAxisForDataset(99)); }
Example #13
Source File: CategoryPlotTest.java From openstock with GNU General Public License v3.0 | 6 votes |
@Test public void testGetRendererForDataset2() { CategoryDataset dataset = new DefaultCategoryDataset(); CategoryAxis xAxis = new CategoryAxis("X"); NumberAxis yAxis = new NumberAxis("Y"); CategoryItemRenderer renderer = new BarRenderer(); CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer); // add a second dataset DefaultCategoryDataset dataset2 = new DefaultCategoryDataset(); dataset2.setValue(1, "R1", "C1"); plot.setDataset(99, dataset2); // by default, the renderer with index 0 is used assertEquals(renderer, plot.getRendererForDataset(dataset2)); // add a second renderer with the same index as dataset2, now it will // be used CategoryItemRenderer renderer2 = new LineAndShapeRenderer(); plot.setRenderer(99, renderer2); assertEquals(renderer2, plot.getRendererForDataset(dataset2)); }
Example #14
Source File: StandardCategoryURLGeneratorTest.java From openstock with GNU General Public License v3.0 | 6 votes |
/** * Some tests for the generateURL() method. */ @Test public void testGenerateURL() { StandardCategoryURLGenerator g1 = new StandardCategoryURLGenerator(); DefaultCategoryDataset dataset = new DefaultCategoryDataset(); dataset.addValue(1.0, "R1", "C1"); dataset.addValue(2.0, "R2", "C2"); dataset.addValue(3.0, "R&", "C&"); assertEquals("index.html?series=R1&category=C1", g1.generateURL(dataset, 0, 0)); assertEquals("index.html?series=R1&category=C2", g1.generateURL(dataset, 0, 1)); assertEquals("index.html?series=R2&category=C2", g1.generateURL(dataset, 1, 1)); assertEquals("index.html?series=R%26&category=C%26", g1.generateURL(dataset, 2, 2)); }
Example #15
Source File: EditionFinancialChartPanel.java From MtgDesktopCompanion with GNU General Public License v3.0 | 6 votes |
private CategoryDataset getDataSet() { DefaultCategoryDataset dataset = new DefaultCategoryDataset(); try { MagicEdition ed = (MagicEdition)cboEditions.getSelectedItem(); items = MTGControler.getInstance().getEnabled(MTGDao.class).listOrderForEdition(ed); EditionsShakers price = MTGControler.getInstance().getEnabled(MTGDashBoard.class).getShakesForEdition(ed); double totalEd = price.getShakes().stream().mapToDouble(CardShake::getPrice).sum(); if(!items.isEmpty()) { dataset.addValue(totalEd, "Actual Value", ed.getSet() ); dataset.addValue(getTotal(items), "Paid", ed.getSet() ); } } catch(Exception e) { logger.error("erreur calculate dataset",e); } return dataset; }
Example #16
Source File: DefaultCategoryDatasetTests.java From astor with GNU General Public License v2.0 | 6 votes |
/** * Some checks for the addValue() method. */ public void testAddValue() { DefaultCategoryDataset d1 = new DefaultCategoryDataset(); d1.addValue(null, "R1", "C1"); assertNull(d1.getValue("R1", "C1")); d1.addValue(new Double(1.0), "R2", "C1"); assertEquals(new Double(1.0), d1.getValue("R2", "C1")); boolean pass = false; try { d1.addValue(new Double(1.1), null, "C2"); } catch (IllegalArgumentException e) { pass = true; } assertTrue(pass); }
Example #17
Source File: AreaRendererTest.java From buffer_bci with GNU General Public License v3.0 | 6 votes |
/** * A check for the datasetIndex and seriesIndex fields in the LegendItem * returned by the getLegendItem() method. */ @Test public void testGetLegendItemSeriesIndex() { DefaultCategoryDataset dataset0 = new DefaultCategoryDataset(); dataset0.addValue(21.0, "R1", "C1"); dataset0.addValue(22.0, "R2", "C1"); DefaultCategoryDataset dataset1 = new DefaultCategoryDataset(); dataset1.addValue(23.0, "R3", "C1"); dataset1.addValue(24.0, "R4", "C1"); dataset1.addValue(25.0, "R5", "C1"); AreaRenderer r = new AreaRenderer(); CategoryPlot plot = new CategoryPlot(dataset0, new CategoryAxis("x"), new NumberAxis("y"), r); plot.setDataset(1, dataset1); /*JFreeChart chart =*/ new JFreeChart(plot); LegendItem li = r.getLegendItem(1, 2); assertEquals("R5", li.getLabel()); assertEquals(1, li.getDatasetIndex()); assertEquals(2, li.getSeriesIndex()); }
Example #18
Source File: DatasetUtilities.java From astor with GNU General Public License v2.0 | 6 votes |
/** * Creates a {@link CategoryDataset} by copying the data from the supplied * {@link KeyedValues} instance. * * @param rowKey the row key (<code>null</code> not permitted). * @param rowData the row data (<code>null</code> not permitted). * * @return A dataset. */ public static CategoryDataset createCategoryDataset(Comparable rowKey, KeyedValues rowData) { if (rowKey == null) { throw new IllegalArgumentException("Null 'rowKey' argument."); } if (rowData == null) { throw new IllegalArgumentException("Null 'rowData' argument."); } DefaultCategoryDataset result = new DefaultCategoryDataset(); for (int i = 0; i < rowData.getItemCount(); i++) { result.addValue(rowData.getValue(i), rowKey, rowData.getKey(i)); } return result; }
Example #19
Source File: AbstractCategoryItemRendererTest.java From ccu-historian with GNU General Public License v3.0 | 6 votes |
/** * Some checks for the findRangeBounds() method. */ @Test public void testFindRangeBounds() { AbstractCategoryItemRenderer r = new LineAndShapeRenderer(); assertNull(r.findRangeBounds(null)); // an empty dataset should return a null range DefaultCategoryDataset dataset = new DefaultCategoryDataset(); assertNull(r.findRangeBounds(dataset)); dataset.addValue(1.0, "R1", "C1"); assertEquals(new Range(1.0, 1.0), r.findRangeBounds(dataset)); dataset.addValue(-2.0, "R1", "C2"); assertEquals(new Range(-2.0, 1.0), r.findRangeBounds(dataset)); dataset.addValue(null, "R1", "C3"); assertEquals(new Range(-2.0, 1.0), r.findRangeBounds(dataset)); }
Example #20
Source File: StackedAreaRendererTest.java From buffer_bci with GNU General Public License v3.0 | 6 votes |
/** * Some checks for the findRangeBounds() method. */ @Test public void testFindRangeBounds() { StackedAreaRenderer r = new StackedAreaRenderer(); assertNull(r.findRangeBounds(null)); // an empty dataset should return a null range DefaultCategoryDataset dataset = new DefaultCategoryDataset(); assertNull(r.findRangeBounds(dataset)); dataset.addValue(1.0, "R1", "C1"); assertEquals(new Range(0.0, 1.0), r.findRangeBounds(dataset)); dataset.addValue(-2.0, "R1", "C2"); assertEquals(new Range(-2.0, 1.0), r.findRangeBounds(dataset)); dataset.addValue(null, "R1", "C3"); assertEquals(new Range(-2.0, 1.0), r.findRangeBounds(dataset)); dataset.addValue(2.0, "R2", "C1"); assertEquals(new Range(-2.0, 3.0), r.findRangeBounds(dataset)); dataset.addValue(null, "R2", "C2"); assertEquals(new Range(-2.0, 3.0), r.findRangeBounds(dataset)); }
Example #21
Source File: SpiderWebPlotTests.java From astor with GNU General Public License v2.0 | 6 votes |
/** * Draws the chart with a null info object to make sure that no exceptions * are thrown. */ public void testDrawWithNullInfo() { DefaultCategoryDataset dataset = new DefaultCategoryDataset(); dataset.addValue(35.0, "S1", "C1"); dataset.addValue(45.0, "S1", "C2"); dataset.addValue(55.0, "S1", "C3"); dataset.addValue(15.0, "S1", "C4"); dataset.addValue(25.0, "S1", "C5"); SpiderWebPlot plot = new SpiderWebPlot(dataset); JFreeChart chart = new JFreeChart(plot); boolean success = false; try { 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(); success = true; } catch (Exception e) { success = false; } assertTrue(success); }
Example #22
Source File: JMethodObfAnalysis.java From JByteMod-Beta with GNU General Public License v2.0 | 6 votes |
protected CategoryDataset analyze(Map<String, ClassNode> nodes) { MethodResult mr = analyzer.analyzeMethod(); final DefaultCategoryDataset dataset = new DefaultCategoryDataset(); for (MethodObfType t : MethodObfType.values()) { if (t == MethodObfType.NONE) continue; int i = 0; for (MethodObfType not : mr.mobf) { if (not == t) { i++; } } dataset.addValue((double) (i / (double) mr.mobf.size()) * 100d, "", t.getType()); } return dataset; }
Example #23
Source File: MinMaxCategoryRendererTests.java From astor with GNU General Public License v2.0 | 6 votes |
/** * Draws the chart with a <code>null</code> info object to make sure that * no exceptions are thrown (particularly by code in the renderer). */ public void testDrawWithNullInfo() { boolean success = false; try { DefaultCategoryDataset dataset = new DefaultCategoryDataset(); dataset.addValue(1.0, "S1", "C1"); CategoryPlot plot = new CategoryPlot(dataset, new CategoryAxis("Category"), new NumberAxis("Value"), new MinMaxCategoryRenderer()); JFreeChart chart = new JFreeChart(plot); /* BufferedImage image = */ chart.createBufferedImage(300, 200, null); success = true; } catch (NullPointerException e) { e.printStackTrace(); success = false; } assertTrue(success); }
Example #24
Source File: LevelRendererTest.java From SIMVA-SoS with Apache License 2.0 | 6 votes |
/** * A check for the datasetIndex and seriesIndex fields in the LegendItem * returned by the getLegendItem() method. */ @Test public void testGetLegendItemSeriesIndex() { DefaultCategoryDataset dataset0 = new DefaultCategoryDataset(); dataset0.addValue(21.0, "R1", "C1"); dataset0.addValue(22.0, "R2", "C1"); DefaultCategoryDataset dataset1 = new DefaultCategoryDataset(); dataset1.addValue(23.0, "R3", "C1"); dataset1.addValue(24.0, "R4", "C1"); dataset1.addValue(25.0, "R5", "C1"); LevelRenderer r = new LevelRenderer(); CategoryPlot plot = new CategoryPlot(dataset0, new CategoryAxis("x"), new NumberAxis("y"), r); plot.setDataset(1, dataset1); /*JFreeChart chart =*/ new JFreeChart(plot); LegendItem li = r.getLegendItem(1, 2); assertEquals("R5", li.getLabel()); assertEquals(1, li.getDatasetIndex()); assertEquals(2, li.getSeriesIndex()); }
Example #25
Source File: DatasetUtilitiesTest.java From SIMVA-SoS with Apache License 2.0 | 6 votes |
/** * A further test for the cumulative range calculation. */ @Test public void testCumulativeRange2() { DefaultCategoryDataset dataset = new DefaultCategoryDataset(); dataset.addValue(-21.4, "Series 1", "Start Value"); dataset.addValue(11.57, "Series 1", "Delta 1"); dataset.addValue(3.51, "Series 1", "Delta 2"); dataset.addValue(-12.36, "Series 1", "Delta 3"); dataset.addValue(3.39, "Series 1", "Delta 4"); dataset.addValue(38.68, "Series 1", "Delta 5"); dataset.addValue(-43.31, "Series 1", "Delta 6"); dataset.addValue(-29.59, "Series 1", "Delta 7"); dataset.addValue(35.30, "Series 1", "Delta 8"); dataset.addValue(5.0, "Series 1", "Delta 9"); Range range = DatasetUtilities.findCumulativeRangeBounds(dataset); assertEquals(-49.51, range.getLowerBound(), 0.00000001); assertEquals(23.39, range.getUpperBound(), 0.00000001); }
Example #26
Source File: DistributionPlotter.java From rapidminer-studio with GNU Affero General Public License v3.0 | 6 votes |
private CategoryDataset createNominalDataSet() { DefaultCategoryDataset dataset = new DefaultCategoryDataset(); for (Integer classIndex : model.getClassIndices()) { DiscreteDistribution distribution = (DiscreteDistribution) model.getDistribution(classIndex, translateToModelColumn(plotColumn)); String labelName = model.getClassName(classIndex); // sort values by name TreeMap<String, Double> valueMap = new TreeMap<String, Double>(); for (Double value : distribution.getValues()) { String valueName; if (Double.isNaN(value)) { valueName = "Unknown"; } else { valueName = distribution.mapValue(value); } valueMap.put(valueName, value); } for (Entry<String, Double> entry : valueMap.entrySet()) { dataset.addValue(distribution.getProbability(entry.getValue()), labelName, entry.getKey()); } } return dataset; }
Example #27
Source File: ServerWideReportManagerImpl.java From sakai with Educational Community License v2.0 | 6 votes |
private CategoryDataset getTopActivitiesDataSet () { List<ServerWideStatsRecord> topActivitiesList = getTop20Activities (); if (topActivitiesList == null) { return null; } DefaultCategoryDataset dataset = new DefaultCategoryDataset (); for (ServerWideStatsRecord regularUsers : topActivitiesList) { String event = (String) regularUsers.get (0); dataset.addValue ((Double) regularUsers.get (1), "last 7 days", event); dataset.addValue ((Double) regularUsers.get (2), "last 30 days", event); dataset.addValue ((Double) regularUsers.get (3), "last 365 days", event); } return dataset; }
Example #28
Source File: DatasetUtilitiesTests.java From astor with GNU General Public License v2.0 | 6 votes |
/** * Some checks for the iterateRangeBounds() method. */ public void testIterateRangeBounds2_CategoryDataset() { // an empty dataset should return a null range DefaultCategoryDataset dataset = new DefaultCategoryDataset(); Range r = DatasetUtilities.iterateRangeBounds(dataset, false); assertNull(r); // a dataset with a single value dataset.addValue(1.23, "R1", "C1"); r = DatasetUtilities.iterateRangeBounds(dataset, false); assertEquals(1.23, r.getLowerBound(), EPSILON); assertEquals(1.23, r.getUpperBound(), EPSILON); // null is ignored dataset.addValue(null, "R2", "C1"); r = DatasetUtilities.iterateRangeBounds(dataset, false); assertEquals(1.23, r.getLowerBound(), EPSILON); assertEquals(1.23, r.getUpperBound(), EPSILON); // a Double.NaN should be ignored dataset.addValue(Double.NaN, "R2", "C1"); r = DatasetUtilities.iterateRangeBounds(dataset, false); assertEquals(1.23, r.getLowerBound(), EPSILON); assertEquals(1.23, r.getUpperBound(), EPSILON); }
Example #29
Source File: AreaRendererTest.java From SIMVA-SoS with Apache License 2.0 | 6 votes |
/** * A check for the datasetIndex and seriesIndex fields in the LegendItem * returned by the getLegendItem() method. */ @Test public void testGetLegendItemSeriesIndex() { DefaultCategoryDataset dataset0 = new DefaultCategoryDataset(); dataset0.addValue(21.0, "R1", "C1"); dataset0.addValue(22.0, "R2", "C1"); DefaultCategoryDataset dataset1 = new DefaultCategoryDataset(); dataset1.addValue(23.0, "R3", "C1"); dataset1.addValue(24.0, "R4", "C1"); dataset1.addValue(25.0, "R5", "C1"); AreaRenderer r = new AreaRenderer(); CategoryPlot plot = new CategoryPlot(dataset0, new CategoryAxis("x"), new NumberAxis("y"), r); plot.setDataset(1, dataset1); /*JFreeChart chart =*/ new JFreeChart(plot); LegendItem li = r.getLegendItem(1, 2); assertEquals("R5", li.getLabel()); assertEquals(1, li.getDatasetIndex()); assertEquals(2, li.getSeriesIndex()); }
Example #30
Source File: SpiderWebPlotTests.java From astor with GNU General Public License v2.0 | 6 votes |
/** * Draws the chart with a null info object to make sure that no exceptions * are thrown. */ public void testDrawWithNullInfo() { DefaultCategoryDataset dataset = new DefaultCategoryDataset(); dataset.addValue(35.0, "S1", "C1"); dataset.addValue(45.0, "S1", "C2"); dataset.addValue(55.0, "S1", "C3"); dataset.addValue(15.0, "S1", "C4"); dataset.addValue(25.0, "S1", "C5"); SpiderWebPlot plot = new SpiderWebPlot(dataset); JFreeChart chart = new JFreeChart(plot); boolean success = false; try { 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(); success = true; } catch (Exception e) { success = false; } assertTrue(success); }