Index: branches/HeuristicLab.RegressionSolutionGradientView/HeuristicLab.Problems.DataAnalysis.Views/3.4/GradientChart.cs
===================================================================
--- branches/HeuristicLab.RegressionSolutionGradientView/HeuristicLab.Problems.DataAnalysis.Views/3.4/GradientChart.cs	(revision 13825)
+++ branches/HeuristicLab.RegressionSolutionGradientView/HeuristicLab.Problems.DataAnalysis.Views/3.4/GradientChart.cs	(revision 13829)
@@ -32,5 +32,6 @@
 namespace HeuristicLab.Problems.DataAnalysis.Views {
   public partial class GradientChart : EnhancedChart {
-    private ModifiableDataset dataset;
+    private ModifiableDataset sharedDataset; // used for syncronising variable values between charts
+    private ModifiableDataset internalDataset; // used to cache values and speed up calculations
 
     public bool ShowLegend { get; set; }
@@ -191,24 +192,46 @@
       this.problemData = pd;
       this.variable = variable;
-      this.dataset = dataset;
+      this.sharedDataset = dataset;
       this.min = min;
       this.max = max;
       this.points = points;
+
+      // add an event such that whenever a value is changed in the shared dataset, 
+      // this change is reflected in the internal dataset (where the value becomes a whole column)
+      var variables = sharedDataset.DoubleVariables.ToList();
+      sharedDataset.ItemChanged += (o, e) => {
+        var rowIndex = e.Value;
+        var columnIndex = e.Value2;
+        var ds = (ModifiableDataset)o;
+        var variableName = variables[columnIndex];
+        if (variableName == Variable) return;
+        var v = ds.GetDoubleValue(variableName, rowIndex);
+        var values = new List<double>(Enumerable.Repeat(v, Points));
+        internalDataset.ReplaceVariable(variableName, values);
+      };
+
+      // configure internal dataset. we also expand the range in order to get nice tick intervals on the x axis
+      const int tics = 5;
+      double xmin, xmax, xinterval;
+      ChartUtil.CalculateAxisInterval(min, max, tics, out xmin, out xmax, out xinterval);
+      var step = (xmax - xmin) / points;
+      var xvalues = new List<double>();
+      for (int i = 0; i < points; ++i) { xvalues.Add(xmin + i * step); }
+      internalDataset = new ModifiableDataset(variables, variables.Select(x => x == Variable ? xvalues : new List<double>(Enumerable.Repeat(sharedDataset.GetDoubleValue(x, 0), xvalues.Count))));
     }
 
     public void UpdateChart() {
       // throw exceptions?
-      if (dataset == null || solutionList == null || !solutionList.Any())
+      if (sharedDataset == null || solutionList == null || !solutionList.Any())
         return;
       if (min.IsAlmost(max) || min > max || points == 0)
         return;
       Series.Clear();
-
-      var defaultValue = dataset.GetDoubleValue(variable, 0);
       var vla = VerticalLineAnnotation;
+      Annotations.Clear();
+      var defaultValue = sharedDataset.GetDoubleValue(variable, 0);
+      vla.Visible = ShowCursor;
+      Annotations.Add(vla);
       vla.X = defaultValue;
-      vla.Visible = ShowCursor;
-      Annotations.Clear();
-      Annotations.Add(vla);
 
       double axisMin, axisMax, axisInterval;
@@ -262,45 +285,20 @@
         }
       }
-      dataset = new ModifiableDataset(variables, variableValues);
-    }
-
-    private double GetEstimatedValue(IRegressionSolution solution, double x) {
-      var v = dataset.GetDoubleValue(Variable, 0);
-      dataset.SetVariableValue(x, Variable, 0);
-      var y = solution.Model.GetEstimatedValues(dataset, new[] { 0 }).Single();
-      dataset.SetVariableValue(v, Variable, 0);
-      return y;
+      sharedDataset = new ModifiableDataset(variables, variableValues);
     }
 
     private Series PlotSeries(IRegressionSolution solution) {
-      var v = dataset.GetDoubleValue(variable, 0);
+      var v = sharedDataset.GetDoubleValue(variable, 0);
       var series = new Series { ChartType = SeriesChartType.Point };
-
-      var step = (max - min) / points;
-      var axisX = ChartAreas[0].AxisX;
-      if (ShowXAxisLabel) {
-        axisX.Title = Variable + " : " + v.ToString("N3", CultureInfo.CurrentCulture);
-      }
-      var axisY = ChartAreas[0].AxisY;
-      if (ShowYAxisLabel) { axisY.Title = Target; }
-      double y;
-      // lefthand section outside of the training range
-      for (double x = axisX.Minimum; x < min; x += step) {
-        y = GetEstimatedValue(solution, x);
-        series.Points.Add(new DataPoint(x, y) { MarkerSize = 2, MarkerColor = Color.Orange });
-      }
-      // points in the trainig range
-      for (double x = min; x < max; x += step) {
-        y = GetEstimatedValue(solution, x);
-        series.Points.Add(new DataPoint(x, y) { MarkerSize = 2 });
-      }
-      // righthand section outside of the training range
-      for (double x = max; x < axisX.Maximum; x += step) {
-        y = GetEstimatedValue(solution, x);
-        series.Points.Add(new DataPoint(x, y) { MarkerSize = 2, MarkerColor = Color.Orange });
-      }
-
+      // get values from series
+      var xvalues = internalDataset.GetReadOnlyDoubleValues(Variable);
+      var yvalues = solution.Model.GetEstimatedValues(internalDataset, Enumerable.Range(0, internalDataset.Rows));
+      int i = 0;
+      foreach (var y in yvalues) {
+        var x = xvalues[i++];
+        series.Points.Add(new DataPoint(x, y) { MarkerSize = 2, MarkerColor = Color.DodgerBlue });
+      }
       if (ShowCursor) {
-        y = GetEstimatedValue(solution, v);
+        var y = solution.Model.GetEstimatedValues(sharedDataset, new[] { 0 }).Single();
         series.Points.Add(new DataPoint(v, y) { MarkerSize = 5, MarkerColor = Color.Red });
       }
@@ -308,5 +306,4 @@
         series.IsVisibleInLegend = true;
       }
-
       return series;
     }
@@ -355,7 +352,7 @@
       var annotation = VerticalLineAnnotation;
       var x = annotation.X;
-      dataset.SetVariableValue(x, Variable, 0);
+      sharedDataset.SetVariableValue(x, Variable, 0);
       for (int i = 0; i < solutionList.Count; ++i) {
-        var y = GetEstimatedValue(solutionList[i], x);
+        var y = solutionList[i].Model.GetEstimatedValues(sharedDataset, new[] { 0 }).Single();
         var s = Series[i];
         var n = s.Points.Count;
