List of usage examples for org.jfree.chart.plot XYPlot getRenderer
public XYItemRenderer getRenderer(int index)
From source file:org.matsim.contrib.drt.analysis.DensityScatterPlots.java
public static JFreeChart createPlot(String title, String xAxisLabel, String yAxisLabel, XYSeries series, Pair<Double, Double> lineCoeffs) { XYSeriesCollection dataset = new XYSeriesCollection(); dataset.addSeries(series);//from w w w.j a va 2 s . c om double maxValue = Math.max(series.getMaxX(), series.getMaxY()); // y=x XYSeries lineXY = new XYSeries("y = x"); lineXY.add(0, 0); lineXY.add(maxValue, maxValue); dataset.addSeries(lineXY); if (lineCoeffs != null) { // a*y+b=x double a = lineCoeffs.getLeft(); double b = lineCoeffs.getRight(); String namePrefix = a == 0 ? "" : (a + " * y + "); XYSeries lineABXY = new XYSeries(namePrefix + b + " = x"); lineABXY.add(b, 0); if (a == 0) { lineABXY.add(b, maxValue); } else { lineABXY.add(maxValue, (maxValue - b) / a); } dataset.addSeries(lineABXY); } final JFreeChart chart = ChartFactory.createScatterPlot(title, xAxisLabel, yAxisLabel, dataset); XYPlot xyPlot = (XYPlot) chart.getPlot(); XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) xyPlot.getRenderer(0); renderer.setSeriesPaint(0, new Color(255, 0, 0, 50)); renderer.setSeriesShape(0, CIRCLE); renderer.setSeriesLinesVisible(0, false); renderer.setSeriesShapesVisible(0, true); renderer.setSeriesVisibleInLegend(0, false); for (int i = 1; i < dataset.getSeriesCount(); i++) { renderer.setSeriesPaint(i, new Color(0, 0, 0)); renderer.setSeriesLinesVisible(i, true); renderer.setSeriesShapesVisible(i, false); renderer.setSeriesVisibleInLegend(i, false); } xyPlot.getDomainAxis().setUpperBound(maxValue); xyPlot.getRangeAxis().setUpperBound(maxValue); xyPlot.getDomainAxis().setLowerBound(0); xyPlot.getRangeAxis().setLowerBound(0); return chart; }
From source file:org.fhcrc.cpl.viewer.gui.SpectrumChartFactory.java
public static void setColors(XYPlot xy, Color[] colors) { for (int c = 0; c < colors.length; c++) { XYItemRenderer r = xy.getRenderer(c); if (null == r) continue; r.setSeriesPaint(c, colors[c]);/* w ww . j a v a2 s. co m*/ } }
From source file:io.github.mzmine.util.jfreechart.JFreeChartUtils.java
private static void setDrawSeriesLineAsPath(JFreeChart chart, boolean usePath) { final XYPlot plot = chart.getXYPlot(); for (int i = 0; i < plot.getRendererCount(); i++) { XYItemRenderer renderer = plot.getRenderer(i); if (renderer instanceof XYLineAndShapeRenderer) { XYLineAndShapeRenderer r = (XYLineAndShapeRenderer) renderer; r.setDrawSeriesLineAsPath(usePath); }// w w w . j ava2 s . co m } }
From source file:org.lmn.fc.frameworks.starbase.plugins.observatory.ui.tabs.charts.ChartUIHelper.java
/*********************************************************************************************** * Customise the Plot data renderer to improve legend visibility. * * @param plot/* ww w . j av a2s . c om*/ * @param rendererindex */ public static void customisePlotRenderer(final XYPlot plot, final int rendererindex) { if (plot != null) { final XYItemRenderer renderer; renderer = plot.getRenderer(rendererindex); if ((renderer != null) && (renderer instanceof XYLineAndShapeRenderer)) { final XYLineAndShapeRenderer xyItemRenderer; xyItemRenderer = (XYLineAndShapeRenderer) renderer; xyItemRenderer.setBaseLinesVisible(true); xyItemRenderer.setBaseShapesVisible(false); xyItemRenderer.setBaseShapesFilled(true); xyItemRenderer.setItemLabelsVisible(true); // Set the shape for the Chart legend items setLegendShape(xyItemRenderer); } } }
From source file:net.sf.jsfcomp.chartcreator.utils.ChartAxisUtils.java
public static void createXYSeriesAxis(JFreeChart chart, ChartAxisData chartAxisData, int axisIndex) { ValueAxis axis = null;//from w w w .java 2 s .com if (chartAxisData.getType() != null) { if (chartAxisData.getType().equals("number")) axis = createNumberAxis(chart, chartAxisData); else if (chartAxisData.getType().equals("date")) axis = createDateAxis(chart, chartAxisData); if (chartAxisData.getTickLabelFontSize() > 0) { Font tickFont = CategoryAxis.DEFAULT_TICK_LABEL_FONT .deriveFont(chartAxisData.getTickLabelFontSize()); axis.setTickLabelFont(tickFont); } axis.setTickLabelsVisible(chartAxisData.isTickLabels()); axis.setTickMarksVisible(chartAxisData.isTickMarks()); axis.setVerticalTickLabels(chartAxisData.isVerticalTickLabels()); } XYPlot plot = chart.getXYPlot(); if (chartAxisData.isDomain()) { plot.setDomainAxis(plot.getDomainAxisCount() - 1, axis); } else { plot.setRangeAxis(axisIndex, axis); XYDataset dataset = (XYDataset) chartAxisData.getDatasource(); plot.setRenderer(axisIndex, new StandardXYItemRenderer()); plot.setDataset(axisIndex, dataset); plot.mapDatasetToRangeAxis(axisIndex, axisIndex); } setXYSeriesAxisColors(chartAxisData, plot.getRenderer(axisIndex)); }
From source file:com.bdb.weather.display.day.DayPressurePane.java
@Override protected void addAnnotations(XYPlot plot, SummaryRecord summaryRecord) { plot.getRenderer(0).removeAnnotations(); plot.getRenderer(1).removeAnnotations(); if (summaryRecord == null) return;//from w ww . ja v a 2s.co m LocalDateTime maxTime = summaryRecord.getMaxBaroPressureTime(); Pressure maxBaroPressure = summaryRecord.getMaxBaroPressure(); LocalDateTime minTime = summaryRecord.getMinBaroPressureTime(); Pressure minBaroPressure = summaryRecord.getMinBaroPressure(); // // Barometric pressure // String highAnnotation = maxBaroPressure.toString() + Pressure.getDefaultUnit() + " " + DisplayConstants.formatTime(maxTime.toLocalTime()); String lowAnnotation = minBaroPressure.toString() + Pressure.getDefaultUnit() + " " + DisplayConstants.formatTime(minTime.toLocalTime()); XYTextAnnotation a = new XYTextAnnotation(highAnnotation, (double) TimeUtils.localDateTimeToEpochMillis(maxTime), maxBaroPressure.get()); a.setTextAnchor(TextAnchor.BASELINE_CENTER); plot.getRenderer(0).addAnnotation(a); TextAnchor anchor = TextAnchor.TOP_CENTER; if (minTime.getHour() <= 2) anchor = TextAnchor.TOP_LEFT; else if (minTime.getHour() >= 22) anchor = TextAnchor.TOP_RIGHT; a = new XYTextAnnotation(lowAnnotation, (double) TimeUtils.localDateTimeToEpochMillis(minTime), minBaroPressure.get()); a.setTextAnchor(anchor); plot.getRenderer(0).addAnnotation(a); SolarRadiation maxSolarRadiation = summaryRecord.getMaxSolarRadiation(); maxTime = summaryRecord.getMaxSolarRadiationTime(); if (maxSolarRadiation != null) { highAnnotation = maxSolarRadiation.toString() + SolarRadiation.Unit.WATTS_PER_METER_SQUARED + " " + DisplayConstants.formatTime(maxTime.toLocalTime()); a = new XYTextAnnotation(highAnnotation, (double) TimeUtils.localDateTimeToEpochMillis(maxTime), maxSolarRadiation.get()); a.setTextAnchor(TextAnchor.BASELINE_CENTER); plot.getRenderer(1).addAnnotation(a); } }
From source file:org.mwc.debrief.sensorfusion.views.MouseClickSolutionDemo.java
private void fixProblem(final XYPlot plot) { for (int i = 0; i < plot.getRendererCount(); i++) { final XYItemRenderer renderer = plot.getRenderer(i); final XYItemRenderer fixed = XYLineAndShapeRendererFix.newFixedVersion(renderer); if (renderer != fixed) { plot.setRenderer(i, fixed);/*w w w.j a va 2 s . co m*/ } } }
From source file:no.met.jtimeseries.netcdf.plot.SimplePlotProvider.java
/** * Add a single {@link GenericNumberPhenomenon} with the given color to the plot. *//*ww w . j av a 2 s . co m*/ private void addTimeSeries(XYPlot plot, NumberPhenomenon toAdd, int dataSetCount, Color color) { plot.setDataset(dataSetCount, getTimeSeries(toAdd)); plot.setRenderer(dataSetCount, new XYSplineRenderer()); plot.getRenderer(dataSetCount).setSeriesPaint(0, color); }
From source file:de.atomfrede.tools.evalutation.tools.plot.TimePlot.java
@Override protected JFreeChart createChart(XYDatasetWrapper... datasetWrappers) { XYDatasetWrapper mainDataset = datasetWrappers[0]; JFreeChart chart = ChartFactory.createTimeSeriesChart(mainDataset.getSeriesName(), "Time", mainDataset.getSeriesName(), mainDataset.getDataset(), true, true, false); XYPlot plot = (XYPlot) chart.getPlot(); // all adjustments for first/main dataset plot.getRangeAxis(0).setLowerBound(mainDataset.getMinimum()); plot.getRangeAxis(0).setUpperBound(mainDataset.getMaximum()); // some additional "design" stuff for the plot plot.getRenderer(0).setSeriesPaint(0, mainDataset.getSeriesColor()); plot.getRenderer(0).setSeriesStroke(0, new BasicStroke(mainDataset.getStroke())); for (int i = 1; i < datasetWrappers.length; i++) { XYDatasetWrapper wrapper = datasetWrappers[i]; plot.setDataset(i, wrapper.getDataset()); chart.setTitle(chart.getTitle().getText() + "/" + wrapper.getSeriesName()); NumberAxis axis = new NumberAxis(wrapper.getSeriesName()); plot.setRangeAxis(i, axis);/*from w w w. j a va 2 s . com*/ plot.setRangeAxisLocation(i, AxisLocation.BOTTOM_OR_RIGHT); plot.getRangeAxis(i).setLowerBound(wrapper.getMinimum() - 15.0); plot.getRangeAxis(i).setUpperBound(wrapper.getMaximum() + 15.0); // map the second dataset to the second axis plot.mapDatasetToRangeAxis(i, i); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); renderer.setBaseShapesVisible(false); renderer.setSeriesStroke(0, new BasicStroke(wrapper.getStroke())); plot.setRenderer(i, renderer); plot.getRenderer(i).setSeriesPaint(0, wrapper.getSeriesColor()); } // change the background and gridline colors plot.setBackgroundPaint(Color.white); plot.setDomainMinorGridlinePaint(Color.LIGHT_GRAY); plot.setDomainGridlinePaint(Color.LIGHT_GRAY); plot.setRangeGridlinePaint(Color.LIGHT_GRAY); // format the date axis DateAxis axis = (DateAxis) plot.getDomainAxis(); axis.setDateFormatOverride(new SimpleDateFormat("dd.MM HH:mm")); axis.setTickUnit(new DateTickUnit(DateTickUnitType.HOUR, 1)); axis.setVerticalTickLabels(true); return chart; }
From source file:de.atomfrede.tools.evalutation.tools.plot.custom.CustomSimplePlot.java
@Override protected JFreeChart createChart(XYDatasetWrapper... datasetWrappers) { XYDatasetWrapper mainDataset = datasetWrappers[0]; JFreeChart chart = ChartFactory.createXYLineChart(mainDataset.getSeriesName(), "Index", mainDataset.getSeriesName(), mainDataset.getDataset(), PlotOrientation.VERTICAL, true, false, false);//from w w w. j a v a 2 s . c om XYPlot plot = (XYPlot) chart.getPlot(); // all adjustments for first/main dataset plot.getRangeAxis(0).setLowerBound(mainDataset.getMinimum()); plot.getRangeAxis(0).setUpperBound(mainDataset.getMaximum()); // some additional "design" stuff for the plot plot.getRenderer(0).setSeriesPaint(0, mainDataset.getSeriesColor()); plot.getRenderer(0).setSeriesStroke(0, new BasicStroke(mainDataset.getStroke())); for (int i = 1; i < datasetWrappers.length; i++) { XYDatasetWrapper wrapper = datasetWrappers[i]; plot.setDataset(i, wrapper.getDataset()); chart.setTitle(chart.getTitle().getText() + "/" + wrapper.getSeriesName()); NumberAxis axis = new NumberAxis(wrapper.getSeriesName()); plot.setRangeAxis(i, axis); plot.setRangeAxisLocation(i, AxisLocation.BOTTOM_OR_RIGHT); plot.getRangeAxis(i).setLowerBound(wrapper.getMinimum() - 15.0); plot.getRangeAxis(i).setUpperBound(wrapper.getMaximum() + 15.0); // map the second dataset to the second axis plot.mapDatasetToRangeAxis(i, i); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); renderer.setBaseShapesVisible(false); renderer.setSeriesStroke(0, new BasicStroke(wrapper.getStroke())); plot.setRenderer(i, renderer); plot.getRenderer(i).setSeriesPaint(0, wrapper.getSeriesColor()); } // change the background and gridline colors plot.setBackgroundPaint(Color.white); plot.setDomainMinorGridlinePaint(Color.LIGHT_GRAY); plot.setDomainGridlinePaint(Color.LIGHT_GRAY); plot.setRangeGridlinePaint(Color.LIGHT_GRAY); return chart; }