[Schmitzm-commits] r488 - in branches/1.0-gt2-2.6/src/schmitzm/jfree: . chart/style
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Tue Oct 20 21:23:32 CEST 2009
Author: mojays
Date: 2009-10-20 21:23:31 +0200 (Tue, 20 Oct 2009)
New Revision: 488
Modified:
branches/1.0-gt2-2.6/src/schmitzm/jfree/JFreeChartUtil.java
branches/1.0-gt2-2.6/src/schmitzm/jfree/chart/style/ScatterChartStyle.java
Log:
BugFix: Errors on regression line calculation caught
Modified: branches/1.0-gt2-2.6/src/schmitzm/jfree/JFreeChartUtil.java
===================================================================
--- branches/1.0-gt2-2.6/src/schmitzm/jfree/JFreeChartUtil.java 2009-10-20 18:33:53 UTC (rev 487)
+++ branches/1.0-gt2-2.6/src/schmitzm/jfree/JFreeChartUtil.java 2009-10-20 19:23:31 UTC (rev 488)
@@ -474,7 +474,7 @@
}
/**
- * Creates a {@link JFreeChart} which shows a point for each data iten and
+ * Creates a {@link JFreeChart} which shows a point for each data item and
* a the appropriate regression line.
* @param dataset the data
* @param title title for the chart
@@ -505,21 +505,11 @@
if ( regressionLine) {
// only if there are at least 2 items, otherwise we would get a IllegalArgumentException
- if (((XYSeriesCollection)dataset).getItemCount(0)>=2) {
-
- //TODO Try Ctch.. /**
- /**
- * ERROR AtlasCreator uncaughtException An uncaught exception happened on Thread Thread[AWT-EventQueue-0,6,main]
-java.lang.IllegalArgumentException: Requires 'start' < 'end'.
- at org.jfree.data.general.DatasetUtilities.sampleFunction2DToSeries(DatasetUtilities.java:534)
- at org.jfree.data.general.DatasetUtilities.sampleFunction2D(DatasetUtilities.java:503)
- at schmitzm.jfree.JFreeChartUtil.createRegressionLineDataset(JFreeChartUtil.java:479)
- at schmitzm.jfree.JFreeChartUtil.createRegressionLineDataset(JFreeChartUtil.java:464)
- at schmitzm.jfree.JFreeChartUtil.createRegressionChart(JFreeChartUtil.java:443)
- */
- // create sample data for curve (plot function directly is not yet available)
- XYDataset regressionData = createRegressionLineDataset((XYSeriesCollection)dataset,0,title+" (RegressionLine)",2);
- addRegressionLineToPlot(plot, regressionData, Color.blue);
+ if ( ((XYSeriesCollection)dataset).getItemCount(0)>=2 ) {
+ // create sample data for curve (plot function directly is not yet available)
+ XYDataset regressionData = createRegressionLineDataset((XYSeriesCollection)dataset,0,title+" (RegressionLine)",2);
+ if ( regressionData != null )
+ addRegressionLineToPlot(plot, regressionData, Color.blue);
} else {
LOGGER.info("Not enought items in the series to create a regression line.");
}
@@ -550,11 +540,20 @@
* @param startX the first value the sample data is created for
* @param endX the last value the sample data is created for
* @param sampleCnt count of created samples
+ * @return {@code null} if the regression data could not be created (because of an
+ * error
*/
public static XYDataset createRegressionLineDataset(XYDataset dataset, int series, Comparable<?> seriesKey, double startX, double endX, int sampleCount) {
- double[] coefficients = Regression.getOLSRegression(dataset, series);
- Function2D curve = new LineFunction2D(coefficients[0], coefficients[1]);
- return DatasetUtilities.sampleFunction2D(curve, startX, endX, 2, seriesKey);
+ try {
+ double[] coefficients = Regression.getOLSRegression(dataset, series);
+ Function2D curve = new LineFunction2D(coefficients[0], coefficients[1]);
+ return DatasetUtilities.sampleFunction2D(curve, startX, endX, 2, seriesKey);
+ } catch (Exception err) {
+ // according to the data sometimes the regression
+ // dataset could not be created
+ LOGGER.warn("Regression line could not be created: "+err.getLocalizedMessage());
+ return null;
+ }
}
/**
Modified: branches/1.0-gt2-2.6/src/schmitzm/jfree/chart/style/ScatterChartStyle.java
===================================================================
--- branches/1.0-gt2-2.6/src/schmitzm/jfree/chart/style/ScatterChartStyle.java 2009-10-20 18:33:53 UTC (rev 487)
+++ branches/1.0-gt2-2.6/src/schmitzm/jfree/chart/style/ScatterChartStyle.java 2009-10-20 19:23:31 UTC (rev 488)
@@ -144,7 +144,8 @@
XYDataset regressionData = JFreeChartUtil.createRegressionLineDataset(
dataset, 0, regressionTitle, 2);
// Add regression line to plot (with default color)
- JFreeChartUtil.addRegressionLineToPlot(chart.getXYPlot(), regressionData, Color.blue);
+ if ( regressionData != null )
+ JFreeChartUtil.addRegressionLineToPlot(chart.getXYPlot(), regressionData, Color.blue);
}
// apply "normal" style properties
More information about the Schmitzm-commits
mailing list