This project is read-only.

UnhandledException while using chart

Sep 23, 2013 at 7:58 AM
Edited Sep 23, 2013 at 1:17 PM
Hi, I am using charts in my app. In certain screens chart works fine but in certain screens it throws UnhandledException (earlier it was working fine). I am not getting much exception details. What's wrong with the chart?
   at Windows.UI.Xaml.UIElement.Measure(Size availableSize)
   at WinRTXamlToolkit.Controls.DataVisualization.Charting.Primitives.EdgePanel.MeasureOverride(Size constraint)   at Windows.UI.Xaml.FrameworkElement.MeasureOverride(Size availableSize)

"Error HRESULT E_FAIL has been returned from a call to a COM component."
Here's code to regenerate it. I am doing all the stuff in code behind because in real there would be dynamic chart.

    <Style TargetType="charting:ColumnDataPoint" x:Key="MyColumnDataPointStyle">
        <Setter Property="Template">
                <ControlTemplate TargetType="charting:ColumnDataPoint">
                                <TextBlock Text="{Binding Tooltip}" TextAlignment="Center" />
                        <Rectangle Fill="{Binding Color}" Stroke="{Binding Color}" StrokeThickness="3" />

<Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
    <charting:Chart x:Name="ChartSalesRevenue" Margin="70,0" /> 
protected override void OnNavigatedTo(NavigationEventArgs e)
    ChartSalesRevenue.Series.Add(new StackedColumnSeries());
    Binding DependentBinding = new Binding();
    Binding IndependentBinding = new Binding();
    IndependentBinding.Converter = new DateToStringConverter();
    SeriesDefinition series;

    series = new SeriesDefinition();
    series.DataPointStyle = this.Resources["MyColumnDataPointStyle"] as Style;
    DependentBinding.Path = new PropertyPath("Units");
    IndependentBinding.Path = new PropertyPath("Begin_Date");
    series.DependentValueBinding = DependentBinding;
    series.IndependentValueBinding = IndependentBinding;
    series.ItemsSource = GetDataItems();

private List<DataItem> GetDataItems()
    return new List<DataItem> 
        new DataItem("Tooltip 1", new SolidColorBrush(Colors.Red), 5, DateTime.Now.AddDays(-1)),
        new DataItem("Tooltip 2", new SolidColorBrush(Colors.Violet), 3, DateTime.Now.AddDays(1)),
        new DataItem("Tooltip 3", new SolidColorBrush(Colors.PaleGoldenrod), 22, DateTime.Now.AddDays(-2)),
        new DataItem("Tooltip 4", new SolidColorBrush(Colors.DarkBlue), 15, DateTime.Now.AddDays(2)),
        new DataItem("Tooltip 5", new SolidColorBrush(Colors.DeepPink), 9, DateTime.Now),

public class DateToStringConverter : IValueConverter
    public object Convert(object value, Type targetType, object parameter, string Language)
        return ((DateTime)value).ToString("MMM dd, yyyy", System.Globalization.CultureInfo.InvariantCulture);

    public object ConvertBack(object value, Type targetType, object parameter, string language)
        throw new NotImplementedException();

public class DataItem
    public DataItem(string _Tooltip, SolidColorBrush _Color, int _Units, DateTime _Begin_Date)
        Tooltip = _Tooltip;
        Color = _Color;
        Units = _Units;
        Begin_Date = _Begin_Date;
    public string Tooltip { get; set; }
    public SolidColorBrush Color { get; set; }
    public int Units { get; set; }
    public DateTime Begin_Date { get; set; }