List of usage examples for org.jfree.chart.renderer.xy XYErrorRenderer setDrawYError
public void setDrawYError(boolean draw)
From source file:graph.jfreecharts.GraphFunction.java
/** * A custom xyerror renderer because jfreecharts does not * have it supported in the api.//w w w.j a v a 2s . c o m * @param title the graph title * @param xAxisLabel the xaxis title * @param yAxisLabel the yaxis title * @param dataset the xydataset * @param orientation the plot orientation * @param legend true to turn on legend * @param tooltips true to turn on tooltips (the pop up when right click) * @param urls // no idea what this is for * @return */ private static JFreeChart createXYIntervalChart(String title, String xAxisLabel, String yAxisLabel, XYDataset dataset, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls) { if (orientation == null) { throw new IllegalArgumentException("Null 'orientation' argument."); } NumberAxis xAxis = new NumberAxis(xAxisLabel); xAxis.setAutoRangeIncludesZero(false); NumberAxis yAxis = new NumberAxis(yAxisLabel); XYErrorRenderer renderer = new XYErrorRenderer(); renderer.setDrawXError(true); renderer.setDrawYError(true); xAxis.setNumberFormatOverride(new DecimalFormat("0.######E0")); yAxis.setNumberFormatOverride(new DecimalFormat("0.######E0")); xAxis.setAutoRangeIncludesZero(false); yAxis.setAutoRangeIncludesZero(false); XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer); plot.setOrientation(orientation); if (tooltips) { renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator()); } if (urls) { renderer.setURLGenerator(new StandardXYURLGenerator()); } JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend); currentTheme.apply(chart); return chart; }
From source file:org.gumtree.vis.plot1d.Plot1D.java
/** * Creates a line chart (based on an {@link XYDataset}) with default * settings./* w w w .ja va 2 s . c o m*/ * * @param title the chart title (<code>null</code> permitted). * @param xAxisLabel a label for the X-axis (<code>null</code> permitted). * @param yAxisLabel a label for the Y-axis (<code>null</code> permitted). * @param dataset the dataset for the chart (<code>null</code> permitted). * @param orientation the plot orientation (horizontal or vertical) * (<code>null</code> NOT permitted). * @param legend a flag specifying whether or not a legend is required. * @param tooltips configure chart to generate tool tips? * @param urls configure chart to generate URLs? * * @return The chart. */ public static JFreeChart createXYLineChart(String title, String xAxisLabel, String yAxisLabel, XYDataset dataset, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls) { if (orientation == null) { throw new IllegalArgumentException("Null 'orientation' argument."); } // NumberAxis xAxis = new NumberAxis(xAxisLabel); LogarithmizableAxis xAxis = new LogarithmizableAxis(xAxisLabel); xAxis.setLogarithmic(false); xAxis.setAutoRangeIncludesZero(false); xAxis.setAllowNegativesFlag(true); xAxis.setLowerMargin(0.02); xAxis.setUpperMargin(0.02); // NumberAxis yAxis = new NumberAxis(yAxisLabel); LogarithmizableAxis yAxis = new LogarithmizableAxis(yAxisLabel); yAxis.setAllowNegativesFlag(true); yAxis.setAutoRangeNextLogFlag(false); yAxis.setLowerMargin(0.02); yAxis.setUpperMargin(0.02); yAxis.setLogarithmic(false); XYErrorRenderer renderer = new XYErrorRenderer(); renderer.setBaseLinesVisible(true); renderer.setBaseShapesVisible(false); renderer.setDrawYError(true); // XYItemRenderer renderer = new XYLineAndShapeRenderer(true, false); XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer); plot.setOrientation(orientation); if (tooltips) { renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator()); } if (urls) { renderer.setURLGenerator(new StandardXYURLGenerator()); } JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend); chartTheme.apply(chart); return chart; }
From source file:org.gumtree.vis.awt.PlotFactory.java
/** * Creates a line chart (based on an {@link XYDataset}) with default * settings.//w w w . j a v a 2 s . c o m * * @param title the chart title (<code>null</code> permitted). * @param xAxisLabel a label for the X-axis (<code>null</code> permitted). * @param yAxisLabel a label for the Y-axis (<code>null</code> permitted). * @param dataset the dataset for the chart (<code>null</code> permitted). * @param orientation the plot orientation (horizontal or vertical) * (<code>null</code> NOT permitted). * @param legend a flag specifying whether or not a legend is required. * @param tooltips configure chart to generate tool tips? * @param urls configure chart to generate URLs? * * @return The chart. */ protected static JFreeChart createXYLineChart(String title, String xAxisLabel, String yAxisLabel, XYDataset dataset, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls) { if (orientation == null) { throw new IllegalArgumentException("Null 'orientation' argument."); } // NumberAxis xAxis = new NumberAxis(xAxisLabel); LogarithmizableAxis xAxis = new LogarithmizableAxis(xAxisLabel); boolean isLogX = false; try { isLogX = Boolean.valueOf(System.getProperty(LOGX_PROPERTY)); } catch (Exception e) { } xAxis.setLogarithmic(isLogX); // xAxis.setAutoRangeIncludesZero(false); xAxis.setAllowNegativesFlag(true); xAxis.setLowerMargin(0.02); xAxis.setUpperMargin(0.02); // NumberAxis yAxis = new NumberAxis(yAxisLabel); LogarithmizableAxis yAxis = new LogarithmizableAxis(yAxisLabel); boolean isLogY = false; try { isLogY = Boolean.valueOf(System.getProperty(LOGY_PROPERTY)); } catch (Exception e) { } yAxis.setLogarithmic(isLogY); yAxis.setAllowNegativesFlag(true); yAxis.setAutoRangeNextLogFlag(false); yAxis.setLowerMargin(0.02); yAxis.setUpperMargin(0.02); XYErrorRenderer renderer = new XYErrorRenderer(); renderer.setBaseLinesVisible(true); renderer.setBaseShapesVisible(false); renderer.setDrawYError(true); // XYItemRenderer renderer = new XYLineAndShapeRenderer(true, false); XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer); plot.setOrientation(orientation); if (tooltips) { renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator()); } if (urls) { renderer.setURLGenerator(new StandardXYURLGenerator()); } JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend); chartTheme.apply(chart); return chart; }
From source file:org.esa.beam.timeseries.ui.graph.TimeSeriesGraphModel.java
private XYErrorRenderer createXYErrorRenderer() { final XYErrorRenderer renderer = new XYErrorRenderer(); renderer.setDrawXError(false);// ww w. j ava2 s .com renderer.setDrawYError(false); renderer.setBaseLinesVisible(true); renderer.setAutoPopulateSeriesStroke(false); renderer.setAutoPopulateSeriesPaint(false); renderer.setAutoPopulateSeriesFillPaint(false); renderer.setAutoPopulateSeriesOutlinePaint(false); renderer.setAutoPopulateSeriesOutlineStroke(false); renderer.setAutoPopulateSeriesShape(false); final StandardXYToolTipGenerator tipGenerator; tipGenerator = new StandardXYToolTipGenerator("Value: {2} Date: {1}", new SimpleDateFormat(), new DecimalFormat()); renderer.setBaseToolTipGenerator(tipGenerator); return renderer; }
From source file:weka.classifiers.timeseries.eval.graph.JFreeChartDriver.java
protected JFreeChart getPredictedTargetsChart(TSForecaster forecaster, ErrorModule preds, List<String> targetNames, int stepNumber, int instanceNumOffset, Instances data) { if (forecaster instanceof TSLagUser && data != null) { TSLagMaker lagMaker = ((TSLagUser) forecaster).getTSLagMaker(); if (lagMaker.getAdjustForTrends() && !lagMaker.isUsingAnArtificialTimeIndex()) { // fill in any missing time stamps only data = new Instances(data); data = weka.classifiers.timeseries.core.Utils.replaceMissing(data, null, lagMaker.getTimeStampField(), true, lagMaker.getPeriodicity(), lagMaker.getSkipEntries()); }/* www . j ava 2 s . c om*/ } // set up a collection of predicted and actual series XYIntervalSeriesCollection xyDataset = new XYIntervalSeriesCollection(); for (String target : targetNames) { XYIntervalSeries targetSeries = new XYIntervalSeries(target + "-actual", false, false); xyDataset.addSeries(targetSeries); targetSeries = new XYIntervalSeries(target + "-predicted", false, false); xyDataset.addSeries(targetSeries); } ValueAxis timeAxis = null; NumberAxis valueAxis = new NumberAxis(""); valueAxis.setAutoRangeIncludesZero(false); int timeIndex = -1; boolean timeAxisIsDate = false; if (forecaster instanceof TSLagUser && data != null) { TSLagMaker lagMaker = ((TSLagUser) forecaster).getTSLagMaker(); if (!lagMaker.isUsingAnArtificialTimeIndex() && lagMaker.getAdjustForTrends()) { String timeName = lagMaker.getTimeStampField(); if (data.attribute(timeName).isDate()) { timeAxis = new DateAxis(""); timeAxisIsDate = true; timeIndex = data.attribute(timeName).index(); } } } if (timeAxis == null) { timeAxis = new NumberAxis(""); ((NumberAxis) timeAxis).setAutoRangeIncludesZero(false); } // now populate the series boolean hasConfidenceIntervals = false; for (int i = 0; i < targetNames.size(); i++) { String targetName = targetNames.get(i); List<NumericPrediction> predsForI = preds.getPredictionsForTarget(targetName); int predIndex = xyDataset.indexOf(targetName + "-predicted"); int actualIndex = xyDataset.indexOf(targetName + "-actual"); XYIntervalSeries predSeries = xyDataset.getSeries(predIndex); XYIntervalSeries actualSeries = xyDataset.getSeries(actualIndex); for (int j = 0; j < predsForI.size(); j++) { double x = Utils.missingValue(); if (timeAxisIsDate) { if (instanceNumOffset + j + stepNumber - 1 < data.numInstances()) { x = data.instance(instanceNumOffset + j + stepNumber - 1).value(timeIndex); } } else { x = instanceNumOffset + j + stepNumber; } double yPredicted = predsForI.get(j).predicted(); double yHigh = yPredicted; double yLow = yPredicted; double[][] conf = predsForI.get(j).predictionIntervals(); if (conf.length > 0) { yLow = conf[0][0]; yHigh = conf[0][1]; hasConfidenceIntervals = true; } if (!Utils.isMissingValue(x) && !Utils.isMissingValue(yPredicted)) { if (predSeries != null) { predSeries.add(x, x, x, yPredicted, yLow, yHigh); } // System.err.println("* " + yPredicted + " " + x); } double yActual = predsForI.get(j).actual(); if (!Utils.isMissingValue(x) && !Utils.isMissingValue(yActual)) { if (actualSeries != null) { actualSeries.add(x, x, x, yActual, yActual, yActual); } } } } // set up the chart String title = "" + stepNumber + " step-ahead predictions for: "; for (String s : targetNames) { title += s + ","; } title = title.substring(0, title.lastIndexOf(",")); /* * String algoSpec = forecaster.getAlgorithmName(); title += " (" + algoSpec * + ")"; */ if (forecaster instanceof WekaForecaster && hasConfidenceIntervals) { double confPerc = ((WekaForecaster) forecaster).getConfidenceLevel() * 100.0; title += " [" + Utils.doubleToString(confPerc, 0) + "% conf. intervals]"; } XYErrorRenderer renderer = new XYErrorRenderer(); renderer.setBaseLinesVisible(true); renderer.setDrawXError(false); renderer.setDrawYError(true); // renderer.setShapesFilled(true); XYPlot plot = new XYPlot(xyDataset, timeAxis, valueAxis, renderer); JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, true); chart.setBackgroundPaint(java.awt.Color.white); TextTitle chartTitle = chart.getTitle(); String fontName = chartTitle.getFont().getFontName(); java.awt.Font newFont = new java.awt.Font(fontName, java.awt.Font.PLAIN, 12); chartTitle.setFont(newFont); return chart; }
From source file:weka.classifiers.timeseries.eval.graph.JFreeChartDriver.java
protected JFreeChart getFutureForecastChart(TSForecaster forecaster, List<List<NumericPrediction>> preds, List<String> targetNames, Instances history) { if (forecaster instanceof TSLagUser && history != null) { TSLagMaker lagMaker = ((TSLagUser) forecaster).getTSLagMaker(); if (lagMaker.getAdjustForTrends() && !lagMaker.isUsingAnArtificialTimeIndex()) { // fill in any missing time stamps only history = new Instances(history); history = weka.classifiers.timeseries.core.Utils.replaceMissing(history, null, lagMaker.getTimeStampField(), true, lagMaker.getPeriodicity(), lagMaker.getSkipEntries()); }//ww w . j av a 2 s . co m } // set up a collection of series XYIntervalSeriesCollection xyDataset = new XYIntervalSeriesCollection(); if (history != null) { // add actual historical data values for (String targetName : targetNames) { XYIntervalSeries targetSeries = new XYIntervalSeries(targetName, false, false); xyDataset.addSeries(targetSeries); } } // add predicted series for (String targetName : targetNames) { XYIntervalSeries targetSeries = new XYIntervalSeries(targetName + "-predicted", false, false); xyDataset.addSeries(targetSeries); } ValueAxis timeAxis = null; NumberAxis valueAxis = new NumberAxis(""); valueAxis.setAutoRangeIncludesZero(false); int timeIndex = -1; boolean timeAxisIsDate = false; double artificialTimeStart = 0; double lastRealTimeValue = Utils.missingValue(); if (forecaster instanceof TSLagUser && history != null) { TSLagMaker lagMaker = ((TSLagUser) forecaster).getTSLagMaker(); if (!lagMaker.isUsingAnArtificialTimeIndex() && lagMaker.getAdjustForTrends()) { String timeName = lagMaker.getTimeStampField(); if (history.attribute(timeName).isDate()) { timeAxis = new DateAxis(""); timeAxisIsDate = true; timeIndex = history.attribute(timeName).index(); } } else { try { artificialTimeStart = (history != null) ? 1 : lagMaker.getArtificialTimeStartValue() + 1; } catch (Exception ex) { } } } if (timeAxis == null) { timeAxis = new NumberAxis(""); ((NumberAxis) timeAxis).setAutoRangeIncludesZero(false); } boolean hasConfidenceIntervals = false; // now populate the series if (history != null) { // do the actuals first for (int i = 0; i < history.numInstances(); i++) { Instance current = history.instance(i); for (String targetName : targetNames) { int dataIndex = history.attribute(targetName.trim()).index(); if (dataIndex >= 0) { XYIntervalSeries actualSeries = null; int actualIndex = xyDataset.indexOf(targetName); actualSeries = xyDataset.getSeries(actualIndex); double x = Utils.missingValue(); if (timeAxisIsDate) { x = current.value(timeIndex); if (!Utils.isMissingValue(x)) { lastRealTimeValue = x; } } else { x = artificialTimeStart; } double y = Utils.missingValue(); y = current.value(dataIndex); if (!Utils.isMissingValue(x) && !Utils.isMissingValue(y)) { if (actualSeries != null) { actualSeries.add(x, x, x, y, y, y); } } } } if (!timeAxisIsDate) { artificialTimeStart++; } } } // now do the futures List<String> forecasterTargets = AbstractForecaster.stringToList(forecaster.getFieldsToForecast()); // loop over the steps for (int j = 0; j < preds.size(); j++) { List<NumericPrediction> predsForStepJ = preds.get(j); // advance the real time index (if appropriate) if (timeAxisIsDate) { lastRealTimeValue = ((TSLagUser) forecaster).getTSLagMaker() .advanceSuppliedTimeValue(lastRealTimeValue); } for (String targetName : targetNames) { // look up this requested target in the list that the forecaster // has predicted int predIndex = forecasterTargets.indexOf(targetName.trim()); if (predIndex >= 0) { NumericPrediction predsForTargetAtStepJ = predsForStepJ.get(predIndex); XYIntervalSeries predSeries = null; int datasetIndex = xyDataset.indexOf(targetName + "-predicted"); predSeries = xyDataset.getSeries(datasetIndex); if (predSeries != null) { double y = predsForTargetAtStepJ.predicted(); double x = Utils.missingValue(); double yHigh = y; double yLow = y; double[][] conf = predsForTargetAtStepJ.predictionIntervals(); if (conf.length > 0) { yLow = conf[0][0]; yHigh = conf[0][1]; hasConfidenceIntervals = true; } if (!timeAxisIsDate) { x = artificialTimeStart; } else { x = lastRealTimeValue; } if (!Utils.isMissingValue(x) && !Utils.isMissingValue(y)) { predSeries.add(x, x, x, y, yLow, yHigh); } } } } // advance the artificial time index (if appropriate) if (!timeAxisIsDate) { artificialTimeStart++; } } String title = "Future forecast for: "; for (String s : targetNames) { title += s + ","; } title = title.substring(0, title.lastIndexOf(",")); /* * String algoSpec = forecaster.getAlgorithmName(); title += " (" + algoSpec * + ")"; */ if (forecaster instanceof WekaForecaster && hasConfidenceIntervals) { double confPerc = ((WekaForecaster) forecaster).getConfidenceLevel() * 100.0; title += " [" + Utils.doubleToString(confPerc, 0) + "% conf. intervals]"; } XYErrorRenderer renderer = new XYErrorRenderer(); // renderer.setShapesFilled(true); XYPlot plot = new XYPlot(xyDataset, timeAxis, valueAxis, renderer); // renderer = (XYErrorRenderer)plot.getRenderer(); if (history != null) { for (String targetName : targetNames) { XYIntervalSeries predSeries = null; int predIndex = xyDataset.indexOf(targetName + "-predicted"); predSeries = xyDataset.getSeries(predIndex); XYIntervalSeries actualSeries = null; int actualIndex = xyDataset.indexOf(targetName); actualSeries = xyDataset.getSeries(actualIndex); if (actualSeries != null && predSeries != null) { // match the color of the actual series java.awt.Paint actualPaint = renderer.lookupSeriesPaint(actualIndex); renderer.setSeriesPaint(predIndex, actualPaint); // now set the line style to dashed BasicStroke dashed = new BasicStroke(1.5f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, new float[] { 5.0f }, 0.0f); renderer.setSeriesStroke(predIndex, dashed); } } } renderer.setBaseLinesVisible(true); renderer.setDrawXError(false); renderer.setDrawYError(true); JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, true); chart.setBackgroundPaint(java.awt.Color.white); TextTitle chartTitle = chart.getTitle(); String fontName = chartTitle.getFont().getFontName(); java.awt.Font newFont = new java.awt.Font(fontName, java.awt.Font.PLAIN, 12); chartTitle.setFont(newFont); return chart; }