private void UpdateChart(object chart, Dictionary <string, DataContainer> dict) { Chart chart_ = (Chart)chart; // get all keys from the current connection var keys = dict.Keys.ToArray(); // clear and update the graphs (for each key) foreach (string key in keys) { // if series does not exist, add it if (chart_.Series.IndexOf(key) == -1) { Charting.AddChartSeries(this, key, chart_); } int i = dict[key].time.Length - 1; if (dict[key].time[i] != null) { DateTime time = DateTime.ParseExact(dict[key].time[i], Constants.FMT, CultureInfo.InvariantCulture, DateTimeStyles.AssumeLocal); chart_.Series[key].Points.AddXY(time.ToOADate(), Convert.ToDouble(dict[key].value[i])); } // remove old data points if (chart_.Series[key].Points.Count > Constants.n_datapoints_max) { chart_.Series[key].Points.RemoveAt(0); } } }