Index: branches/HeuristicLab.RegressionSolutionGradientView/HeuristicLab.Problems.DataAnalysis.Views/3.4/GradientChart.cs
===================================================================
--- branches/HeuristicLab.RegressionSolutionGradientView/HeuristicLab.Problems.DataAnalysis.Views/3.4/GradientChart.cs	(revision 13836)
+++ branches/HeuristicLab.RegressionSolutionGradientView/HeuristicLab.Problems.DataAnalysis.Views/3.4/GradientChart.cs	(revision 13837)
@@ -25,4 +25,5 @@
 using System.Globalization;
 using System.Linq;
+using System.Threading.Tasks;
 using System.Windows.Forms;
 using System.Windows.Forms.DataVisualization.Charting;
@@ -34,5 +35,5 @@
   public partial class GradientChart : UserControl {
     private ModifiableDataset sharedFixedVariables; // used for syncronising variable values between charts
-    private ModifiableDataset internalDataset; // used to cache values and speed up calculations
+    private ModifiableDataset internalDataset; // holds the x values for each point drawn
 
     public bool ShowLegend {
@@ -56,10 +57,10 @@
     public int XAxisTicks {
       get { return xAxisTicks; }
-      set { if (xAxisTicks != value) { xAxisTicks = value; UpdateChart(); } }
+      set { if (xAxisTicks != value) { xAxisTicks = value; UpdateChartAsync(); } }
     }
     private int yAxisTicks = 5;
     public int YXAxisTicks {
       get { return yAxisTicks; }
-      set { if (yAxisTicks != value) { yAxisTicks = value; UpdateChart(); } }
+      set { if (yAxisTicks != value) { yAxisTicks = value; UpdateChartAsync(); } }
     }
 
@@ -67,10 +68,10 @@
     public double TrainingMin {
       get { return trainingMin; }
-      set { if (!value.IsAlmost(trainingMin)) { trainingMin = value; UpdateChart(); } }
+      set { if (!value.IsAlmost(trainingMin)) { trainingMin = value; UpdateChartAsync(); } }
     }
     private double trainingMax = double.MaxValue;
     public double TrainingMax {
       get { return trainingMax; }
-      set { if (!value.IsAlmost(trainingMax)) { trainingMax = value; UpdateChart(); } }
+      set { if (!value.IsAlmost(trainingMax)) { trainingMax = value; UpdateChartAsync(); } }
     }
 
@@ -78,5 +79,5 @@
     public int DrawingSteps {
       get { return drawingSteps; }
-      set { if (value != drawingSteps) { drawingSteps = value; UpdateChart(); } }
+      set { if (value != drawingSteps) { drawingSteps = value; UpdateChartAsync(); } }
     }
 
@@ -91,12 +92,6 @@
         freeVariable = value;
         RecalculateInternalDataset();
-        UpdateChart();
-      }
-    }
-
-    private bool updateChartAutomatically = false;
-    public bool UpdateChartAutomatically {
-      get { return updateChartAutomatically; }
-      set { updateChartAutomatically = value; if (updateChartAutomatically) UpdateChart(); }
+        UpdateChartAsync();
+      }
     }
 
@@ -139,12 +134,10 @@
       this.sharedFixedVariables.ItemChanged += sharedFixedVariables_ItemChanged;
 
-      trainingMin = solutions.Select(s => s.ProblemData.Dataset.GetDoubleValues(freeVariable, s.ProblemData.TrainingIndices).Min()).Max();
-      trainingMax = solutions.Select(s => s.ProblemData.Dataset.GetDoubleValues(freeVariable, s.ProblemData.TrainingIndices).Max()).Min();
-
+      RecalculateTrainingLimits();
       RecalculateInternalDataset();
     }
 
     private void sharedFixedVariables_ItemChanged(object o, EventArgs<int, int> e) {
-      var sender = (ModifiableDataset)o;
+      if (o != sharedFixedVariables) return;
       var variables = sharedFixedVariables.DoubleVariables.ToList();
       var rowIndex = e.Value;
@@ -153,10 +146,7 @@
       var variableName = variables[columnIndex];
       if (variableName == FreeVariable) return;
-      var v = sender.GetDoubleValue(variableName, rowIndex);
+      var v = sharedFixedVariables.GetDoubleValue(variableName, rowIndex);
       var values = new List<double>(Enumerable.Repeat(v, DrawingSteps));
       internalDataset.ReplaceVariable(variableName, values);
-
-      if (UpdateChartAutomatically)
-        UpdateChart();
     }
 
@@ -180,5 +170,10 @@
     }
 
-    public void UpdateChart() {
+    private void RecalculateTrainingLimits() {
+      trainingMin = solutions.Select(s => s.ProblemData.Dataset.GetDoubleValues(freeVariable, s.ProblemData.TrainingIndices).Min()).Max();
+      trainingMax = solutions.Select(s => s.ProblemData.Dataset.GetDoubleValues(freeVariable, s.ProblemData.TrainingIndices).Max()).Min();
+    }
+
+    public async Task UpdateChartAsync() {
       // throw exceptions?
       if (sharedFixedVariables == null || solutions == null || !solutions.Any())
@@ -203,10 +198,12 @@
       for (int i = 0; i < solutions.Count; ++i) {
         var solution = solutions[i];
-        Series confidenceIntervalPlotSeries;
-        var meanSeries = CreateSeries(solution, out confidenceIntervalPlotSeries);
-        meanSeries.Name = Solutions.First().ProblemData.TargetVariable + " " + i;
-        seriesDict.Add(meanSeries, confidenceIntervalPlotSeries);
-        if (confidenceIntervalPlotSeries != null)
-          confidenceIntervalPlotSeries.Name = "95% Conf. Interval " + meanSeries.Name;
+        var series = await CreateSeriesAsync(solution);
+        series.Item1.Tag = i; // for sorting
+        var meanSeries = series.Item1;
+        var confidenceIntervalSeries = series.Item2;
+        meanSeries.Name = solution.ProblemData.TargetVariable + " " + i;
+        seriesDict.Add(meanSeries, confidenceIntervalSeries);
+        if (confidenceIntervalSeries != null)
+          confidenceIntervalSeries.Name = "95% Conf. Interval " + meanSeries.Name;
       }
 
@@ -214,5 +211,5 @@
       chart.Series.Clear();
       // Add mean series for applying palette colors
-      foreach (var series in seriesDict.Keys) {
+      foreach (var series in seriesDict.Keys.OrderBy(s => (int)s.Tag)) {
         series.LegendText = series.Name;
         chart.Series.Add(series);
@@ -222,5 +219,5 @@
       chart.Palette = ChartColorPalette.None;
 
-      foreach (var series in seriesDict) {
+      foreach (var series in seriesDict.OrderBy(s => (int)s.Key.Tag)) {
         if (series.Value == null) continue;
         int idx = chart.Series.IndexOf(series.Key);
@@ -232,9 +229,12 @@
 
 
-      //// calculate Y-axis interval
+      // calculate Y-axis interval
       //double ymin = 0, ymax = 0;
-      //foreach (var v in chart.Series[0].Points.Select(x => x.YValues[0])) {
-      //  if (ymin > v) ymin = v;
-      //  if (ymax < v) ymax = v;
+      //foreach (var vs in chart.Series.SelectMany(series => series.Points.Select(s => s.YValues))) {
+      //  for (int index = 0; index < vs.Length; index++) {
+      //    var v = vs[index];
+      //    if (ymin > v) ymin = v;
+      //    if (ymax < v) ymax = v;
+      //  }
       //}
       //ChartUtil.CalculateAxisInterval(ymin, ymax, YXAxisTicks, out axisMin, out axisMax, out axisInterval);
@@ -243,4 +243,5 @@
       //axis.Maximum = axisMax;
       //axis.Interval = axisInterval;
+      //chart.ChartAreas[0].RecalculateAxesScale();
 
       // set axis title
@@ -250,30 +251,26 @@
     }
 
-    private Series CreateSeries(IRegressionSolution solution, out Series confidenceIntervalPlotSeries) {
-      var series = new Series {
-        ChartType = SeriesChartType.Line
-      };
-
-      var xvalues = internalDataset.GetDoubleValues(FreeVariable).ToList();
-      var yvalues = solution.Model.GetEstimatedValues(internalDataset, Enumerable.Range(0, internalDataset.Rows)).ToList();
-      series.Points.DataBindXY(xvalues, yvalues);
-
-      var confidenceBoundSolution = solution as IConfidenceBoundRegressionSolution;
-      if (confidenceBoundSolution != null) {
-        var variances = confidenceBoundSolution.Model.GetEstimatedVariances(internalDataset, Enumerable.Range(0, internalDataset.Rows)).ToList();
-
-        var lower = yvalues.Zip(variances, (m, s2) => m - 1.96 * Math.Sqrt(s2)).ToList();
-        var upper = yvalues.Zip(variances, (m, s2) => m + 1.96 * Math.Sqrt(s2)).ToList();
-
-        confidenceIntervalPlotSeries = new Series {
-          ChartType = SeriesChartType.Range,
-          YValuesPerPoint = 2
-        };
-        confidenceIntervalPlotSeries.Points.DataBindXY(xvalues, lower, upper);
-      } else {
-        confidenceIntervalPlotSeries = null;
-      }
-
-      return series;
+    private Task<Tuple<Series, Series>> CreateSeriesAsync(IRegressionSolution solution) {
+      return Task.Run(() => {
+        var xvalues = internalDataset.GetDoubleValues(FreeVariable).ToList();
+        var yvalues = solution.Model.GetEstimatedValues(internalDataset, Enumerable.Range(0, internalDataset.Rows)).ToList();
+
+        var series = new Series { ChartType = SeriesChartType.Line };
+        series.Points.DataBindXY(xvalues, yvalues);
+
+        var confidenceBoundSolution = solution as IConfidenceBoundRegressionSolution;
+        Series confidenceIntervalSeries = null;
+        if (confidenceBoundSolution != null) {
+          var variances = confidenceBoundSolution.Model.GetEstimatedVariances(internalDataset, Enumerable.Range(0, internalDataset.Rows)).ToList();
+
+          var lower = yvalues.Zip(variances, (m, s2) => m - 1.96 * Math.Sqrt(s2)).ToList();
+          var upper = yvalues.Zip(variances, (m, s2) => m + 1.96 * Math.Sqrt(s2)).ToList();
+
+          confidenceIntervalSeries = new Series { ChartType = SeriesChartType.Range, YValuesPerPoint = 2 };
+          confidenceIntervalSeries.Points.DataBindXY(xvalues, lower, upper);
+        }
+
+        return Tuple.Create(series, confidenceIntervalSeries);
+      });
     }
 
@@ -283,10 +280,11 @@
       if (solutions.Contains(solution)) return;
       solutions.Add(solution);
-      UpdateChart();
+      RecalculateTrainingLimits();
+      UpdateChartAsync();
     }
     public void RemoveSolution(IRegressionSolution solution) {
-      bool removed = solutions.Remove(solution);
-      if (removed)
-        UpdateChart();
+      if (!solutions.Remove(solution)) return;
+      RecalculateTrainingLimits();
+      UpdateChartAsync();
     }
 
Index: branches/HeuristicLab.RegressionSolutionGradientView/HeuristicLab.Problems.DataAnalysis.Views/3.4/RegressionSolutionGradientView.Designer.cs
===================================================================
--- branches/HeuristicLab.RegressionSolutionGradientView/HeuristicLab.Problems.DataAnalysis.Views/3.4/RegressionSolutionGradientView.Designer.cs	(revision 13836)
+++ branches/HeuristicLab.RegressionSolutionGradientView/HeuristicLab.Problems.DataAnalysis.Views/3.4/RegressionSolutionGradientView.Designer.cs	(revision 13837)
@@ -78,5 +78,4 @@
       this.gradientChart.Dock = System.Windows.Forms.DockStyle.Fill;
       this.gradientChart.DrawingSteps = 1000;
-      this.gradientChart.UpdateChartAutomatically = true;
       this.gradientChart.Location = new System.Drawing.Point(0, 0);
       this.gradientChart.Name = "gradientChart";
Index: branches/HeuristicLab.RegressionSolutionGradientView/HeuristicLab.Problems.DataAnalysis.Views/3.4/RegressionSolutionGradientView.cs
===================================================================
--- branches/HeuristicLab.RegressionSolutionGradientView/HeuristicLab.Problems.DataAnalysis.Views/3.4/RegressionSolutionGradientView.cs	(revision 13836)
+++ branches/HeuristicLab.RegressionSolutionGradientView/HeuristicLab.Problems.DataAnalysis.Views/3.4/RegressionSolutionGradientView.cs	(revision 13837)
@@ -32,5 +32,5 @@
 namespace HeuristicLab.Algorithms.DataAnalysis.Views {
   [View("Gradient View")]
-  [Content(typeof(IConfidenceBoundRegressionSolution))]
+  [Content(typeof(IRegressionSolution))]
   public partial class RegressionSolutionGradientView : DataAnalysisSolutionEvaluationView {
     private const int DrawingSteps = 1000;
@@ -44,6 +44,6 @@
     }
 
-    public new IConfidenceBoundRegressionSolution Content {
-      get { return (IConfidenceBoundRegressionSolution)base.Content; }
+    public new IRegressionSolution Content {
+      get { return (IRegressionSolution)base.Content; }
       set { base.Content = value; }
     }
@@ -55,12 +55,12 @@
       trackbars = new ObservableList<DensityTrackbar>();
       trackbars.ItemsAdded += (sender, args) => {
-        ForEach(args.Items.Select(i => i.Value), RegisterEvents);
+        args.Items.Select(i => i.Value).ForEach(RegisterEvents);
       };
       trackbars.ItemsRemoved += (sender, args) => {
-        ForEach(args.Items.Select(i => i.Value), DeregisterEvents);
+        args.Items.Select(i => i.Value).ForEach(DeregisterEvents);
       };
       trackbars.CollectionReset += (sender, args) => {
-        ForEach(args.OldItems.Select(i => i.Value), DeregisterEvents);
-        ForEach(args.Items.Select(i => i.Value), RegisterEvents);
+        args.OldItems.Select(i => i.Value).ForEach(DeregisterEvents);
+        args.Items.Select(i => i.Value).ForEach(RegisterEvents);
       };
 
@@ -87,5 +87,5 @@
       sharedFixedVariables = new ModifiableDataset(variableNames, newTrackbars.Select(tb => new List<double>(1) { (double)tb.Value }));
       gradientChart.Configure(new[] { Content }, sharedFixedVariables, variableNames.First(), DrawingSteps);
-      gradientChart.UpdateChart();
+      gradientChart.UpdateChartAsync();
 
       // Add to table and observable lists     
@@ -149,9 +149,9 @@
     }
 
-    private void trackbar_ValueChanged(object sender, EventArgs e) {
+    private async void trackbar_ValueChanged(object sender, EventArgs e) {
       var trackBar = sender as DensityTrackbar;
       if (trackBar == null) return;
       sharedFixedVariables.SetVariableValue((double)trackBar.Value, variableNames[trackbars.IndexOf(trackBar)], 0);
-      gradientChart.UpdateChart();
+      await gradientChart.UpdateChartAsync();
     }
 
@@ -183,5 +183,9 @@
     #endregion
 
-    public static void ForEach<T>(IEnumerable<T> source, Action<T> action) {
+
+  }
+
+  internal static class Extensions {
+    public static void ForEach<T>(this IEnumerable<T> source, Action<T> action) {
       foreach (T item in source)
         action(item);
Index: branches/HeuristicLab.RegressionSolutionGradientView/HeuristicLab.Problems.DataAnalysis.Views/3.4/RegressionSolutionTargetResponseGradientView.cs
===================================================================
--- branches/HeuristicLab.RegressionSolutionGradientView/HeuristicLab.Problems.DataAnalysis.Views/3.4/RegressionSolutionTargetResponseGradientView.cs	(revision 13836)
+++ branches/HeuristicLab.RegressionSolutionGradientView/HeuristicLab.Problems.DataAnalysis.Views/3.4/RegressionSolutionTargetResponseGradientView.cs	(revision 13837)
@@ -73,8 +73,8 @@
           ShowYAxisLabel = true,
         };
-        gradientChart.VariableValueChanged += (o, e) => {
+        gradientChart.VariableValueChanged += async (o, e) => {
           foreach (var chart in gradientChartTableLayout.Controls.Cast<GradientChart>()) {
             if (chart == (GradientChart)o) continue;
-            chart.UpdateChart();
+            await chart.UpdateChartAsync();
           }
         };
@@ -99,5 +99,5 @@
     }
 
-    private void variableListView_ItemChecked(object sender, ItemCheckedEventArgs e) {
+    private async void variableListView_ItemChecked(object sender, ItemCheckedEventArgs e) {
       if (charts == null) return;
       var item = e.Item;
@@ -111,5 +111,5 @@
       if (item.Checked) {
         tl.Controls.Add(chart);
-        chart.UpdateChart();
+        await chart.UpdateChartAsync();
       } else {
         tl.Controls.Remove(chart);
