Search code examples
silverlight-toolkit

How to set interval on an empty DateTimeAxis in a Silverlight toolkit chart


I have created a chart using the Silverlight 5 toolkit. It has LinearSeries without the ItemsSource specified (it is assigned later in code). The DateTimeAxis does not have a Maximum nor the Minimum specified as I might be plotting different data at different time. However, no matter what the data to plot is, I would like the points to be spaced out every 30 seconds. When specifying this in XAML the page fails to load (the system runs out of memory). When trying a different (larger) time interval it manages just fine (ex 1 month steps). It seems that if no data is provided to the graph it takes a 1 year interval as default.

Is this a known issue? What is the way to deal with this, other than specifying a Max/Min and then getting rid of it once some data is supplied?

Here is my code:

<toolkit:Chart Title="Live Use">
    <toolkit:Chart.Series>
        <toolkit:LineSeries
                IndependentValueBinding="{Binding Time}" 
                DependentValueBinding="{Binding Value}" 
                AnimationSequence="Simultaneous" />
    </toolkit:Chart.Series>
    <toolkit:Chart.Axes>
        <toolkit:DateTimeAxis Orientation="X" Location="Bottom" BorderThickness="2" Title="Time" ShowGridLines="True" IntervalType="Months" Interval="3"/>
    </toolkit:Chart.Axes>
</toolkit:Chart>

Solution

  • Apparently this is a bug in the toolkit chart. I found this link which confirms this: http://forums.silverlight.net/t/101287.aspx. The problem is that the chart by default has its range set to 1 year. Now, if you try to set the interval to 30 seconds it will attempt to generate a lot of labels and this will slow it down up to the point where it runs out of memory. Solution is to manually set the range or to specify the itemsSource prior to specifying the interval on the axis.

    Hope this helps.