List of usage examples for org.jfree.chart.plot XYPlot setAxisOffset
public void setAxisOffset(RectangleInsets offset)
From source file:org.n52.server.io.render.DiagramRenderer.java
/** * <pre>/*from www . ja v a 2s . c o m*/ * dataset := associated to one range-axis; * corresponds to one observedProperty; * may contain multiple series; * series := corresponds to a time series for one foi * </pre> * * . * * @param entireCollMap * the entire coll map * @param options * the options * @param begin * the begin * @param end * the end * @param compress * @return the j free chart */ public JFreeChart renderChart(Map<String, OXFFeatureCollection> entireCollMap, DesignOptions options, Calendar begin, Calendar end, boolean compress) { DesignDescriptionList designDescriptions = buildUpDesignDescriptionList(options); /*** FIRST RUN ***/ JFreeChart chart = initializeTimeSeriesChart(); chart.setBackgroundPaint(Color.white); if (!this.isOverview) { chart.addSubtitle(new TextTitle(ConfigurationContext.COPYRIGHT, new Font(LABEL_FONT, Font.PLAIN, 9), Color.black, RectangleEdge.BOTTOM, HorizontalAlignment.RIGHT, VerticalAlignment.BOTTOM, new RectangleInsets(0, 0, 20, 20))); } XYPlot plot = (XYPlot) chart.getPlot(); plot.setBackgroundPaint(Color.white); plot.setDomainGridlinePaint(Color.lightGray); plot.setRangeGridlinePaint(Color.lightGray); plot.setAxisOffset(new RectangleInsets(2.0, 2.0, 2.0, 2.0)); plot.setDomainCrosshairVisible(true); plot.setRangeCrosshairVisible(true); plot.setDomainGridlinesVisible(options.getGrid()); plot.setRangeGridlinesVisible(options.getGrid()); // add additional datasets: DateAxis dateAxis = (DateAxis) plot.getDomainAxis(); dateAxis.setRange(begin.getTime(), end.getTime()); dateAxis.setDateFormatOverride(new SimpleDateFormat()); dateAxis.setTimeZone(end.getTimeZone()); // add all axes String[] phenomenaIds = options.getAllPhenomenIds(); // all the axis indices to map them later HashMap<String, Integer> axes = new HashMap<String, Integer>(); for (int i = 0; i < phenomenaIds.length; i++) { axes.put(phenomenaIds[i], i); plot.setRangeAxis(i, new NumberAxis(phenomenaIds[i])); } // list range markers ArrayList<ValueMarker> referenceMarkers = new ArrayList<ValueMarker>(); HashMap<String, double[]> referenceBounds = new HashMap<String, double[]>(); // create all TS collections for (int i = 0; i < options.getProperties().size(); i++) { TimeseriesProperties prop = options.getProperties().get(i); String phenomenonId = prop.getPhenomenon(); TimeSeriesCollection dataset = createDataset(entireCollMap, prop, phenomenonId, compress); dataset.setGroup(new DatasetGroup(prop.getTimeseriesId())); XYDataset additionalDataset = dataset; NumberAxis axe = (NumberAxis) plot.getRangeAxis(axes.get(phenomenonId)); if (this.isOverview) { axe.setAutoRange(true); axe.setAutoRangeIncludesZero(false); } else if (prop.getAxisUpperBound() == prop.getAxisLowerBound() || prop.isAutoScale()) { if (prop.isZeroScaled()) { axe.setAutoRangeIncludesZero(true); } else { axe.setAutoRangeIncludesZero(false); } } else { if (prop.isZeroScaled()) { if (axe.getUpperBound() < prop.getAxisUpperBound()) { axe.setUpperBound(prop.getAxisUpperBound()); } if (axe.getLowerBound() > prop.getAxisLowerBound()) { axe.setLowerBound(prop.getAxisLowerBound()); } } else { axe.setRange(prop.getAxisLowerBound(), prop.getAxisUpperBound()); axe.setAutoRangeIncludesZero(false); } } plot.setDataset(i, additionalDataset); plot.mapDatasetToRangeAxis(i, axes.get(phenomenonId)); // set bounds new for reference values if (!referenceBounds.containsKey(phenomenonId)) { double[] bounds = new double[] { axe.getLowerBound(), axe.getUpperBound() }; referenceBounds.put(phenomenonId, bounds); } else { double[] bounds = referenceBounds.get(phenomenonId); if (bounds[0] >= axe.getLowerBound()) { bounds[0] = axe.getLowerBound(); } if (bounds[1] <= axe.getUpperBound()) { bounds[1] = axe.getUpperBound(); } } double[] bounds = referenceBounds.get(phenomenonId); for (String string : prop.getReferenceValues()) { if (prop.getRefValue(string).show()) { Double value = prop.getRefValue(string).getValue(); if (value <= bounds[0]) { bounds[0] = value; } else if (value >= bounds[1]) { bounds[1] = value; } } } Axis axis = prop.getAxis(); if (axis == null) { axis = new Axis(axe.getUpperBound(), axe.getLowerBound()); } else if (prop.isAutoScale()) { axis.setLowerBound(axe.getLowerBound()); axis.setUpperBound(axe.getUpperBound()); axis.setMaxY(axis.getMaxY()); axis.setMinY(axis.getMinY()); } prop.setAxisData(axis); this.axisMapping.put(prop.getTimeseriesId(), axis); for (String string : prop.getReferenceValues()) { if (prop.getRefValue(string).show()) { referenceMarkers.add(new ValueMarker(prop.getRefValue(string).getValue(), Color.decode(prop.getRefValue(string).getColor()), new BasicStroke(1.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f))); } } plot.mapDatasetToRangeAxis(i, axes.get(phenomenonId)); } for (ValueMarker valueMarker : referenceMarkers) { plot.addRangeMarker(valueMarker); } // show actual time ValueMarker nowMarker = new ValueMarker(System.currentTimeMillis(), Color.orange, new BasicStroke(1.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f)); plot.addDomainMarker(nowMarker); if (!this.isOverview) { Iterator<Entry<String, double[]>> iterator = referenceBounds.entrySet().iterator(); while (iterator.hasNext()) { Entry<String, double[]> boundsEntry = iterator.next(); String phenId = boundsEntry.getKey(); NumberAxis axe = (NumberAxis) plot.getRangeAxis(axes.get(phenId)); axe.setAutoRange(true); // add a margin double marginOffset = (boundsEntry.getValue()[1] - boundsEntry.getValue()[0]) / 25; boundsEntry.getValue()[0] -= marginOffset; boundsEntry.getValue()[1] += marginOffset; axe.setRange(boundsEntry.getValue()[0], boundsEntry.getValue()[1]); } } /**** SECOND RUN ***/ // set domain axis labels: plot.getDomainAxis().setLabelFont(label); plot.getDomainAxis().setLabelPaint(LABEL_COLOR); plot.getDomainAxis().setTickLabelFont(tickLabelDomain); plot.getDomainAxis().setTickLabelPaint(LABEL_COLOR); plot.getDomainAxis().setLabel(designDescriptions.getDomainAxisLabel()); // define the design for each series: for (int datasetIndex = 0; datasetIndex < plot.getDatasetCount(); datasetIndex++) { TimeSeriesCollection dataset = (TimeSeriesCollection) plot.getDataset(datasetIndex); for (int seriesIndex = 0; seriesIndex < dataset.getSeriesCount(); seriesIndex++) { String timeseriesId = (String) dataset.getSeries(seriesIndex).getKey(); RenderingDesign dd = designDescriptions.get(timeseriesId); if (dd != null) { // LINESTYLE: String lineStyle = dd.getLineStyle(); int width = dd.getLineWidth(); if (this.isOverview) { width = width / 2; width = (width == 0) ? 1 : width; } // "1" is lineStyle "line" if (lineStyle.equalsIgnoreCase(LINE)) { XYLineAndShapeRenderer ren = new XYLineAndShapeRenderer(true, false); ren.setStroke(new BasicStroke(width)); plot.setRenderer(datasetIndex, ren); } // "2" is lineStyle "area" else if (lineStyle.equalsIgnoreCase(AREA)) { plot.setRenderer(datasetIndex, new XYAreaRenderer()); } // "3" is lineStyle "dotted" else if (lineStyle.equalsIgnoreCase(DOTTED)) { XYLineAndShapeRenderer ren = new XYLineAndShapeRenderer(false, true); ren.setShape(new Ellipse2D.Double(-width, -width, 2 * width, 2 * width)); plot.setRenderer(datasetIndex, ren); } // "4" is dashed else if (lineStyle.equalsIgnoreCase("4")) { // dashed XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true, false); renderer.setSeriesStroke(0, new BasicStroke(width, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f, new float[] { 4.0f * width, 4.0f * width }, 0.0f)); plot.setRenderer(datasetIndex, renderer); } else if (lineStyle.equalsIgnoreCase("5")) { // lines and dots XYLineAndShapeRenderer ren = new XYLineAndShapeRenderer(true, true); int thickness = 2 * width; ren.setShape(new Ellipse2D.Double(-width, -width, thickness, thickness)); ren.setStroke(new BasicStroke(width)); plot.setRenderer(datasetIndex, ren); } else { // default is lineStyle "line" plot.setRenderer(datasetIndex, new XYLineAndShapeRenderer(true, false)); } plot.getRenderer(datasetIndex).setSeriesPaint(seriesIndex, dd.getColor()); // plot.getRenderer(datasetIndex).setShapesVisible(true); XYToolTipGenerator toolTipGenerator = StandardXYToolTipGenerator.getTimeSeriesInstance(); XYURLGenerator urlGenerator = new MetadataInURLGenerator(designDescriptions); plot.getRenderer(datasetIndex).setBaseToolTipGenerator(toolTipGenerator); plot.getRenderer(datasetIndex).setURLGenerator(urlGenerator); // GRID: // PROBLEM: JFreeChart only allows to switch the grid on/off // for the whole XYPlot. And the // grid will always be displayed for the first series in the // plot. I'll always show the // grid. // --> plot.setDomainGridlinesVisible(visible) // RANGE AXIS LABELS: if (isOverview) { plot.getRangeAxisForDataset(datasetIndex).setTickLabelsVisible(false); plot.getRangeAxisForDataset(datasetIndex).setTickMarksVisible(false); plot.getRangeAxisForDataset(datasetIndex).setVisible(false); } else { plot.getRangeAxisForDataset(datasetIndex).setLabelFont(label); plot.getRangeAxisForDataset(datasetIndex).setLabelPaint(LABEL_COLOR); plot.getRangeAxisForDataset(datasetIndex).setTickLabelFont(tickLabelDomain); plot.getRangeAxisForDataset(datasetIndex).setTickLabelPaint(LABEL_COLOR); StringBuilder unitOfMeasure = new StringBuilder(); unitOfMeasure.append(dd.getPhenomenon().getLabel()); String uomLabel = dd.getUomLabel(); if (uomLabel != null && !uomLabel.isEmpty()) { unitOfMeasure.append(" (").append(uomLabel).append(")"); } plot.getRangeAxisForDataset(datasetIndex).setLabel(unitOfMeasure.toString()); } } } } return chart; }
From source file:dk.netarkivet.harvester.harvesting.monitor.StartedJobHistoryChartGen.java
/** * Generates a chart in PNG format.//from w w w .j a v a 2 s . c o m * @param outputFile the output file, it should exist. * @param pxWidth the image width in pixels. * @param pxHeight the image height in pixels. * @param chartTitle the chart title, may be null. * @param xAxisTitle the x axis title * @param yDataSeriesRange the axis range (null for auto) * @param yDataSeriesTitles the Y axis titles. * @param timeValuesInSeconds the time values in seconds * @param yDataSeries the Y axis value series. * @param yDataSeriesColors the Y axis value series drawing colors. * @param yDataSeriesTickSuffix TODO explain argument yDataSeriesTickSuffix * @param drawBorder draw, or not, the border. * @param backgroundColor the chart background color. */ final void generatePngChart(File outputFile, int pxWidth, int pxHeight, String chartTitle, String xAxisTitle, String[] yDataSeriesTitles, double[] timeValuesInSeconds, double[][] yDataSeriesRange, double[][] yDataSeries, Color[] yDataSeriesColors, String[] yDataSeriesTickSuffix, boolean drawBorder, Color backgroundColor) { // Domain axis NumberAxis xAxis = new NumberAxis(xAxisTitle); xAxis.setFixedDimension(CHART_AXIS_DIMENSION); xAxis.setLabelPaint(Color.black); xAxis.setTickLabelPaint(Color.black); double maxSeconds = getMaxValue(timeValuesInSeconds); TimeAxisResolution xAxisRes = TimeAxisResolution.findTimeUnit(maxSeconds); xAxis.setTickUnit(new NumberTickUnit(xAxisRes.tickStep)); double[] scaledTimeValues = xAxisRes.scale(timeValuesInSeconds); String tickSymbol = I18N.getString(locale, "running.job.details.chart.timeunit.symbol." + xAxisRes.name()); xAxis.setNumberFormatOverride(new DecimalFormat("###.##'" + tickSymbol + "'")); // First dataset String firstDataSetTitle = yDataSeriesTitles[0]; XYDataset firstDataSet = createXYDataSet(firstDataSetTitle, scaledTimeValues, yDataSeries[0]); Color firstDataSetColor = yDataSeriesColors[0]; // First range axis NumberAxis firstYAxis = new NumberAxis(firstDataSetTitle); firstYAxis.setFixedDimension(CHART_AXIS_DIMENSION); setAxisRange(firstYAxis, yDataSeriesRange[0]); firstYAxis.setLabelPaint(firstDataSetColor); firstYAxis.setTickLabelPaint(firstDataSetColor); String firstAxisTickSuffix = yDataSeriesTickSuffix[0]; if (firstAxisTickSuffix != null && !firstAxisTickSuffix.isEmpty()) { firstYAxis.setNumberFormatOverride(new DecimalFormat("###.##'" + firstAxisTickSuffix + "'")); } // Create the plot with domain axis and first range axis XYPlot plot = new XYPlot(firstDataSet, xAxis, firstYAxis, null); XYLineAndShapeRenderer firstRenderer = new XYLineAndShapeRenderer(true, false); plot.setRenderer(firstRenderer); plot.setOrientation(PlotOrientation.VERTICAL); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); firstRenderer.setSeriesPaint(0, firstDataSetColor); // Now iterate on next axes for (int i = 1; i < yDataSeries.length; i++) { // Create axis String seriesTitle = yDataSeriesTitles[i]; Color seriesColor = yDataSeriesColors[i]; NumberAxis yAxis = new NumberAxis(seriesTitle); yAxis.setFixedDimension(CHART_AXIS_DIMENSION); setAxisRange(yAxis, yDataSeriesRange[i]); yAxis.setLabelPaint(seriesColor); yAxis.setTickLabelPaint(seriesColor); String yAxisTickSuffix = yDataSeriesTickSuffix[i]; if (yAxisTickSuffix != null && !yAxisTickSuffix.isEmpty()) { yAxis.setNumberFormatOverride(new DecimalFormat("###.##'" + yAxisTickSuffix + "'")); } // Create dataset and add axis to plot plot.setRangeAxis(i, yAxis); plot.setRangeAxisLocation(i, AxisLocation.BOTTOM_OR_LEFT); plot.setDataset(i, createXYDataSet(seriesTitle, scaledTimeValues, yDataSeries[i])); plot.mapDatasetToRangeAxis(i, i); XYItemRenderer renderer = new StandardXYItemRenderer(); renderer.setSeriesPaint(0, seriesColor); plot.setRenderer(i, renderer); } // Create the chart JFreeChart chart = new JFreeChart(chartTitle, JFreeChart.DEFAULT_TITLE_FONT, plot, false); // Customize rendering chart.setBackgroundPaint(Color.white); chart.setBorderVisible(true); chart.setBorderPaint(Color.BLACK); // Render image try { ChartUtilities.saveChartAsPNG(outputFile, chart, pxWidth, pxHeight); } catch (IOException e) { LOG.error("Chart export failed", e); } }
From source file:org.n52.server.sos.render.DiagramRenderer.java
/** * <pre>//from w w w. j a v a 2s.c om * dataset := associated to one range-axis; * corresponds to one observedProperty; * may contain multiple series; * series := corresponds to a time series for one foi * </pre> * * . * * @param entireCollMap * the entire coll map * @param options * the options * @param begin * the begin * @param end * the end * @param compress * @return the j free chart */ public JFreeChart renderChart(Map<String, OXFFeatureCollection> entireCollMap, DesignOptions options, Calendar begin, Calendar end, boolean compress) { DesignDescriptionList designDescriptions = buildUpDesignDescriptionList(options); /*** FIRST RUN ***/ JFreeChart chart = initializeTimeSeriesChart(); chart.setBackgroundPaint(Color.white); if (!this.isOverview) { chart.addSubtitle(new TextTitle(ConfigurationContext.COPYRIGHT, new Font(LABEL_FONT, Font.PLAIN, 9), Color.black, RectangleEdge.BOTTOM, HorizontalAlignment.RIGHT, VerticalAlignment.BOTTOM, new RectangleInsets(0, 0, 20, 20))); } XYPlot plot = (XYPlot) chart.getPlot(); plot.setBackgroundPaint(Color.white); plot.setDomainGridlinePaint(Color.lightGray); plot.setRangeGridlinePaint(Color.lightGray); plot.setAxisOffset(new RectangleInsets(2.0, 2.0, 2.0, 2.0)); plot.setDomainCrosshairVisible(true); plot.setRangeCrosshairVisible(true); plot.setDomainGridlinesVisible(options.getGrid()); plot.setRangeGridlinesVisible(options.getGrid()); // add additional datasets: DateAxis dateAxis = (DateAxis) plot.getDomainAxis(); dateAxis.setRange(begin.getTime(), end.getTime()); dateAxis.setDateFormatOverride(new SimpleDateFormat()); // add all axes String[] phenomenaIds = options.getAllPhenomenIds(); // all the axis indices to map them later HashMap<String, Integer> axes = new HashMap<String, Integer>(); for (int i = 0; i < phenomenaIds.length; i++) { axes.put(phenomenaIds[i], i); plot.setRangeAxis(i, new NumberAxis(phenomenaIds[i])); } // list range markers ArrayList<ValueMarker> referenceMarkers = new ArrayList<ValueMarker>(); HashMap<String, double[]> referenceBounds = new HashMap<String, double[]>(); // create all TS collections for (int i = 0; i < options.getProperties().size(); i++) { TimeseriesProperties prop = options.getProperties().get(i); String phenomenonId = prop.getPhenomenon(); TimeSeriesCollection dataset = createDataset(entireCollMap, prop, phenomenonId, compress); dataset.setGroup(new DatasetGroup(prop.getTimeseriesId())); XYDataset additionalDataset = dataset; NumberAxis axe = (NumberAxis) plot.getRangeAxis(axes.get(phenomenonId)); if (this.isOverview) { axe.setAutoRange(true); axe.setAutoRangeIncludesZero(false); } else if (prop.getAxisUpperBound() == prop.getAxisLowerBound() || prop.isAutoScale()) { if (prop.isZeroScaled()) { axe.setAutoRangeIncludesZero(true); } else { axe.setAutoRangeIncludesZero(false); } } else { if (prop.isZeroScaled()) { if (axe.getUpperBound() < prop.getAxisUpperBound()) { axe.setUpperBound(prop.getAxisUpperBound()); } if (axe.getLowerBound() > prop.getAxisLowerBound()) { axe.setLowerBound(prop.getAxisLowerBound()); } } else { axe.setRange(prop.getAxisLowerBound(), prop.getAxisUpperBound()); axe.setAutoRangeIncludesZero(false); } } plot.setDataset(i, additionalDataset); plot.mapDatasetToRangeAxis(i, axes.get(phenomenonId)); // set bounds new for reference values if (!referenceBounds.containsKey(phenomenonId)) { double[] bounds = new double[] { axe.getLowerBound(), axe.getUpperBound() }; referenceBounds.put(phenomenonId, bounds); } else { double[] bounds = referenceBounds.get(phenomenonId); if (bounds[0] >= axe.getLowerBound()) { bounds[0] = axe.getLowerBound(); } if (bounds[1] <= axe.getUpperBound()) { bounds[1] = axe.getUpperBound(); } } double[] bounds = referenceBounds.get(phenomenonId); for (String string : prop.getReferenceValues()) { if (prop.getRefValue(string).show()) { Double value = prop.getRefValue(string).getValue(); if (value <= bounds[0]) { bounds[0] = value; } else if (value >= bounds[1]) { bounds[1] = value; } } } Axis axis = prop.getAxis(); if (axis == null) { axis = new Axis(axe.getUpperBound(), axe.getLowerBound()); } else if (prop.isAutoScale()) { axis.setLowerBound(axe.getLowerBound()); axis.setUpperBound(axe.getUpperBound()); axis.setMaxY(axis.getMaxY()); axis.setMinY(axis.getMinY()); } prop.setAxisData(axis); this.axisMapping.put(prop.getTimeseriesId(), axis); for (String string : prop.getReferenceValues()) { if (prop.getRefValue(string).show()) { referenceMarkers.add(new ValueMarker(prop.getRefValue(string).getValue(), Color.decode(prop.getRefValue(string).getColor()), new BasicStroke(1.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f))); } } plot.mapDatasetToRangeAxis(i, axes.get(phenomenonId)); } for (ValueMarker valueMarker : referenceMarkers) { plot.addRangeMarker(valueMarker); } // show actual time ValueMarker nowMarker = new ValueMarker(System.currentTimeMillis(), Color.orange, new BasicStroke(1.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f)); plot.addDomainMarker(nowMarker); if (!this.isOverview) { Iterator<Entry<String, double[]>> iterator = referenceBounds.entrySet().iterator(); while (iterator.hasNext()) { Entry<String, double[]> boundsEntry = iterator.next(); String phenId = boundsEntry.getKey(); NumberAxis axe = (NumberAxis) plot.getRangeAxis(axes.get(phenId)); axe.setAutoRange(true); // add a margin double marginOffset = (boundsEntry.getValue()[1] - boundsEntry.getValue()[0]) / 25; boundsEntry.getValue()[0] -= marginOffset; boundsEntry.getValue()[1] += marginOffset; axe.setRange(boundsEntry.getValue()[0], boundsEntry.getValue()[1]); } } /**** SECOND RUN ***/ // set domain axis labels: plot.getDomainAxis().setLabelFont(label); plot.getDomainAxis().setLabelPaint(LABEL_COLOR); plot.getDomainAxis().setTickLabelFont(tickLabelDomain); plot.getDomainAxis().setTickLabelPaint(LABEL_COLOR); plot.getDomainAxis().setLabel(designDescriptions.getDomainAxisLabel()); // define the design for each series: for (int datasetIndex = 0; datasetIndex < plot.getDatasetCount(); datasetIndex++) { TimeSeriesCollection dataset = (TimeSeriesCollection) plot.getDataset(datasetIndex); for (int seriesIndex = 0; seriesIndex < dataset.getSeriesCount(); seriesIndex++) { String timeseriesId = (String) dataset.getSeries(seriesIndex).getKey(); RenderingDesign dd = designDescriptions.get(timeseriesId); if (dd != null) { // LINESTYLE: String lineStyle = dd.getLineStyle(); int width = dd.getLineWidth(); if (this.isOverview) { width = width / 2; width = (width == 0) ? 1 : width; } // "1" is lineStyle "line" if (lineStyle.equalsIgnoreCase(LINE)) { XYLineAndShapeRenderer ren = new XYLineAndShapeRenderer(true, false); ren.setStroke(new BasicStroke(width)); plot.setRenderer(datasetIndex, ren); } // "2" is lineStyle "area" else if (lineStyle.equalsIgnoreCase(AREA)) { plot.setRenderer(datasetIndex, new XYAreaRenderer()); } // "3" is lineStyle "dotted" else if (lineStyle.equalsIgnoreCase(DOTTED)) { XYLineAndShapeRenderer ren = new XYLineAndShapeRenderer(false, true); ren.setShape(new Ellipse2D.Double(-width, -width, 2 * width, 2 * width)); plot.setRenderer(datasetIndex, ren); } // "4" is dashed else if (lineStyle.equalsIgnoreCase("4")) { XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true, false); renderer.setSeriesStroke(0, new BasicStroke(width, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f, new float[] { 4.0f * width, 4.0f * width }, 0.0f)); plot.setRenderer(datasetIndex, renderer); } else if (lineStyle.equalsIgnoreCase("5")) { // lines and dots XYLineAndShapeRenderer ren = new XYLineAndShapeRenderer(true, true); int thickness = 2 * width; ren.setShape(new Ellipse2D.Double(-width, -width, thickness, thickness)); ren.setStroke(new BasicStroke(width)); plot.setRenderer(datasetIndex, ren); } else { // default is lineStyle "line" plot.setRenderer(datasetIndex, new XYLineAndShapeRenderer(true, false)); } plot.getRenderer(datasetIndex).setSeriesPaint(seriesIndex, dd.getColor()); // plot.getRenderer(datasetIndex).setShapesVisible(true); XYToolTipGenerator toolTipGenerator = StandardXYToolTipGenerator.getTimeSeriesInstance(); XYURLGenerator urlGenerator = new MetadataInURLGenerator(designDescriptions); plot.getRenderer(datasetIndex).setBaseToolTipGenerator(toolTipGenerator); plot.getRenderer(datasetIndex).setURLGenerator(urlGenerator); // GRID: // PROBLEM: JFreeChart only allows to switch the grid on/off // for the whole XYPlot. And the // grid will always be displayed for the first series in the // plot. I'll always show the // grid. // --> plot.setDomainGridlinesVisible(visible) // RANGE AXIS LABELS: if (isOverview) { plot.getRangeAxisForDataset(datasetIndex).setTickLabelsVisible(false); plot.getRangeAxisForDataset(datasetIndex).setTickMarksVisible(false); plot.getRangeAxisForDataset(datasetIndex).setVisible(false); } else { plot.getRangeAxisForDataset(datasetIndex).setLabelFont(label); plot.getRangeAxisForDataset(datasetIndex).setLabelPaint(LABEL_COLOR); plot.getRangeAxisForDataset(datasetIndex).setTickLabelFont(tickLabelDomain); plot.getRangeAxisForDataset(datasetIndex).setTickLabelPaint(LABEL_COLOR); StringBuilder unitOfMeasure = new StringBuilder(); unitOfMeasure.append(dd.getPhenomenon().getLabel()); String uomLabel = dd.getUomLabel(); if (uomLabel != null && !uomLabel.isEmpty()) { unitOfMeasure.append(" (").append(uomLabel).append(")"); } plot.getRangeAxisForDataset(datasetIndex).setLabel(unitOfMeasure.toString()); } } } } return chart; }
From source file:org.locationtech.udig.processingtoolbox.tools.ScatterPlotDialog.java
private void updateChart(SimpleFeatureCollection features, String xField, String yField) { // 1. Create a single plot containing both the scatter and line XYPlot plot = new XYPlot(); plot.setOrientation(PlotOrientation.VERTICAL); plot.setBackgroundPaint(java.awt.Color.WHITE); plot.setDomainPannable(false);/* w w w .j av a 2 s .c om*/ plot.setRangePannable(false); plot.setSeriesRenderingOrder(SeriesRenderingOrder.FORWARD); plot.setDomainCrosshairVisible(false); plot.setRangeCrosshairVisible(false); plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); // 2. Setup Scatter plot // Create the scatter data, renderer, and axis int fontStyle = java.awt.Font.BOLD; FontData fontData = getShell().getDisplay().getSystemFont().getFontData()[0]; NumberAxis xPlotAxis = new NumberAxis(xField); // Independent variable xPlotAxis.setLabelFont(new Font(fontData.getName(), fontStyle, 12)); xPlotAxis.setTickLabelFont(new Font(fontData.getName(), fontStyle, 10)); NumberAxis yPlotAxis = new NumberAxis(yField); // Dependent variable yPlotAxis.setLabelFont(new Font(fontData.getName(), fontStyle, 12)); yPlotAxis.setTickLabelFont(new Font(fontData.getName(), fontStyle, 10)); XYToolTipGenerator plotToolTip = new StandardXYToolTipGenerator(); XYItemRenderer plotRenderer = new XYLineAndShapeRenderer(false, true); // Shapes only plotRenderer.setSeriesShape(0, new Ellipse2D.Double(0, 0, 3, 3)); plotRenderer.setSeriesPaint(0, java.awt.Color.BLUE); // dot plotRenderer.setBaseToolTipGenerator(plotToolTip); // Set the scatter data, renderer, and axis into plot plot.setDataset(0, getScatterPlotData(features, xField, yField)); xPlotAxis.setAutoRangeIncludesZero(false); xPlotAxis.setAutoRange(false); double differUpper = minMaxVisitor.getMaxX() - minMaxVisitor.getAverageX(); double differLower = minMaxVisitor.getAverageX() - minMaxVisitor.getMinX(); double gap = Math.abs(differUpper - differLower); if (differUpper > differLower) { xPlotAxis.setRange(minMaxVisitor.getMinX() - gap, minMaxVisitor.getMaxX()); } else { xPlotAxis.setRange(minMaxVisitor.getMinX(), minMaxVisitor.getMaxX() + gap); } yPlotAxis.setAutoRangeIncludesZero(false); yPlotAxis.setAutoRange(false); differUpper = minMaxVisitor.getMaxY() - minMaxVisitor.getAverageY(); differLower = minMaxVisitor.getAverageY() - minMaxVisitor.getMinY(); gap = Math.abs(differUpper - differLower); if (differUpper > differLower) { yPlotAxis.setRange(minMaxVisitor.getMinY() - gap, minMaxVisitor.getMaxY()); } else { yPlotAxis.setRange(minMaxVisitor.getMinY(), minMaxVisitor.getMaxY() + gap); } plot.setRenderer(0, plotRenderer); plot.setDomainAxis(0, xPlotAxis); plot.setRangeAxis(0, yPlotAxis); // Map the scatter to the first Domain and first Range plot.mapDatasetToDomainAxis(0, 0); plot.mapDatasetToRangeAxis(0, 0); // 3. Setup line // Create the line data, renderer, and axis XYItemRenderer lineRenderer = new XYLineAndShapeRenderer(true, false); // Lines only lineRenderer.setSeriesPaint(0, java.awt.Color.GRAY); lineRenderer.setSeriesPaint(1, java.awt.Color.GRAY); lineRenderer.setSeriesPaint(2, java.awt.Color.GRAY); // Set the line data, renderer, and axis into plot NumberAxis xLineAxis = new NumberAxis(EMPTY); xLineAxis.setTickMarksVisible(false); xLineAxis.setTickLabelsVisible(false); NumberAxis yLineAxis = new NumberAxis(EMPTY); yLineAxis.setTickMarksVisible(false); yLineAxis.setTickLabelsVisible(false); XYSeriesCollection lineDataset = new XYSeriesCollection(); // AverageY XYSeries horizontal = new XYSeries("AverageY"); //$NON-NLS-1$ horizontal.add(xPlotAxis.getRange().getLowerBound(), minMaxVisitor.getAverageY()); horizontal.add(xPlotAxis.getRange().getUpperBound(), minMaxVisitor.getAverageY()); lineDataset.addSeries(horizontal); // AverageX XYSeries vertical = new XYSeries("AverageX"); //$NON-NLS-1$ vertical.add(minMaxVisitor.getAverageX(), yPlotAxis.getRange().getLowerBound()); vertical.add(minMaxVisitor.getAverageX(), yPlotAxis.getRange().getUpperBound()); lineDataset.addSeries(vertical); // Degree XYSeries degree = new XYSeries("Deegree"); //$NON-NLS-1$ degree.add(xPlotAxis.getRange().getLowerBound(), yPlotAxis.getRange().getLowerBound()); degree.add(xPlotAxis.getRange().getUpperBound(), yPlotAxis.getRange().getUpperBound()); lineDataset.addSeries(degree); plot.setDataset(1, lineDataset); plot.setRenderer(1, lineRenderer); plot.setDomainAxis(1, xLineAxis); plot.setRangeAxis(1, yLineAxis); // Map the line to the second Domain and second Range plot.mapDatasetToDomainAxis(1, 0); plot.mapDatasetToRangeAxis(1, 0); // 4. Setup Selection NumberAxis xSelectionAxis = new NumberAxis(EMPTY); xSelectionAxis.setTickMarksVisible(false); xSelectionAxis.setTickLabelsVisible(false); NumberAxis ySelectionAxis = new NumberAxis(EMPTY); ySelectionAxis.setTickMarksVisible(false); ySelectionAxis.setTickLabelsVisible(false); XYItemRenderer selectionRenderer = new XYLineAndShapeRenderer(false, true); // Shapes only selectionRenderer.setSeriesShape(0, new Ellipse2D.Double(0, 0, 6, 6)); selectionRenderer.setSeriesPaint(0, java.awt.Color.RED); // dot plot.setDataset(2, new XYSeriesCollection(new XYSeries(EMPTY))); plot.setRenderer(2, selectionRenderer); plot.setDomainAxis(2, xSelectionAxis); plot.setRangeAxis(2, ySelectionAxis); // Map the scatter to the second Domain and second Range plot.mapDatasetToDomainAxis(2, 0); plot.mapDatasetToRangeAxis(2, 0); // 5. Finally, Create the chart with the plot and a legend java.awt.Font titleFont = new Font(fontData.getName(), fontStyle, 20); JFreeChart chart = new JFreeChart(EMPTY, titleFont, plot, false); chart.setBackgroundPaint(java.awt.Color.WHITE); chart.setBorderVisible(false); chartComposite.setChart(chart); chartComposite.forceRedraw(); }
From source file:code.google.gclogviewer.GCLogViewer.java
private JFreeChart createGCTrendChart(GCLogData data) { XYDataset gcTrendDataset = createGCTrendDataset(data, null); JFreeChart chart = ChartFactory.createXYLineChart("GC Trend", "Time(S)", "Pause Time(ms)", gcTrendDataset, PlotOrientation.VERTICAL, true, true, false); chart.setBackgroundPaint(java.awt.Color.white); chart.setBorderVisible(true);/* w ww. ja va 2 s . c om*/ chart.setBorderPaint(java.awt.Color.BLACK); XYPlot plot = (XYPlot) chart.getPlot(); plot.setBackgroundPaint(java.awt.Color.lightGray); plot.setDomainGridlinePaint(java.awt.Color.white); plot.setRangeGridlinePaint(java.awt.Color.white); plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); plot.getRangeAxis().setFixedDimension(15.0); return chart; }
From source file:code.google.gclogviewer.GCLogViewer.java
private JFreeChart createLDSTrendChart(GCLogData data) { XYDataset ldsTrendDataset = createLDSTrendDataset(data); JFreeChart chart = ChartFactory.createXYLineChart("Live Data Size Trend", "Time(S)", "Size(K)", ldsTrendDataset, PlotOrientation.VERTICAL, true, true, false); chart.setBackgroundPaint(java.awt.Color.white); chart.setBorderVisible(true);/*from ww w .j a v a 2s. co m*/ chart.setBorderPaint(java.awt.Color.BLACK); XYPlot plot = (XYPlot) chart.getPlot(); plot.setBackgroundPaint(java.awt.Color.lightGray); plot.setDomainGridlinePaint(java.awt.Color.white); plot.setRangeGridlinePaint(java.awt.Color.white); plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); plot.getRangeAxis().setFixedDimension(15.0); return chart; }
From source file:code.google.gclogviewer.GCLogViewer.java
private JFreeChart createPTOSTrendChart(GCLogData data) { XYDataset ldsTrendDataset = createPTOSTrendDataset(data); JFreeChart chart = ChartFactory.createXYLineChart("Promotion To Old Size Trend", "Time(S)", "Size(K)", ldsTrendDataset, PlotOrientation.VERTICAL, true, true, false); chart.setBackgroundPaint(java.awt.Color.white); chart.setBorderVisible(true);// w ww. jav a 2s. c o m chart.setBorderPaint(java.awt.Color.BLACK); XYPlot plot = (XYPlot) chart.getPlot(); plot.setBackgroundPaint(java.awt.Color.lightGray); plot.setDomainGridlinePaint(java.awt.Color.white); plot.setRangeGridlinePaint(java.awt.Color.white); plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); plot.getRangeAxis().setFixedDimension(15.0); return chart; }
From source file:code.google.gclogviewer.GCLogViewer.java
/** * create Memory Trend Chart/*www .ja v a 2 s .c o m*/ */ private JFreeChart createMemoryTrendChart(GCLogData data) { XYDataset memoryTrendDataset = createMemoryTrendDataset(data, null); JFreeChart chart = ChartFactory.createXYLineChart("Memory Trend", "Time(S)", "Memory Change(K)", memoryTrendDataset, PlotOrientation.VERTICAL, true, true, false); chart.setBackgroundPaint(java.awt.Color.white); chart.setBorderVisible(true); chart.setBorderPaint(java.awt.Color.BLACK); XYPlot plot = (XYPlot) chart.getPlot(); plot.setBackgroundPaint(java.awt.Color.lightGray); plot.setDomainGridlinePaint(java.awt.Color.white); plot.setRangeGridlinePaint(java.awt.Color.white); plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); plot.getRangeAxis().setFixedDimension(15.0); return chart; }
From source file:org.esa.snap.rcp.statistics.ScatterPlotPanel.java
private void createUI() { final XYPlot plot = getPlot(); plot.setAxisOffset(new RectangleInsets(5, 5, 5, 5)); plot.setNoDataMessage(NO_DATA_MESSAGE); int confidenceDSIndex = 0; int regressionDSIndex = 1; int scatterpointsDSIndex = 2; plot.setDataset(confidenceDSIndex, acceptableDeviationDataset); plot.setDataset(regressionDSIndex, regressionDataset); plot.setDataset(scatterpointsDSIndex, scatterpointsDataset); plot.addAnnotation(r2Annotation); final DeviationRenderer identityRenderer = new DeviationRenderer(true, false); identityRenderer.setSeriesPaint(0, StatisticChartStyling.SAMPLE_DATA_PAINT); identityRenderer.setSeriesFillPaint(0, StatisticChartStyling.SAMPLE_DATA_FILL_PAINT); plot.setRenderer(confidenceDSIndex, identityRenderer); final DeviationRenderer regressionRenderer = new DeviationRenderer(true, false); regressionRenderer.setSeriesPaint(0, StatisticChartStyling.REGRESSION_DATA_PAINT); regressionRenderer.setSeriesFillPaint(0, StatisticChartStyling.REGRESSION_DATA_FILL_PAINT); plot.setRenderer(regressionDSIndex, regressionRenderer); final XYErrorRenderer scatterPointsRenderer = new XYErrorRenderer(); scatterPointsRenderer.setDrawXError(true); scatterPointsRenderer.setErrorStroke(new BasicStroke(1)); scatterPointsRenderer.setErrorPaint(StatisticChartStyling.CORRELATIVE_POINT_OUTLINE_PAINT); scatterPointsRenderer.setSeriesShape(0, StatisticChartStyling.CORRELATIVE_POINT_SHAPE); scatterPointsRenderer.setSeriesOutlinePaint(0, StatisticChartStyling.CORRELATIVE_POINT_OUTLINE_PAINT); scatterPointsRenderer.setSeriesFillPaint(0, StatisticChartStyling.CORRELATIVE_POINT_FILL_PAINT); scatterPointsRenderer.setSeriesLinesVisible(0, false); scatterPointsRenderer.setSeriesShapesVisible(0, true); scatterPointsRenderer.setSeriesOutlineStroke(0, new BasicStroke(1.0f)); scatterPointsRenderer.setSeriesToolTipGenerator(0, (dataset, series, item) -> { final XYIntervalSeriesCollection collection = (XYIntervalSeriesCollection) dataset; final Comparable key = collection.getSeriesKey(series); final double xValue = collection.getXValue(series, item); final double endYValue = collection.getEndYValue(series, item); final double yValue = collection.getYValue(series, item); return String.format("%s: mean = %6.2f, sigma = %6.2f | %s: value = %6.2f", getRasterName(), yValue, endYValue - yValue, key, xValue); });/*from www . j ava 2s. c om*/ plot.setRenderer(scatterpointsDSIndex, scatterPointsRenderer); final boolean autoRangeIncludesZero = false; final boolean xLog = scatterPlotModel.xAxisLogScaled; final boolean yLog = scatterPlotModel.yAxisLogScaled; plot.setDomainAxis( StatisticChartStyling.updateScalingOfAxis(xLog, plot.getDomainAxis(), autoRangeIncludesZero)); plot.setRangeAxis( StatisticChartStyling.updateScalingOfAxis(yLog, plot.getRangeAxis(), autoRangeIncludesZero)); createUI(createChartPanel(chart), createInputParameterPanel(), bindingContext); plot.getDomainAxis().addChangeListener(domainAxisChangeListener); scatterPlotDisplay.setMouseWheelEnabled(true); scatterPlotDisplay.setMouseZoomable(true); }
From source file:jchrest.gui.VisualSearchPane.java
private ChartPanel createPanel() { XYSeriesCollection dataset = new XYSeriesCollection(); dataset.addSeries(_trainingTimes);//from ww w . ja va2 s .c o m JFreeChart chart = ChartFactory.createXYLineChart("Plot of network size vs. number of training patterns", "Number of training patterns", "Network size", dataset, org.jfree.chart.plot.PlotOrientation.VERTICAL, true, true, false); XYPlot plot = (XYPlot) chart.getPlot(); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); plot.setDomainCrosshairVisible(true); plot.setRangeCrosshairVisible(true); XYItemRenderer r = plot.getRenderer(); if (r instanceof XYLineAndShapeRenderer) { XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r; renderer.setBaseShapesVisible(true); renderer.setBaseShapesFilled(true); renderer.setDrawSeriesLineAsPath(true); } return new ChartPanel(chart); }