title: "Red X of Doom" while plotting multiple time series chart in WinForm
body: <p>I'm trying to <em>plot multiple time series data</em>. I based my code off the accepted answer here:</p>
  
  <p><a href="https://stackoverflow.com/questions/10622674/chart-creating-dynamically-in-net-c-sharp">Chart creating dynamically. in .net, c#</a></p>
  
  <p>However, I am plotting the data for multiple timeseries data that can be coming in from different sources which I've labeled as "tags."</p>
  
  <p>After <em>two calls to AddXY from different sources</em>, I get the big Red X, but I'm unable to determine why this is.  My code is below, along with a picture of the big red X, in case it's ambiguous what I'm talking about.</p>
  
  <p>It might be worth noting that I'm <em>in a Console application</em>, and <em>creating a WinForm dynamically</em>.</p>
  
  <pre><code>using System;
  using System.Collections.Concurrent;
  using System.Collections.Generic;
  using System.Linq;
  using System.Runtime.CompilerServices;
  using System.Text;
  using System.Threading.Tasks;
  using System.Windows.Forms;
  using System.Windows.Forms.DataVisualization;
  using System.Windows.Forms.DataVisualization.Charting;
  
  namespace MyApplication
  {
      public class ChartForm : Form
      {
          private System.ComponentModel.IContainer components = null;
          System.Windows.Forms.DataVisualization.Charting.Chart chart1;
          System.Windows.Forms.DataVisualization.Charting.Series series1;
          ConcurrentDictionary&lt;string, System.Windows.Forms.DataVisualization.Charting.Series&gt; tagToSeriesDict;
          Random r = new Random();
  
          public ChartForm()
          {
              InitializeComponent();
  
          }
          private void Form1_Load(object sender, EventArgs e)
          {
              this.tagToSeriesDict = new ConcurrentDictionary&lt;string, System.Windows.Forms.DataVisualization.Charting.Series&gt;();
              chart1.Series.Clear();
          }
  
          [MethodImpl(MethodImplOptions.Synchronized)]
          public void addPoint(string tag, double x, double y)
          {
              if (!tagToSeriesDict.ContainsKey(tag))
              {
                  tagToSeriesDict[tag] = new System.Windows.Forms.DataVisualization.Charting.Series
                  {
                      Name = tag,
                      Color = System.Drawing.Color.FromArgb((int)(r.NextDouble() * 255), (int)(r.NextDouble() * 255), (int)(r.NextDouble() * 255)),
                      IsVisibleInLegend = false,
                      IsXValueIndexed = true,
                      ChartType = SeriesChartType.Line
                  };
  
                  this.chart1.Series.Add(tagToSeriesDict[tag]);
              }
  
              tagToSeriesDict[tag].Points.AddXY(x, y);
          }
  
          protected override void Dispose(bool disposing)
          {
              if (disposing &amp;&amp; (components != null))
              {
                  components.Dispose();
              }
              base.Dispose(disposing);
          }
  
          private void InitializeComponent()
          {
              this.components = new System.ComponentModel.Container();
              System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea1 = new System.Windows.Forms.DataVisualization.Charting.ChartArea();
              System.Windows.Forms.DataVisualization.Charting.Legend legend1 = new System.Windows.Forms.DataVisualization.Charting.Legend();
              this.chart1 = new System.Windows.Forms.DataVisualization.Charting.Chart();
              ((System.ComponentModel.ISupportInitialize)(this.chart1)).BeginInit();
              this.SuspendLayout();
              //
              // chart1
              //
              chartArea1.Name = "ChartArea1";
              this.chart1.ChartAreas.Add(chartArea1);
              this.chart1.Dock = System.Windows.Forms.DockStyle.Fill;
              legend1.Name = "Legend1";
              this.chart1.Legends.Add(legend1);
              this.chart1.Location = new System.Drawing.Point(0, 50);
              this.chart1.Name = "chart1";
              // this.chart1.Size = new System.Drawing.Size(284, 212);
              this.chart1.TabIndex = 0;
              this.chart1.Text = "chart1";
              //
              // Form1
              //
              this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
              this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
              this.ClientSize = new System.Drawing.Size(800, 600);
              this.Controls.Add(this.chart1);
              this.Name = "Form1";
              this.Text = "Chart";
              this.Load += new System.EventHandler(this.Form1_Load);
              ((System.ComponentModel.ISupportInitialize)(this.chart1)).EndInit();
              this.ResumeLayout(false);
          }
      }
  }
  </code></pre>
  
  <p>EDIT: as requested, I've added the code in which the form is created, and in which addPoint is called:</p>
  
  <pre><code>//a static field in the main application:
  static ChartForm plot = new ChartForm();
  
  //called once in the constructor of my main application
  Application.EnableVisualStyles();
  Application.Run(plot); // or whatever
  
  //callback to ObservableConcurrentDictionary called whenever new data comes in:
  [MethodImpl(MethodImplOptions.Synchronized)]
      public void onVisibilityChanged(object obj, System.Collections.Specialized.NotifyCollectionChangedEventArgs args)
      {
  
          KeyValuePair&lt;string, IDistribution&gt; tagAndState = (KeyValuePair&lt;string, IDistribution&gt;)args.NewItems[0];
          string tag = tagAndState.Key;
          double value = (double)tagAndState.Value;
  
  
  
  
          double now = DateTime.UtcNow.Ticks;
          TicTacToeInteraction.plot.addPoint(tag, now, value);
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/tFGgO.png" alt="enter image description here"></p>