0

I have a chart control that has a series of dates plotted along the x axis. There are 120 dates, each for a different day. When these dates are plotted, the graph wraps around itself and plots the graph as multiple lines (basically its circled around all 120 dates because it cant fit them into the space)

I've set the min value to the first date in the range and the max value to the last date in the range

reportChartArea.AxisX.Minimum = this._list.First().DATE.ToOADate();
reportChartArea.AxisX.Maximum = this._list.Last().DATE.ToOADate();

I've also set the interval type to days

reportChartArea.AxisX.IntervalType = DateTimeIntervalType.Days;
reportChartArea.AxisX.Interval = 4;
reportChartArea.AxisX.IntervalOffset = 1;
reportChartArea.AxisX.IntervalAutoMode = IntervalAutoMode.VariableCount;

I then create a series

Series price = new Series();
price.Font = new Font("Lucida Sans Unicode", 6f);
price.Color = Color.FromArgb(49, 116, 175);
price.XValueType = ChartValueType.DateTime;
price.YValueType = ChartValueType.Double;
price.Legend = price.Name;
price.ChartType = SeriesChartType.Line;
price.YAxisType = AxisType.Secondary;
reportChart.Legends.Add(price.Name);

and finally I iterate through my list to plot the data

foreach (var p in this._list)
{
    DataPoint p1 = new DataPoint(p.DATE.ToOADate(), p.CurrentPrice);
    price.Points.Add(p1);
}

I then add the datapoints to the chart

reportChart.Series.Add(price);

the graph is plotted and when the line reaches a certain point (about 35) it cycles over on itself and plots the next 35 or so next to the previous one and so on until it reaches the end. I've added this in to my code to test this and it doesn't cycle and just plots the first 35 data points

int i = 0;
foreach (var p in this._list)
{
    if(i<= 35)
    {
        DataPoint p1 = new DataPoint(p.DATE.ToOADate(), p.CurrentPrice);
        price.Points.Add(p1);
    }
    i++;
}

as soon as the number of points exceeds this number it loops over on itself turning the graph into a mess. Can anyone see where I'm going wrong here ? Surely the min & max settings should solve this issue, but it doesn't

proteus
  • 545
  • 2
  • 12
  • 36
  • FYI `foreach (var p in this._list)` can be `foreach (var p in this._list.Take(35))` and lose the conditional – Franck Nov 07 '17 at 16:30
  • that wasn't my question, I only put the loop in to prove it wraps around after a certain number of iterations, it was purely for testing and not part of the functionality – proteus Nov 08 '17 at 08:27
  • anyone got an idea whats going on here ? is there a bug in the chart control ? – proteus Nov 08 '17 at 09:25

0 Answers0