List of usage examples for org.jfree.chart.renderer.xy XYErrorRenderer setBaseLinesVisible
public void setBaseLinesVisible(boolean flag)
From source file:org.jfree.chart.demo.XYErrorRendererDemo2.java
private static JFreeChart createChart(IntervalXYDataset intervalxydataset) { NumberAxis numberaxis = new NumberAxis("X"); NumberAxis numberaxis1 = new NumberAxis("Y"); XYErrorRenderer xyerrorrenderer = new XYErrorRenderer(); xyerrorrenderer.setBaseLinesVisible(true); xyerrorrenderer.setBaseShapesVisible(false); XYPlot xyplot = new XYPlot(intervalxydataset, numberaxis, numberaxis1, xyerrorrenderer); xyplot.setBackgroundPaint(Color.lightGray); xyplot.setDomainGridlinePaint(Color.white); xyplot.setRangeGridlinePaint(Color.white); JFreeChart jfreechart = new JFreeChart("XYErrorRenderer Demo 2", xyplot); jfreechart.setBackgroundPaint(Color.white); return jfreechart; }
From source file:org.jfree.chart.demo.YIntervalChartDemo2.java
private static JFreeChart createChart(IntervalXYDataset intervalxydataset) { JFreeChart jfreechart = ChartFactory.createXYLineChart("YIntervalChartDemo2", "Date", "Value", intervalxydataset, PlotOrientation.VERTICAL, true, true, false); XYPlot xyplot = (XYPlot) jfreechart.getPlot(); xyplot.setDomainPannable(true);//from ww w. j a va 2s.c o m xyplot.setRangePannable(true); xyplot.setDomainAxis(new DateAxis("Date")); NumberAxis numberaxis = (NumberAxis) xyplot.getRangeAxis(); numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); numberaxis.setAutoRangeIncludesZero(false); XYErrorRenderer xyerrorrenderer = new XYErrorRenderer(); xyerrorrenderer.setBaseLinesVisible(true); xyerrorrenderer.setUseFillPaint(true); xyerrorrenderer.setBaseFillPaint(Color.white); xyplot.setRenderer(xyerrorrenderer); ChartUtilities.applyCurrentTheme(jfreechart); return jfreechart; }
From source file:org.gumtree.vis.plot1d.Plot1D.java
/** * Creates a line chart (based on an {@link XYDataset}) with default * settings.//w w w. j a va2s . com * * @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./*from w w w . j av 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);/*from ww w.j ava 2 s . c o m*/ 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:org.esa.beam.timeseries.ui.graph.TimeSeriesGraphModel.java
private void updatePlot(boolean hasData) { for (int i = 0; i < timeSeriesPlot.getDatasetCount(); i++) { timeSeriesPlot.setDataset(i, null); }// www. ja v a 2 s .co m timeSeriesPlot.clearRangeAxes(); if (!hasData) { return; } paintMap.clear(); final Set<String> aliasNamesSet = displayAxisMapping.getAliasNames(); final String[] aliasNames = aliasNamesSet.toArray(new String[aliasNamesSet.size()]); for (String aliasName : aliasNamesSet) { consumeColors(aliasName, displayAxisMapping.getRasterNames(aliasName), QUALIFIER_RASTER); consumeColors(aliasName, displayAxisMapping.getInsituNames(aliasName), QUALIFIER_INSITU); } for (int aliasIdx = 0; aliasIdx < aliasNames.length; aliasIdx++) { String aliasName = aliasNames[aliasIdx]; timeSeriesPlot.setRangeAxis(aliasIdx, createValueAxis(aliasName)); final int aliasIndexOffset = aliasIdx * 3; final int cursorCollectionIndex = aliasIndexOffset + CURSOR_COLLECTION_INDEX_OFFSET; final int pinCollectionIndex = aliasIndexOffset + PIN_COLLECTION_INDEX_OFFSET; final int insituCollectionIndex = aliasIndexOffset + INSITU_COLLECTION_INDEX_OFFSET; TimeSeriesCollection cursorDataset = new TimeSeriesCollection(); timeSeriesPlot.setDataset(cursorCollectionIndex, cursorDataset); TimeSeriesCollection pinDataset = new TimeSeriesCollection(); timeSeriesPlot.setDataset(pinCollectionIndex, pinDataset); TimeSeriesCollection insituDataset = new TimeSeriesCollection(); timeSeriesPlot.setDataset(insituCollectionIndex, insituDataset); timeSeriesPlot.mapDatasetToRangeAxis(cursorCollectionIndex, aliasIdx); timeSeriesPlot.mapDatasetToRangeAxis(pinCollectionIndex, aliasIdx); timeSeriesPlot.mapDatasetToRangeAxis(insituCollectionIndex, aliasIdx); final XYErrorRenderer pinRenderer = createXYErrorRenderer(); final XYErrorRenderer cursorRenderer = createXYErrorRenderer(); final XYErrorRenderer insituRenderer = createXYErrorRenderer(); pinRenderer.setBaseStroke(PIN_STROKE); cursorRenderer.setBaseStroke(CURSOR_STROKE); insituRenderer.setBaseLinesVisible(false); insituRenderer.setBaseShapesFilled(false); final List<String> rasterNamesSet = displayAxisMapping.getRasterNames(aliasName); final String[] rasterNames = rasterNamesSet.toArray(new String[rasterNamesSet.size()]); for (int i = 0; i < rasterNames.length; i++) { final String paintKey = aliasName + QUALIFIER_RASTER + rasterNames[i]; final Paint paint = paintMap.get(paintKey); cursorRenderer.setSeriesPaint(i, paint); pinRenderer.setSeriesPaint(i, paint); } final List<String> insituNamesSet = displayAxisMapping.getInsituNames(aliasName); final String[] insituNames = insituNamesSet.toArray(new String[insituNamesSet.size()]); for (int i = 0; i < insituNames.length; i++) { final String paintKey = aliasName + QUALIFIER_INSITU + insituNames[i]; final Paint paint = paintMap.get(paintKey); insituRenderer.setSeriesPaint(i, paint); } timeSeriesPlot.setRenderer(cursorCollectionIndex, cursorRenderer); timeSeriesPlot.setRenderer(pinCollectionIndex, pinRenderer); timeSeriesPlot.setRenderer(insituCollectionIndex, insituRenderer); } }
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()); }//from ww w. j a v a 2 s. com } // 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 getPredictedStepsChart(TSForecaster forecaster, List<ErrorModule> preds, String targetName, List<Integer> stepsToPlot, 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()); }/*from ww w . ja v a 2 s .c o m*/ } // set up a collection of predicted series XYIntervalSeriesCollection xyDataset = new XYIntervalSeriesCollection(); XYIntervalSeries targetSeries = new XYIntervalSeries(targetName, false, false); xyDataset.addSeries(targetSeries); // for (int i = 0; i < preds.size(); i++) { for (int z = 0; z < stepsToPlot.size(); z++) { int i = stepsToPlot.get(z); i--; // ignore out of range steps if (i < 0 || i >= preds.size()) { continue; } String step = "-steps"; if (i == 0) { step = "-step"; } targetSeries = new XYIntervalSeries(targetName + "_" + (i + 1) + step + "-ahead", 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 // for (int i = 0; i < preds.size(); i++) { boolean doneActual = false; boolean hasConfidenceIntervals = false; for (int z = 0; z < stepsToPlot.size(); z++) { int i = stepsToPlot.get(z); i--; // ignore out of range steps if (i < 0 || i >= preds.size()) { continue; } ErrorModule predsForStepI = preds.get(i); List<NumericPrediction> predsForTargetAtI = predsForStepI.getPredictionsForTarget(targetName); String step = "-steps"; if (i == 0) { step = "-step"; } int predIndex = xyDataset.indexOf(targetName + "_" + (i + 1) + step + "-ahead"); XYIntervalSeries predSeries = xyDataset.getSeries(predIndex); XYIntervalSeries actualSeries = null; if (!doneActual) { int actualIndex = xyDataset.indexOf(targetName); actualSeries = xyDataset.getSeries(actualIndex); } for (int j = 0; j < predsForTargetAtI.size(); j++) { double x = Utils.missingValue(); if (timeAxisIsDate) { if (instanceNumOffset + j + i < data.numInstances()) { x = data.instance(instanceNumOffset + j + i).value(timeIndex); } } else { x = instanceNumOffset + j + i; } double yPredicted = predsForTargetAtI.get(j).predicted(); double yHigh = yPredicted; double yLow = yPredicted; double[][] conf = predsForTargetAtI.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); } if (!doneActual && actualSeries != null) { double yActual = predsForTargetAtI.get(j).actual(); if (!Utils.isMissingValue(x) && !Utils.isMissingValue(yActual)) { actualSeries.add(x, x, x, yActual, yActual, yActual); } } } if (actualSeries != null) { doneActual = true; } } // set up the chart String title = ""; for (int i : stepsToPlot) { title += i + ","; } title = title.substring(0, title.lastIndexOf(",")); title += " step-ahead predictions for " + targetName; /* * 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.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()); }/*from ww w. ja v 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; }