Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>A collection with one item will have incorrect behavior in several places of your code.</p> <p>Here <code>graphSpan</code> will equal zero:</p> <pre><code>TimeSpan graphSpan = res.Values.ToList().Last().Key - res.Values.ToList().First().Key; </code></pre> <p>And here <code>Maximum</code> and <code>Minimum</code> will be the same:</p> <pre><code>lineSeries.IndependentAxis = new DateTimeAxis { Minimum = res.Values.ToList().First().Key, Maximum = res.Values.ToList().Last().Key, </code></pre> <p>I suggest that you add another if-block and construct a different axis for the special case when the collection has only 1 item.</p> <pre><code>var values = res.Values.ToList(); TimeSpan graphSpan = values.Last().Key - values.First().Key; if (graphSpan == TimeSpan.Zero) { lineSeries.IndependentAxis = new DateTimeAxis { Orientation = AxisOrientation.X, Location = AxisLocation.Bottom }; } else { lineSeries.IndependentAxis = new DateTimeAxis { Minimum = values.First().Key, Maximum = values.Last().Key, Orientation = AxisOrientation.X, Location = AxisLocation.Bottom }; if (graphSpan &gt; monthSpan) { ((DateTimeAxis)lineSeries.IndependentAxis).IntervalType = DateTimeIntervalType.Days; ((DateTimeAxis)lineSeries.IndependentAxis).Interval = 5; } else if (graphSpan &gt; daySpan &amp;&amp; graphSpan &lt; monthSpan) { ((DateTimeAxis)lineSeries.IndependentAxis).IntervalType = DateTimeIntervalType.Days; ((DateTimeAxis)lineSeries.IndependentAxis).Interval = 1; } else if (graphSpan &gt; hourSpan &amp;&amp; graphSpan &lt; daySpan) { ((DateTimeAxis)lineSeries.IndependentAxis).IntervalType = DateTimeIntervalType.Hours; ((DateTimeAxis)lineSeries.IndependentAxis).Interval = 1; } else if (graphSpan &lt; hourSpan) { ((DateTimeAxis)lineSeries.IndependentAxis).IntervalType = DateTimeIntervalType.Minutes; ((DateTimeAxis)lineSeries.IndependentAxis).Interval = 15; } else { //sometimes all comparisons fail, just back up to a safe interval of 1 day. ((DateTimeAxis)lineSeries.IndependentAxis).IntervalType = DateTimeIntervalType.Days; ((DateTimeAxis)lineSeries.IndependentAxis).Interval = 1; } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload