title: C# Excel Interop Charts with multi series - X axis as DateTime
body: <p>I have an excel addin implemented in C#. This connects to a server and obtains &lt;key, value1, value2, value3..&gt; pairs, where key is DateTime.
  After data is fetched, this is populated in Excel worksheet. This data is used to plot multi-series line graph.
  I am using ChartWizard and on the Chart object I add multiple series using .NewSeries option.
  What is the best way to specify that my X axis is DateTime. I see the behaviour differs when I use ScatterLines or XLLines. I am unable to find an approach where I can say to the chart that my X axis is DateTime and specify a dateformat to same
  Any help will be appreciated.
  Vikron</p>
  <pre class="lang-cs prettyprint-override"><code>Microsoft.Office.Tools.Excel.Chart chart = worksheet.Controls.AddChart(0, 0, xx, yy, &quot;Trend&quot;);
  chart.ChartWizard(Type.Missing,
          Microsoft.Office.Interop.Excel.XlChartType.xlXYScatterLines,
          Type.Missing,
          XlRowCol.xlColumns,
          Type.Missing,
          Type.Missing,
          true,
          &quot;Trend&quot;,
          &quot;Time stamp&quot;,
          Type.Missing,
          Type.Missing);
  chart.AutoScaling = false;
  chart.ChartStyle = 34;
  chart.Legend.Position = XlLegendPosition.xlLegendPositionBottom;
  chart.HasTitle = true;
  chart.ChartType = XlChartType.xlXYScatterLines;
  chart.ChartTitle.Text = &quot;Trend&quot;;
  
  foreach (series)
  {
      Excel.Series xlSeries = (Excel.Series)((Excel.SeriesCollection)chart.SeriesCollection()).NewSeries();
      Microsoft.Office.Interop.Excel.Range seriesRange = worksheet.get_Range(series.seriesBeginRange,
                                                          worksheet.get_Range(series.seriesBeginRange).get_End(XlDirection.xlDown));
      xlSeries.Name = series.seriesName;
      xlSeries.XValues = timeSeriesRange; //This has datetime
      xlSeries.ChartType = Microsoft.Office.Interop.Excel.XlChartType.xlXYScatterLines;
      xlSeries.Values = seriesRange;
  }
  
  cell.NumberFormat = &quot;MM/dd/yy HH:mm&quot;;
  cell.Value = ts;
  </code></pre>