List of usage examples for org.jfree.chart.plot CategoryPlot getRangeAxis
public ValueAxis getRangeAxis(int index)
From source file:org.pentaho.plugin.jfreereport.reportcharts.BarLineChartExpression.java
protected void configureChart(final JFreeChart chart) { super.configureChart(chart); final CategoryPlot plot = chart.getCategoryPlot(); if (isSharedRangeAxis() == false) { final ValueAxis linesAxis = plot.getRangeAxis(1); if (linesAxis instanceof NumberAxis) { final NumberAxis numberAxis = (NumberAxis) linesAxis; numberAxis.setAutoRangeIncludesZero(isLineAxisIncludesZero()); numberAxis.setAutoRangeStickyZero(isLineAxisStickyZero()); if (getLinePeriodCount() > 0) { if (getLineTicksLabelFormat() != null) { final FastDecimalFormat formatter = new FastDecimalFormat(getLineTicksLabelFormat(), getResourceBundleFactory().getLocale()); numberAxis.setTickUnit(new FastNumberTickUnit(getLinePeriodCount(), formatter)); } else { numberAxis.setTickUnit(new FastNumberTickUnit(getLinePeriodCount())); }/*www. j a va2 s .c om*/ } else { if (getLineTicksLabelFormat() != null) { final DecimalFormat formatter = new DecimalFormat(getLineTicksLabelFormat(), new DecimalFormatSymbols(getResourceBundleFactory().getLocale())); numberAxis.setNumberFormatOverride(formatter); } } } else if (linesAxis instanceof DateAxis) { final DateAxis numberAxis = (DateAxis) linesAxis; if (getLinePeriodCount() > 0 && getLineTimePeriod() != null) { if (getLineTicksLabelFormat() != null) { final SimpleDateFormat formatter = new SimpleDateFormat(getLineTicksLabelFormat(), new DateFormatSymbols(getResourceBundleFactory().getLocale())); numberAxis.setTickUnit(new DateTickUnit(getDateUnitAsInt(getLineTimePeriod()), (int) getLinePeriodCount(), formatter)); } else { numberAxis.setTickUnit(new DateTickUnit(getDateUnitAsInt(getLineTimePeriod()), (int) getLinePeriodCount())); } } else if (getRangeTickFormatString() != null) { final SimpleDateFormat formatter = new SimpleDateFormat(getRangeTickFormatString(), new DateFormatSymbols(getResourceBundleFactory().getLocale())); numberAxis.setDateFormatOverride(formatter); } } if (linesAxis != null) { final Font labelFont = Font.decode(getLabelFont()); linesAxis.setLabelFont(labelFont); linesAxis.setTickLabelFont(labelFont); if (getLineTitleFont() != null) { linesAxis.setLabelFont(getLineTitleFont()); } if (getLineTickFont() != null) { linesAxis.setTickLabelFont(getLineTickFont()); } final int level = getRuntime().getProcessingContext().getCompatibilityLevel(); if (ClassicEngineBoot.isEnforceCompatibilityFor(level, 3, 8)) { if (getRangeMinimum() != 0) { linesAxis.setLowerBound(getLineRangeMinimum()); } if (getRangeMaximum() != 1) { linesAxis.setUpperBound(getLineRangeMaximum()); } if (getLineRangeMinimum() == 0 && getLineRangeMaximum() == 1) { linesAxis.setLowerBound(0); linesAxis.setUpperBound(1); linesAxis.setAutoRange(true); } } else { linesAxis.setLowerBound(getLineRangeMinimum()); linesAxis.setUpperBound(getLineRangeMaximum()); linesAxis.setAutoRange(isLineAxisAutoRange()); } } } final LineAndShapeRenderer linesRenderer = (LineAndShapeRenderer) plot.getRenderer(1); if (linesRenderer != null) { //set stroke with line width linesRenderer.setStroke(translateLineStyle(lineWidth, lineStyle)); //hide shapes on line linesRenderer.setShapesVisible(isMarkersVisible()); linesRenderer.setBaseShapesFilled(isMarkersVisible()); //set colors for each line for (int i = 0; i < lineSeriesColor.size(); i++) { final String s = (String) lineSeriesColor.get(i); linesRenderer.setSeriesPaint(i, parseColorFromString(s)); } } }
From source file:org.n52.oxf.render.sos.AnimatedMapChartRenderer4OnePhenomenon.java
/** * //from www .j a va2 s . co m * @param observationCollection * the observations belonging to the timeStamp (frame) which shall be rendered * @param screenW * @param screenH * @param bbox * @return */ protected Image renderFrame(ITimePosition timePos, int screenW, int screenH, IBoundingBox bbox, Set<OXFFeature> featuresWithCharts, ObservationSeriesCollection tupleFinder) { ContextBoundingBox contextBBox = new ContextBoundingBox(bbox); BufferedImage image = new BufferedImage(screenW, screenH, BufferedImage.TYPE_INT_RGB); Graphics2D g = image.createGraphics(); // draw white background: g.setColor(Color.WHITE); g.fillRect(0, 0, screenW, screenH); for (OXFFeature chartFeature : featuresWithCharts) { // // create Plot for each "chart feature" and add it to the plotArray: // CategoryPlot plot = renderFoiBarChart(chartFeature.getID(), timePos.toString(), tupleFinder.getTuple(chartFeature, timePos)); // // draw the plots into the image at the georeferenced position of the corresponding chartFeature: // Point pRealWorld = (Point) chartFeature.getGeometry(); java.awt.Point pScreen = ContextBoundingBox.realworld2Screen(contextBBox.getActualBBox(), screenW, screenH, new Point2D.Double(pRealWorld.getCoordinate().x, pRealWorld.getCoordinate().y)); plot.getRangeAxis(0).setRange((Double) tupleFinder.getMinimum(0), (Double) tupleFinder.getMaximum(0)); plot.draw(g, new Rectangle2D.Float(pScreen.x + X_SHIFT + 10, pScreen.y + Y_SHIFT, CHART_WIDTH, CHART_HEIGHT), null, null, null); } return image; }
From source file:ca.sqlpower.wabit.swingui.chart.ChartSwingUtil.java
/** * Sets the colours and gradients to be used when painting the given JFreeChart. * //from w w w. j av a2s. com * @param chart * The JFreeChart to make nice. */ public static void makeChartNice(JFreeChart chart) { Plot plot = chart.getPlot(); chart.setBackgroundPaint(null); chart.setBorderStroke(new BasicStroke(1f)); chart.setBorderPaint(new Color(0xDDDDDD)); chart.setBorderVisible(true); // TODO Should we add an option for subtitles, this is where it would go. // TextTitle subTitle = new TextTitle("What's up doc?", // new Font("SansSerif", Font.BOLD, 8)); // chart.addSubtitle(subTitle); // overall plot plot.setOutlinePaint(null); plot.setInsets(new RectangleInsets(0, 5, 0, 5)); // also the overall chart panel plot.setBackgroundPaint(null); plot.setDrawingSupplier(new WabitDrawingSupplier()); // legend LegendTitle legend = chart.getLegend(); if (legend != null) { legend.setBorder(0, 0, 0, 0); legend.setBackgroundPaint(null); legend.setPadding(2, 2, 2, 2); } if (plot instanceof CategoryPlot) { CategoryPlot cplot = (CategoryPlot) plot; CategoryItemRenderer renderer = cplot.getRenderer(); if (renderer instanceof BarRenderer) { BarRenderer brenderer = (BarRenderer) renderer; brenderer.setBarPainter(new StandardBarPainter()); brenderer.setDrawBarOutline(false); brenderer.setShadowVisible(false); brenderer.setGradientPaintTransformer( new StandardGradientPaintTransformer(GradientPaintTransformType.HORIZONTAL)); } else if (renderer instanceof LineAndShapeRenderer) { // it's all taken care of by WabitDrawingSupplier } else { logger.warn("I don't know how to make " + renderer + " pretty. Leaving ugly."); } cplot.setRangeGridlinePaint(Color.BLACK); cplot.setRangeGridlineStroke(GRIDLINE_STROKE); // axes for (int i = 0; i < cplot.getDomainAxisCount(); i++) { CategoryAxis axis = cplot.getDomainAxis(i); axis.setAxisLineVisible(false); } for (int i = 0; i < cplot.getRangeAxisCount(); i++) { ValueAxis axis = cplot.getRangeAxis(i); axis.setAxisLineVisible(false); } } if (plot instanceof MultiplePiePlot) { MultiplePiePlot mpplot = (MultiplePiePlot) plot; JFreeChart pchart = mpplot.getPieChart(); PiePlot3DGradient pplot = (PiePlot3DGradient) pchart.getPlot(); pplot.setBackgroundPaint(null); pplot.setOutlinePaint(null); pplot.setFaceGradientPaintTransformer( new StandardGradientPaintTransformer(GradientPaintTransformType.HORIZONTAL)); pplot.setSideGradientPaintTransformer( new StandardGradientPaintTransformer(GradientPaintTransformType.HORIZONTAL)); CategoryDataset data = mpplot.getDataset(); Color[][] colours = WabitDrawingSupplier.SERIES_COLOURS; //Set all colours for (int i = 0; i < colours.length; i++) { if (data.getColumnCount() >= i + 1) { pplot.setSectionOutlinePaint(data.getColumnKey(i), null); GradientPaint gradient = new GradientPaint(0, 0f, colours[i][0], 100, 0f, colours[i][1]); pplot.setSectionPaint(data.getColumnKey(i), gradient); gradient = new GradientPaint(0, 0f, colours[i][1], 100, 0f, colours[i][0]); pplot.setSidePaint(data.getColumnKey(i), gradient); } } } // Tweak the title font size chart.getTitle().setFont(chart.getTitle().getFont().deriveFont(14f)); chart.getTitle().setPadding(5, 0, 5, 0); chart.setAntiAlias(true); // shrink padding chart.setPadding(new RectangleInsets(0, 0, 0, 0)); }
From source file:org.matsim.counts.algorithms.graphs.BiasNormalizedErrorGraph.java
@Override public JFreeChart createChart(final int nbr) { DefaultCategoryDataset dataset0 = new DefaultCategoryDataset(); DefaultCategoryDataset dataset1 = new DefaultCategoryDataset(); this.errorStats = new ComparisonErrorStatsCalculator(this.ccl_); double[] meanNormRelError = this.errorStats.getMeanNormRelError(); // double[] meanAbsError = this.errorStats.getMeanAbsError(); double[] meanBias = this.errorStats.getMeanBias(); for (int h = 0; h < 24; h++) { meanNormRelError[h] *= 100;/* w w w . j a v a 2 s . co m*/ dataset0.addValue(meanNormRelError[h], "Mean norm rel error", Integer.toString(h + 1)); // dataset1.addValue(meanAbsError[h], "Mean abs error", Integer.toString(h + 1)); dataset1.addValue(meanBias[h], "Mean bias", Integer.toString(h + 1)); } this.chart_ = ChartFactory.createLineChart("", "Hour", "Mean norm rel error [%]", dataset0, PlotOrientation.VERTICAL, true, // legend? true, // tooltips? false // URLs? ); CategoryPlot plot = this.chart_.getCategoryPlot(); plot.setDomainAxisLocation(AxisLocation.BOTTOM_OR_RIGHT); plot.setDataset(1, dataset1); plot.mapDatasetToRangeAxis(1, 1); final LineAndShapeRenderer renderer = new LineAndShapeRenderer(); renderer.setSeriesToolTipGenerator(0, new StandardCategoryToolTipGenerator()); plot.setRenderer(0, renderer); final CategoryAxis axis1 = new CategoryAxis("Hour"); axis1.setTickLabelFont(new Font("SansSerif", Font.PLAIN, 7)); plot.setDomainAxis(axis1); // final ValueAxis axis2 = new NumberAxis("Mean abs {bias, error} [veh/h]"); final ValueAxis axis2 = new NumberAxis("Mean bias [veh/h]"); plot.setRangeAxis(1, axis2); final ValueAxis axis3 = plot.getRangeAxis(0); axis3.setRange(0.0, 100.0); final LineAndShapeRenderer renderer2 = new LineAndShapeRenderer(); renderer2.setSeriesToolTipGenerator(0, new StandardCategoryToolTipGenerator()); renderer2.setSeriesToolTipGenerator(1, new StandardCategoryToolTipGenerator()); // renderer2.setSeriesPaint(0, Color.black); plot.setRenderer(1, renderer2); plot.setDatasetRenderingOrder(DatasetRenderingOrder.REVERSE); return this.chart_; }
From source file:org.matsim.counts.algorithms.graphs.BiasErrorGraph.java
@Override public JFreeChart createChart(final int nbr) { DefaultCategoryDataset dataset0 = new DefaultCategoryDataset(); DefaultCategoryDataset dataset1 = new DefaultCategoryDataset(); this.errorStats = new ComparisonErrorStatsCalculator(this.ccl_); double[] meanRelError = errorStats.getMeanRelError(); // double[] meanAbsError = errorStats.getMeanAbsError(); double[] meanAbsBias = errorStats.getMeanAbsBias(); for (int h = 0; h < 24; h++) { dataset0.addValue(meanRelError[h], "Mean rel error", Integer.toString(h + 1)); // dataset1.addValue(meanAbsError[h], "Mean abs error", Integer.toString(h + 1)); dataset1.addValue(meanAbsBias[h], "Mean abs bias", Integer.toString(h + 1)); }/*from w w w .j a v a2 s . c o m*/ this.chart_ = ChartFactory.createLineChart("", "Hour", "Mean rel error [%]", dataset0, PlotOrientation.VERTICAL, true, // legend? true, // tooltips? false // URLs? ); CategoryPlot plot = this.chart_.getCategoryPlot(); plot.setDomainAxisLocation(AxisLocation.BOTTOM_OR_RIGHT); plot.setDataset(1, dataset1); plot.mapDatasetToRangeAxis(1, 1); final LineAndShapeRenderer renderer = new LineAndShapeRenderer(); renderer.setSeriesToolTipGenerator(0, new StandardCategoryToolTipGenerator()); plot.setRenderer(0, renderer); final CategoryAxis axis1 = new CategoryAxis("Hour"); axis1.setTickLabelFont(new Font("SansSerif", Font.PLAIN, 7)); plot.setDomainAxis(axis1); // final ValueAxis axis2 = new NumberAxis("Mean abs {bias, error} [veh/h]"); final ValueAxis axis2 = new NumberAxis("Mean abs bias [veh/h]"); plot.setRangeAxis(1, axis2); final ValueAxis axis3 = plot.getRangeAxis(0); axis3.setRange(0.0, 100.0); final LineAndShapeRenderer renderer2 = new LineAndShapeRenderer(); renderer2.setSeriesToolTipGenerator(0, new StandardCategoryToolTipGenerator()); renderer2.setSeriesToolTipGenerator(1, new StandardCategoryToolTipGenerator()); // renderer2.setSeriesPaint(0, Color.black); plot.setRenderer(1, renderer2); plot.setDatasetRenderingOrder(DatasetRenderingOrder.REVERSE); return this.chart_; }
From source file:org.matsim.pt.counts.PtBiasErrorGraph.java
@Override public JFreeChart createChart(final int nbr) { DefaultCategoryDataset dataset0 = new DefaultCategoryDataset(); DefaultCategoryDataset dataset1 = new DefaultCategoryDataset(); this.errorStats = new ComparisonErrorStatsCalculator(this.ccl_); double[] meanRelError = errorStats.getMeanRelError(); // double[] meanAbsError = errorStats.getMeanAbsError(); double[] meanAbsBias = errorStats.getMeanAbsBias(); for (int h = 0; h < 24; h++) { dataset0.addValue(meanRelError[h], "Mean rel error", Integer.toString(h + 1)); // dataset1.addValue(meanAbsError[h], "Mean abs error", // Integer.toString(h + 1)); dataset1.addValue(meanAbsBias[h], "Mean abs bias", Integer.toString(h + 1)); }// w ww . j a v a 2 s. co m this.chart_ = ChartFactory.createLineChart(this.chartTitle, "Hour", "Mean rel error [%]", dataset0, PlotOrientation.VERTICAL, true, // legend? true, // tooltips? false // URLs? ); CategoryPlot plot = this.chart_.getCategoryPlot(); plot.setDomainAxisLocation(AxisLocation.BOTTOM_OR_RIGHT); plot.setDataset(1, dataset1); plot.mapDatasetToRangeAxis(1, 1); final LineAndShapeRenderer renderer = new LineAndShapeRenderer(); renderer.setSeriesToolTipGenerator(0, new StandardCategoryToolTipGenerator()); plot.setRenderer(0, renderer); final CategoryAxis axis1 = new CategoryAxis("Hour"); axis1.setTickLabelFont(new Font("SansSerif", Font.PLAIN, 7)); plot.setDomainAxis(axis1); // final ValueAxis axis2 = new // NumberAxis("Mean abs {bias, error} [veh/h]"); final ValueAxis axis2 = new NumberAxis("Mean abs bias [veh/h]"); plot.setRangeAxis(1, axis2); final ValueAxis axis3 = plot.getRangeAxis(0); axis3.setRange(0.0, 100.0); final LineAndShapeRenderer renderer2 = new LineAndShapeRenderer(); renderer2.setSeriesToolTipGenerator(0, new StandardCategoryToolTipGenerator()); renderer2.setSeriesToolTipGenerator(1, new StandardCategoryToolTipGenerator()); // renderer2.setSeriesPaint(0, Color.black); plot.setRenderer(1, renderer2); plot.setDatasetRenderingOrder(DatasetRenderingOrder.REVERSE); return this.chart_; }
From source file:org.matsim.pt.counts.obsolete.PtBiasErrorGraph.java
@Override @Deprecated // use standard counts package public JFreeChart createChart(final int nbr) { DefaultCategoryDataset dataset0 = new DefaultCategoryDataset(); DefaultCategoryDataset dataset1 = new DefaultCategoryDataset(); this.errorStats = new ComparisonErrorStatsCalculator(this.ccl_); double[] meanRelError = errorStats.getMeanRelError(); // double[] meanAbsError = errorStats.getMeanAbsError(); double[] meanAbsBias = errorStats.getMeanAbsBias(); for (int h = 0; h < 24; h++) { dataset0.addValue(meanRelError[h], "Mean rel error", Integer.toString(h + 1)); // dataset1.addValue(meanAbsError[h], "Mean abs error", // Integer.toString(h + 1)); dataset1.addValue(meanAbsBias[h], "Mean abs bias", Integer.toString(h + 1)); }/* w ww.j a v a 2s . c o m*/ this.chart_ = ChartFactory.createLineChart(this.chartTitle, "Hour", "Mean rel error [%]", dataset0, PlotOrientation.VERTICAL, true, // legend? true, // tooltips? false // URLs? ); CategoryPlot plot = this.chart_.getCategoryPlot(); plot.setDomainAxisLocation(AxisLocation.BOTTOM_OR_RIGHT); plot.setDataset(1, dataset1); plot.mapDatasetToRangeAxis(1, 1); final LineAndShapeRenderer renderer = new LineAndShapeRenderer(); renderer.setSeriesToolTipGenerator(0, new StandardCategoryToolTipGenerator()); plot.setRenderer(0, renderer); final CategoryAxis axis1 = new CategoryAxis("Hour"); axis1.setTickLabelFont(new Font("SansSerif", Font.PLAIN, 7)); plot.setDomainAxis(axis1); // final ValueAxis axis2 = new // NumberAxis("Mean abs {bias, error} [veh/h]"); final ValueAxis axis2 = new NumberAxis("Mean abs bias [veh/h]"); plot.setRangeAxis(1, axis2); final ValueAxis axis3 = plot.getRangeAxis(0); axis3.setRange(0.0, 100.0); final LineAndShapeRenderer renderer2 = new LineAndShapeRenderer(); renderer2.setSeriesToolTipGenerator(0, new StandardCategoryToolTipGenerator()); renderer2.setSeriesToolTipGenerator(1, new StandardCategoryToolTipGenerator()); // renderer2.setSeriesPaint(0, Color.black); plot.setRenderer(1, renderer2); plot.setDatasetRenderingOrder(DatasetRenderingOrder.REVERSE); return this.chart_; }
From source file:org.pentaho.platform.uifoundation.chart.JFreeChartEngine.java
private static JFreeChart createBarLineChart(final BarLineChartDefinition chartDefinition) { // TODO Make the following accessible from the chartDefinition String categoryAxisLabel = null; String valueAxisLabel = null; String secondValueAxisLabel = null; boolean tooltips = true; boolean urls = true; // ----------------------------------------------------------- String title = chartDefinition.getTitle(); boolean legend = chartDefinition.isLegendIncluded(); PlotOrientation orientation = chartDefinition.getOrientation(); // split BarLineChartDefinition in two Definitions CategoryDatasetChartDefinition barsDataset = new CategoryDatasetChartDefinition( chartDefinition.getSession(), chartDefinition.getChartAttributes()); CategoryDatasetChartDefinition linesDataset = new CategoryDatasetChartDefinition( chartDefinition.getSession(), chartDefinition.getChartAttributes()); /*//from w ww .j a v a2 s.c om * try{ barsDataset = (CategoryDatasetChartDefinition)chartDefinition.clone(); linesDataset = * (CategoryDatasetChartDefinition)chartDefinition.clone(); }catch(Exception e){} */ // get column and row count of the data set int iColumnCount = chartDefinition.getColumnCount(); int iRowCount = chartDefinition.getRowCount(); if (iRowCount <= 0) { chartDefinition.setNoDataMessage(Messages.getInstance().getString("CHART.USER_NO_DATA_AVAILABLE")); //$NON-NLS-1$ } /* * Copy data to the two new data sets */ // Loop through columns for (int r = 0; r < iRowCount; r++) { // check if measure should be include in bar or line dataset String strMeasureName = (String) chartDefinition.getRowKey(r); boolean bIsBarColumn = JFreeChartEngine.isBarColumn(chartDefinition.getBarColumns(), strMeasureName); boolean bIsLineColumn = JFreeChartEngine.isLineColumn(chartDefinition.getLineColumns(), strMeasureName); // getting all values for (int c = 0; c < iColumnCount; c++) { Comparable compColumnName = chartDefinition.getColumnKey(c); Number nValue = chartDefinition.getValue(strMeasureName, compColumnName); if (bIsBarColumn) { barsDataset.addValue(nValue, strMeasureName, compColumnName); } if (bIsLineColumn) { linesDataset.addValue(nValue, strMeasureName, compColumnName); } } } if ((iRowCount > 0) && (barsDataset.getRowCount() <= 0) && (linesDataset.getRowCount() <= 0)) { chartDefinition.setNoDataMessage(Messages.getInstance().getString("CHART.USER_INCORRECT_DATA_FORMAT")); //$NON-NLS-1$ } // Create Axis Objects CategoryAxis catAxis = new CategoryAxis(categoryAxisLabel); NumberAxis barsAxis = new NumberAxis(valueAxisLabel); NumberAxis linesAxis = new NumberAxis(secondValueAxisLabel); // set title and font for lines Axis linesDataset.setRangeTitle(chartDefinition.getLinesRangeTitle()); linesDataset.setRangeTitleFont(chartDefinition.getLinesRangeTitleFont()); if (chartDefinition.getLinesRangeTickFormat() != null) { linesAxis.setNumberFormatOverride(chartDefinition.getLinesRangeTickFormat()); } // create renderer BarRenderer barRenderer = null; LineAndShapeRenderer lineRenderer = null; // Determine the type of renderer to use if (chartDefinition.isStacked() || chartDefinition.isThreeD()) { if (chartDefinition.isStacked() && chartDefinition.isThreeD()) { barRenderer = new StackedBarRenderer3D(); lineRenderer = new LineRenderer3D(); } else if (chartDefinition.isStacked()) { barRenderer = new StackedBarRenderer(); lineRenderer = new LineAndShapeRenderer(); } else { barRenderer = new BarRenderer3D(); lineRenderer = new LineRenderer3D(); } } else { barRenderer = new BarRenderer(); lineRenderer = new LineAndShapeRenderer(); } if (orientation == PlotOrientation.HORIZONTAL) { ItemLabelPosition position1 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE3, TextAnchor.CENTER_LEFT); barRenderer.setPositiveItemLabelPosition(position1); lineRenderer.setPositiveItemLabelPosition(position1); ItemLabelPosition position2 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE9, TextAnchor.CENTER_RIGHT); barRenderer.setNegativeItemLabelPosition(position2); lineRenderer.setNegativeItemLabelPosition(position2); } else if (orientation == PlotOrientation.VERTICAL) { ItemLabelPosition position1 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BOTTOM_CENTER); barRenderer.setPositiveItemLabelPosition(position1); lineRenderer.setPositiveItemLabelPosition(position1); ItemLabelPosition position2 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE6, TextAnchor.TOP_CENTER); barRenderer.setNegativeItemLabelPosition(position2); lineRenderer.setNegativeItemLabelPosition(position2); } if (tooltips) { barRenderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator()); lineRenderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator()); } if (urls) { barRenderer.setBaseItemURLGenerator(new StandardCategoryURLGenerator()); lineRenderer.setBaseItemURLGenerator(new StandardCategoryURLGenerator()); } if (chartDefinition.getMaxBarWidth() != null) { barRenderer.setMaximumBarWidth(chartDefinition.getMaxBarWidth().doubleValue()); } // setting some line attributes lineRenderer.setStroke(JFreeChartEngine.getLineStyleStroke(chartDefinition.getLineStyle(), chartDefinition.getLineWidth())); lineRenderer.setShapesVisible(chartDefinition.isMarkersVisible()); lineRenderer.setBaseShapesFilled(chartDefinition.isMarkersVisible()); /* * Create plot and make necessary adjustments for overlaid chart */ // create the plot with bar chart CategoryPlot plot = new CategoryPlot(barsDataset, catAxis, barsAxis, barRenderer); // add line renderer plot.setRenderer(1, lineRenderer); // add lines dataset, renderer and axis to plot plot.setDataset(1, linesDataset); plot.setRangeAxis(1, linesAxis); // map lines to second axis plot.mapDatasetToRangeAxis(1, 1); // set rendering order plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD); // set location of second axis plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_RIGHT); // standard settings for plots JFreeChartEngine.updatePlot(plot, barsDataset); // additional settings for second axis ValueAxis secondValueAxis = plot.getRangeAxis(1); if (secondValueAxis != null) { if (chartDefinition.getLinesRangeTitle() != null) { secondValueAxis.setLabel(chartDefinition.getLinesRangeTitle()); } if (chartDefinition.getLinesRangeTitleFont() != null) { secondValueAxis.setLabelFont(chartDefinition.getLinesRangeTitleFont()); } if (chartDefinition.getLinesRangeTickFont() != null) { secondValueAxis.setTickLabelFont(chartDefinition.getLinesRangeTickFont()); } if (chartDefinition.getLinesRangeMinimum() != ValueAxis.DEFAULT_LOWER_BOUND) { secondValueAxis.setLowerBound(chartDefinition.getLinesRangeMinimum()); } if (chartDefinition.getLinesRangeMaximum() != ValueAxis.DEFAULT_UPPER_BOUND) { secondValueAxis.setUpperBound(chartDefinition.getLinesRangeMaximum()); } } JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend); return chart; }
From source file:org.n52.oxf.render.sos.AnimatedMapBarChartRenderer.java
protected Image renderFrame(ITimePosition[] sortedTimeArray, int currentTimeIndex, int screenW, int screenH, IBoundingBox bbox, Set<OXFFeature> featuresWithCharts, ObservationSeriesCollection tupleFinder) { ContextBoundingBox contextBBox = new ContextBoundingBox(bbox); BufferedImage image = new BufferedImage(screenW, screenH, BufferedImage.TYPE_INT_RGB); Graphics2D g = image.createGraphics(); // draw white background: g.setColor(Color.WHITE);//from w w w . j a v a 2 s . co m g.fillRect(0, 0, screenW, screenH); g.setColor(Color.BLACK); ITimePosition currentTimePos = sortedTimeArray[currentTimeIndex]; for (OXFFeature chartFeature : featuresWithCharts) { // // create Plot for each "chart feature" and add it to the cache: // if (!chartCache.contains(currentTimePos, chartFeature)) { // if there is a data tuple for the current time position -> create a new plot if (tupleFinder.getTuple(chartFeature, currentTimePos) != null) { CategoryPlot plot = drawChart4FOI(chartFeature.getID(), currentTimePos.toString(), tupleFinder.getTuple(chartFeature, currentTimePos)); chartCache.add(currentTimePos, chartFeature, plot); } } CategoryPlot plot = (CategoryPlot) chartCache.get(currentTimePos, chartFeature); // if there wasn't a plot for the current time position go backwards through the sortedTimeArray and take the most recent one: int j = currentTimeIndex - 1; while (plot == null && j >= 0) { plot = (CategoryPlot) chartCache.get(sortedTimeArray[j], chartFeature); j--; } // // draw the plots into the image at the georeferenced position of the corresponding chartFeature: // Point pRealWorld = (Point) chartFeature.getGeometry(); java.awt.Point pScreen = ContextBoundingBox.realworld2Screen(contextBBox.getActualBBox(), screenW, screenH, new Point2D.Double(pRealWorld.getCoordinate().x, pRealWorld.getCoordinate().y)); // if an appropriate plot was found -> draw it if (plot != null) { for (int i = 0; i < observedProperties.length; i++) { plot.getRangeAxis(i).setRange((Double) tupleFinder.getMinimum(i) - 5, (Double) tupleFinder.getMaximum(i)); if (i > 0) { plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_RIGHT); } } plot.draw(g, new Rectangle2D.Float(pScreen.x + X_SHIFT + 10, pScreen.y + Y_SHIFT, CHART_WIDTH + observedProperties.length * CHART_WIDTH_MULTIPLICATOR, CHART_HEIGHT), null, null, null); } // otherwise draw "no data available" else { g.drawString("No data available", pScreen.x + X_SHIFT, pScreen.y + Y_SHIFT); } // draw point of feature: g.fillOval(pScreen.x - (FeatureGeometryRenderer.DOT_SIZE_POINT / 2), pScreen.y - (FeatureGeometryRenderer.DOT_SIZE_POINT / 2), FeatureGeometryRenderer.DOT_SIZE_POINT, FeatureGeometryRenderer.DOT_SIZE_POINT); } return image; }
From source file:com.rapidminer.gui.new_plotter.engine.jfreechart.JFreeChartPlotEngine.java
private void setRangeAxisLabel(String name, RangeAxisConfig source) { JFreeChart chart = getCurrentChart(); if (chart != null) { Plot plot = chart.getPlot();// w ww . j av a 2 s .c om int rangeAxisIdx = plotInstance.getCurrentPlotConfigurationClone() .getIndexOfRangeAxisConfigById(source.getId()); if (rangeAxisIdx == -1) { return; } if (plot instanceof CategoryPlot) { CategoryPlot categoryPlot = (CategoryPlot) plot; ValueAxis valueAxis = categoryPlot.getRangeAxis(rangeAxisIdx); if (valueAxis != null) { valueAxis.setLabel(name); } } else { XYPlot xyPlot = (XYPlot) plot; ValueAxis valueAxis = xyPlot.getRangeAxis(rangeAxisIdx); if (valueAxis != null) { valueAxis.setLabel(name); } } } }