public void visualizarSerieChartAsignRescateVict(Color color,CategoryDataset dataset) { ChartPanel chartPanel = new ChartPanel(chartNotifAsigResc); chartNotifAsigResc.setBackgroundPaint(Color.white); CategoryPlot plot = (CategoryPlot) chartNotifAsigResc.getPlot(); plot.setBackgroundPaint(color); plot.setDataset(dataset); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setUpperMargin(0.15); CategoryItemRenderer renderer = plot.getRenderer(); renderer.setItemLabelGenerator(new LabelGenerator(50.0)); renderer.setItemLabelFont(new Font("Serif", Font.PLAIN, 8)); renderer.setItemLabelsVisible(true); chartPanel.setPreferredSize(new java.awt.Dimension(500, 270)); setContentPane(chartPanel); this.pack(); RefineryUtilities.centerFrameOnScreen(this); this.setVisible(true); }
public void visualizarSeriesTiemposRescateVictPorRobots(CategoryDataset dataset) { JFreeChart chart = ChartFactory.createBarChart( "Tiempos de Rescate de Victimas por cada robot ", // chart title "Robots en el entorno", // domain axis label "Tiempo milisegundos", // range axis label dataset, // data PlotOrientation.VERTICAL, // orientation true, // include legend true, // tooltips? false // URLs? ); ChartPanel chartPanel = new ChartPanel(chart); chart.setBackgroundPaint(Color.white); CategoryPlot plot = chart.getCategoryPlot(); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setUpperMargin(0.15); CategoryItemRenderer renderer = plot.getRenderer(); renderer.setItemLabelGenerator(new LabelGenerator(50.0)); renderer.setItemLabelFont(new Font("Serif", Font.PLAIN, 8)); renderer.setItemLabelsVisible(true); chartPanel.setPreferredSize(new java.awt.Dimension(500, 270)); this.visualizar(chartPanel); }
public void visualizarSeriesEnergRescateVictPorRobots(CategoryDataset dataset) { JFreeChart chart = ChartFactory.createBarChart( "Tiempos de Rescate de Victimas por cada robot ", // chart title "Robots en el entorno", // domain axis label "Unidades de energ�a", // range axis label dataset, // data PlotOrientation.VERTICAL, // orientation true, // include legend true, // tooltips? false // URLs? ); ChartPanel chartPanel = new ChartPanel(chart); chart.setBackgroundPaint(Color.white); CategoryPlot plot = chart.getCategoryPlot(); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setUpperMargin(0.15); CategoryItemRenderer renderer = plot.getRenderer(); renderer.setItemLabelGenerator(new LabelGenerator(50.0)); renderer.setItemLabelFont(new Font("Serif", Font.PLAIN, 8)); renderer.setItemLabelsVisible(true); chartPanel.setPreferredSize(new java.awt.Dimension(500, 270)); this.visualizar(chartPanel); }
/** * Sets a renderer. A {@link PlotChangeEvent} is sent to all registered listeners. * * @param index the index. * @param renderer the renderer (<code>null</code> permitted). * @param notify notify listeners? */ public void setRenderer(int index, CategoryItemRenderer renderer, boolean notify) { // stop listening to the existing renderer... CategoryItemRenderer existing = (CategoryItemRenderer) this.renderers.get(index); if (existing != null) { existing.removeChangeListener(this); } // register the new renderer... this.renderers.set(index, renderer); if (renderer != null) { renderer.setPlot(this); renderer.addChangeListener(this); } configureDomainAxes(); configureRangeAxes(); if (notify) { notifyListeners(new PlotChangeEvent(this)); } }
/** * Draws the gridlines for the plot. * * @param g2 the graphics device. * @param dataArea the area inside the axes. * @param ticks the ticks. */ protected void drawRangeGridlines(Graphics2D g2, Rectangle2D dataArea, List ticks) { // draw the range grid lines, if any... if (isRangeGridlinesVisible()) { Stroke gridStroke = getRangeGridlineStroke(); Paint gridPaint = getRangeGridlinePaint(); if ((gridStroke != null) && (gridPaint != null)) { ValueAxis axis = getRangeAxis(); if (axis != null) { Iterator iterator = ticks.iterator(); while (iterator.hasNext()) { ValueTick tick = (ValueTick) iterator.next(); CategoryItemRenderer renderer1 = getRenderer(); if (renderer1 != null) { renderer1.drawRangeGridline( g2, this, getRangeAxis(), dataArea, tick.getValue() ); } } } } } }
/** * Draws the range markers (if any) for an axis and layer. This method is * typically called from within the draw(...) method. * * @param g2 the graphics device. * @param dataArea the data area. * @param index the renderer index. * @param layer the layer (foreground or background). */ protected void drawRangeMarkers(Graphics2D g2, Rectangle2D dataArea, int index, Layer layer) { CategoryItemRenderer r = getRenderer(index); if (r == null) { return; } Collection markers = getRangeMarkers(index, layer); ValueAxis axis = getRangeAxisForDataset(index); if (markers != null && axis != null) { Iterator iterator = markers.iterator(); while (iterator.hasNext()) { Marker marker = (Marker) iterator.next(); r.drawRangeMarker(g2, this, axis, marker, dataArea); } } }
/** * Returns the range of data values that will be plotted against the range axis. * If the dataset is <code>null</code>, this method returns <code>null</code>. * * @param axis the axis. * * @return The data range. */ public Range getDataRange(ValueAxis axis) { Range result = null; List mappedDatasets = new ArrayList(); int rangeIndex = this.rangeAxes.indexOf(axis); if (rangeIndex >= 0) { mappedDatasets.addAll(getDatasetsMappedToRangeAxis(rangeIndex)); } else if (axis == getRangeAxis()) { mappedDatasets.addAll(getDatasetsMappedToRangeAxis(0)); } // iterate through the datasets that map to the axis and get the union of the ranges. Iterator iterator = mappedDatasets.iterator(); while (iterator.hasNext()) { CategoryDataset d = (CategoryDataset) iterator.next(); CategoryItemRenderer r = getRendererForDataset(d); if (r != null) { result = Range.combine(result, r.getRangeExtent(d)); } } return result; }
/** * Sets a renderer. A {@link PlotChangeEvent} is sent to all registered * listeners. * * @param index the index. * @param renderer the renderer (<code>null</code> permitted). * @param notify notify listeners? * * @see #getRenderer(int) */ public void setRenderer(int index, CategoryItemRenderer renderer, boolean notify) { // stop listening to the existing renderer... CategoryItemRenderer existing = (CategoryItemRenderer) this.renderers.get(index); if (existing != null) { existing.removeChangeListener(this); } // register the new renderer... this.renderers.set(index, renderer); if (renderer != null) { renderer.setPlot(this); renderer.addChangeListener(this); } configureDomainAxes(); configureRangeAxes(); if (notify) { notifyListeners(new PlotChangeEvent(this)); } }
/** * Draws the gridlines for the plot. * * @param g2 the graphics device. * @param dataArea the area inside the axes. * @param ticks the ticks. * * @see #drawDomainGridlines(Graphics2D, Rectangle2D) */ protected void drawRangeGridlines(Graphics2D g2, Rectangle2D dataArea, List ticks) { // draw the range grid lines, if any... if (isRangeGridlinesVisible()) { Stroke gridStroke = getRangeGridlineStroke(); Paint gridPaint = getRangeGridlinePaint(); if ((gridStroke != null) && (gridPaint != null)) { ValueAxis axis = getRangeAxis(); if (axis != null) { Iterator iterator = ticks.iterator(); while (iterator.hasNext()) { ValueTick tick = (ValueTick) iterator.next(); CategoryItemRenderer renderer1 = getRenderer(); if (renderer1 != null) { renderer1.drawRangeGridline(g2, this, getRangeAxis(), dataArea, tick.getValue()); } } } } } }
/** * Draws the domain markers (if any) for an axis and layer. This method is * typically called from within the draw() method. * * @param g2 the graphics device. * @param dataArea the data area. * @param index the renderer index. * @param layer the layer (foreground or background). * * @see #drawRangeMarkers(Graphics2D, Rectangle2D, int, Layer) */ protected void drawDomainMarkers(Graphics2D g2, Rectangle2D dataArea, int index, Layer layer) { CategoryItemRenderer r = getRenderer(index); if (r == null) { return; } Collection markers = getDomainMarkers(index, layer); CategoryAxis axis = getDomainAxisForDataset(index); if (markers != null && axis != null) { Iterator iterator = markers.iterator(); while (iterator.hasNext()) { CategoryMarker marker = (CategoryMarker) iterator.next(); r.drawDomainMarker(g2, this, axis, marker, dataArea); } } }
/** * Draws the range markers (if any) for an axis and layer. This method is * typically called from within the draw() method. * * @param g2 the graphics device. * @param dataArea the data area. * @param index the renderer index. * @param layer the layer (foreground or background). * * @see #drawDomainMarkers(Graphics2D, Rectangle2D, int, Layer) */ protected void drawRangeMarkers(Graphics2D g2, Rectangle2D dataArea, int index, Layer layer) { CategoryItemRenderer r = getRenderer(index); if (r == null) { return; } Collection markers = getRangeMarkers(index, layer); ValueAxis axis = getRangeAxisForDataset(index); if (markers != null && axis != null) { Iterator iterator = markers.iterator(); while (iterator.hasNext()) { Marker marker = (Marker) iterator.next(); r.drawRangeMarker(g2, this, axis, marker, dataArea); } } }
/** * Datasets are now stored in a Map, and it should be possible to assign * them an arbitrary key (index). */ @Test public void testDatasetIndices() { 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); assertEquals(dataset, plot.getDataset(0)); DefaultCategoryDataset dataset2 = new DefaultCategoryDataset(); dataset2.setValue(1, "R1", "C1"); // we should be able to give a dataset an arbitrary index plot.setDataset(99, dataset2); assertEquals(2, plot.getDatasetCount()); assertEquals(dataset2, plot.getDataset(99)); assertEquals(0, plot.indexOf(dataset)); assertEquals(99, plot.indexOf(dataset2)); }
@Test public void testAxisIndices() { 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); assertEquals(xAxis, plot.getDomainAxis(0)); assertEquals(yAxis, plot.getRangeAxis(0)); CategoryAxis xAxis2 = new CategoryAxis("X2"); plot.setDomainAxis(99, xAxis2); assertEquals(xAxis2, plot.getDomainAxis(99)); NumberAxis yAxis2 = new NumberAxis("Y2"); plot.setRangeAxis(99, yAxis2); assertEquals(yAxis2, plot.getRangeAxis(99)); }
@Test public void testAxisLocationIndices() { 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"); NumberAxis yAxis2 = new NumberAxis("Y2"); plot.setDomainAxis(99, xAxis2); plot.setRangeAxis(99, yAxis2); plot.setDomainAxisLocation(99, AxisLocation.BOTTOM_OR_RIGHT); assertEquals(AxisLocation.BOTTOM_OR_RIGHT, plot.getDomainAxisLocation(99)); plot.setRangeAxisLocation(99, AxisLocation.BOTTOM_OR_LEFT); assertEquals(AxisLocation.BOTTOM_OR_LEFT, plot.getRangeAxisLocation(99)); }
/** * Returns the range of data values that will be plotted against the range * axis. If the dataset is <code>null</code>, this method returns * <code>null</code>. * * @param axis the axis. * * @return The data range. */ @Override public Range getDataRange(ValueAxis axis) { Range result = null; List<CategoryDataset> mappedDatasets = new ArrayList<CategoryDataset>(); int rangeIndex = findRangeAxisIndex(axis); if (rangeIndex >= 0) { mappedDatasets.addAll(datasetsMappedToRangeAxis(rangeIndex)); } else if (axis == getRangeAxis()) { mappedDatasets.addAll(datasetsMappedToRangeAxis(0)); } // iterate through the datasets that map to the axis and get the union // of the ranges. for (CategoryDataset d : mappedDatasets) { CategoryItemRenderer r = getRendererForDataset(d); if (r != null) { result = Range.combine(result, r.findRangeBounds(d)); } } return result; }
@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)); }
@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)); }
@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)); }
@Test public void testRangeMarkerIndices() { 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 axis DefaultCategoryDataset dataset2 = new DefaultCategoryDataset(); dataset2.setValue(1, "R1", "C1"); plot.setDataset(99, dataset); NumberAxis yAxis2 = new NumberAxis("Y2"); plot.setRangeAxis(1, yAxis2); LineAndShapeRenderer renderer2 = new LineAndShapeRenderer(); plot.setRenderer(99, renderer2); plot.mapDatasetToRangeAxis(99, 1); ValueMarker yMarker1 = new ValueMarker(123); plot.addRangeMarker(99, yMarker1, Layer.FOREGROUND); assertTrue(plot.getRangeMarkers(99, Layer.FOREGROUND).contains( yMarker1)); }
@Test public void testRendererIndices() { 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); assertEquals(renderer, plot.getRenderer(0)); // we should be able to give a renderer an arbitrary index CategoryItemRenderer renderer2 = new LineAndShapeRenderer(); plot.setRenderer(20, renderer2); assertEquals(2, plot.getRendererCount()); assertEquals(renderer2, plot.getRenderer(20)); assertEquals(20, plot.getIndexOf(renderer2)); }
/** * Draws the domain gridlines for the plot, if they are visible. * * @param g2 the graphics device. * @param dataArea the area inside the axes. * * @see #drawRangeGridlines(Graphics2D, Rectangle2D, List) */ protected void drawDomainGridlines(Graphics2D g2, Rectangle2D dataArea) { if (!isDomainGridlinesVisible()) { return; } CategoryAnchor anchor = getDomainGridlinePosition(); RectangleEdge domainAxisEdge = getDomainAxisEdge(); CategoryDataset dataset = getDataset(); if (dataset == null) { return; } CategoryAxis axis = getDomainAxis(); if (axis != null) { int columnCount = dataset.getColumnCount(); for (int c = 0; c < columnCount; c++) { double xx = axis.getCategoryJava2DCoordinate(anchor, c, columnCount, dataArea, domainAxisEdge); CategoryItemRenderer renderer1 = getRenderer(); if (renderer1 != null) { renderer1.drawDomainGridline(g2, this, dataArea, xx); } } } }
/** * Sets the renderer to use for the dataset with the specified index and, * if requested, sends a change event to all registered listeners. Note * that each dataset should have its own renderer, you should not use one * renderer for multiple datasets. * * @param index the index. * @param renderer the renderer (<code>null</code> permitted). * @param notify notify listeners? * * @see #getRenderer(int) */ public void setRenderer(int index, CategoryItemRenderer renderer, boolean notify) { CategoryItemRenderer existing = this.renderers.get(index); if (existing != null) { existing.removeChangeListener(this); } this.renderers.put(index, renderer); if (renderer != null) { renderer.setPlot(this); renderer.addChangeListener(this); } configureDomainAxes(); configureRangeAxes(); if (notify) { fireChangeEvent(); } }
/** * Returns the legend items for the plot. By default, this method creates * a legend item for each series in each of the datasets. You can change * this behaviour by overriding this method. * * @return The legend items. */ @Override public LegendItemCollection getLegendItems() { if (this.fixedLegendItems != null) { return this.fixedLegendItems; } LegendItemCollection result = new LegendItemCollection(); // get the legend items for the datasets... for (CategoryDataset dataset: this.datasets.values()) { if (dataset != null) { int datasetIndex = indexOf(dataset); CategoryItemRenderer renderer = getRenderer(datasetIndex); if (renderer != null) { result.addAll(renderer.getLegendItems()); } } } return result; }
@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)); }
/** * Sets the renderer to use for the dataset with the specified index and, * if requested, sends a change event to all registered listeners. Note * that each dataset should have its own renderer, you should not use one * renderer for multiple datasets. * * @param index the index. * @param renderer the renderer ({@code null} permitted). * @param notify notify listeners? * * @see #getRenderer(int) */ public void setRenderer(int index, CategoryItemRenderer renderer, boolean notify) { CategoryItemRenderer existing = this.renderers.get(index); if (existing != null) { existing.removeChangeListener(this); } this.renderers.put(index, renderer); if (renderer != null) { renderer.setPlot(this); renderer.addChangeListener(this); } configureDomainAxes(); configureRangeAxes(); if (notify) { fireChangeEvent(); } }