This is a migrated thread and some comments may be shown as answers.

Defining a LabelDefinition.Template programmatically crashes browser?

1 Answer 80 Views
Chart
This is a migrated thread and some comments may be shown as answers.
Colter
Top achievements
Rank 1
Colter asked on 30 Jul 2013, 08:23 PM
Hello,

I have the following situation:

I am creating a dynamic number of bar/line series using the SeriesProvider class.

Unfortunately there does not seem to be a way to define a custom label definition within this class so I am waiting until the Loaded event is fired on my chart and trying to do it programmatically.

RadCartesianChart cartesianChart = chart as RadCartesianChart;
 
if (cartesianChart != null)
{
    // add label definitions since our chart series are created dynamically by Series Providers
    ChartSeriesLabelDefinition cartesianLabelDefintion = new ChartSeriesLabelDefinition();
 
    // Grab the data template from the resources
    if (Resources.Contains(CartesianLabelTemplateName))
    {
        DataTemplate labelTemplate = Resources[CartesianLabelTemplateName] as DataTemplate;
        if (labelTemplate != null)
        {
            cartesianLabelDefintion.Template = labelTemplate;
        }
    }
 
    // Default to a property binding if no template is found
    if(cartesianLabelDefintion.Template == null)
    {
        cartesianLabelDefintion.Binding = new PropertyNameDataPointBinding("FormattedValue");
    }
 
    cartesianChart.Series.ForEach(s =>
        {
            s.LabelDefinitions.Add(cartesianLabelDefintion);
        });
 
}


Which results in the following stack trace in Chrome when the chart tries to render.  For some reason I can't intercept this exception in Visual studio.

Uncaught Error: Unhandled Error in Silverlight Application Code: 4004 Category: ManagedRuntimeError Message: System.NullReferenceException: Object reference not set to an instance of an object. at Telerik.Windows.Controls.ChartView.ChartSeries.GetLabelVisual(ChartSeriesLabelUpdateContext context) at Telerik.Windows.Controls.ChartView.ChartSeries.ProcessLabelDefinition(ChartSeriesLabelUpdateContext context) at Telerik.Windows.Controls.ChartView.ChartSeries.ProcessDataPointLabels(ChartSeriesLabelUpdateContext context) at Telerik.Windows.Controls.ChartView.ChartSeries.UpdateLabels(ChartLayoutContext context) at Telerik.Windows.Controls.ChartView.ChartSeries.UpdateUICore(ChartLayoutContext context) at Telerik.Windows.Controls.ChartView.PointTemplateSeries.UpdateUICore(ChartLayoutContext context) at Telerik.Windows.Controls.ChartView.BarSeries.UpdateUICore(ChartLayoutContext context) at Telerik.Windows.Controls.ChartView.PresenterBase.UpdateUI(ChartLayoutContext context) at Telerik.Windows.Controls.ChartView.RadChartBase.UpdateUICore(ChartLayoutContext context) at Telerik.Windows.Controls.ChartView.PresenterBase.UpdateUI(ChartLayoutContext context) at Telerik.Windows.Controls.ChartView.RadChartBase.CallUpdateUI() at Telerik.Windows.Controls.ChartView.RadChartBase.ArrangeOverride(Size finalSize) at System.Windows.FrameworkElement.ArrangeOverride(IntPtr nativeTarget, Single inWidth, Single inHeight, Single& outWidth, Single& outHeight)


Any thoughts?

Colter

1 Answer, 1 is accepted

Sort by
0
Peshito
Telerik team
answered on 02 Aug 2013, 08:17 AM
Hi Colter,

Wiring to the Loaded event is probably too early for the chart. What I could reccomend is setting the LabelDefinition in XAML. Please take a look at the following demo demonstrating the same approach using ChartSeriesProvider and LabelDefinition:
http://demos.telerik.com/silverlight/#ChartView/BrowsersChart

Hope this helps.

Regards,
Peshito
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for SILVERLIGHT.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
Tags
Chart
Asked by
Colter
Top achievements
Rank 1
Answers by
Peshito
Telerik team
Share this question
or