0

I have 2 series which I'm adding to the same chartarea. Both series have the same structure (date on x-axis, amount on y-axis). The first series has values from 01 Oct to 15 Oct and the second from 16 Oct to 31 Oct.

I add the first series as follows:

var series = new Series
{
    ChartType = SeriesChartType.SplineArea
};

series.Points.DataBindXY(data.Select(x => x.Date).ToArray(), data.Select(x => x.Amount).ToArray());
chart.Series.Add(series);

And the second series:

series = new Series
{
    ChartType = SeriesChartType.Line,
    BorderWidth = 2,
    BorderDashStyle = ChartDashStyle.Dot
};

series.Points.DataBindXY(pred.Select(x => x.Date).ToArray(), pred.Select(x => x.Amount).ToArray());
chart.Series.Add(series);

The dates are correct and they are sequential. There are no overlapping.

However, this is what's being plotted:

chart

The second series should begin at the end of the first series but they're overlapping.

Am I missing something?

Ivan-Mark Debono
  • 15,500
  • 29
  • 132
  • 263
  • `x => x.Date` __looks__ like a `DateTime`, but __is__ it?? My guess is: It is really a `string`.. – TaW Oct 06 '18 at 08:28
  • @TaW Yes `Date` is a `string` and in both cases formatted as "dd/mmm". – Ivan-Mark Debono Oct 06 '18 at 08:38
  • 1
    Never add x-values as strings!! Add them as DataTimes if they are and do the formatting in the Format string of the Lables of Series, Axis or DataPoints! - You are adding the x-values as **strings**. This is a tricky mistake: The resulting **labels** are ok, but all **x-values are in fact 0**, so the points do not **align** correctly neither inside nor across series. Other problems will also arise when trying to do things with the x-values, like setting ranges or formatting their (lost) values.. – TaW Oct 06 '18 at 08:44
  • @TaW The original date values are actually long (unix timestamp). Can I use those as the x-values? – Ivan-Mark Debono Oct 06 '18 at 08:54
  • Well, you can use them but I'm not sure about the formatting. The best thing are either DateTimes or doubles from the OADate conversion function. If possible I would try to avoid going via conversion to string and back to datetimes.. [These posts](https://stackoverflow.com/questions/249760/how-can-i-convert-a-unix-timestamp-to-datetime-and-vice-versa) may be the best way.. – TaW Oct 06 '18 at 09:07

0 Answers0