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

Chart Legend error

1 Answer 59 Views
Chart
This is a migrated thread and some comments may be shown as answers.
James
Top achievements
Rank 1
James asked on 01 Feb 2012, 05:13 PM
I upgraded my WPF controls to version 2011.2.712.35 to fix a problem with adding the Camera Extension to a Chart for zooming.  When I did this I started getting a very odd error in a call to add a LegendItemMarkerShape to the Legend.  The chart xaml looks like this:

<UserControl x:Class="ABC.APP.ProfileWpf.ChartControl"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             mc:Ignorable="d"
             d:DesignHeight="300" d:DesignWidth="300" xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation">
    <Grid>
        <telerik:RadChart Margin="0" Name="mChartControl">
            <telerik:RadChart.DefaultSeriesDefinition>
                <telerik:Bar3DSeriesDefinition />
            </telerik:RadChart.DefaultSeriesDefinition>
  
            <telerik:RadChart.DefaultView>
                <telerik:ChartDefaultView>
                    <telerik:ChartDefaultView.ChartLegend>
                        <telerik:ChartLegend Name="legend" />
                    </telerik:ChartDefaultView.ChartLegend>
                    <telerik:ChartDefaultView.ChartArea>
                        <telerik:ChartArea LegendName="legend" DimensionMode="Strict3D">
                            <telerik:ChartArea.Extensions>
                                <telerik:CameraExtension />
                            </telerik:ChartArea.Extensions>
                        </telerik:ChartArea>
                    </telerik:ChartDefaultView.ChartArea>
                </telerik:ChartDefaultView>
            </telerik:RadChart.DefaultView>
        </telerik:RadChart>       
    </Grid>
and the code where I pass the marker shape looks like this:
mChartControl.DefaultView.ChartArea.Legend.LegendItemMarkerShape = value;

I am using VS2010 and the weird thing here is if I let the code run without inspecting the object in the QuickWatch 
Dialog then it will exception with the error "Object reference not set to an instance of an object.".  If I 
go ahead and inspect the mChartControl object and drill all of the way down to the Lengend object the Legend 
object will show "+Legend{Telerik.Windows.Controls.Charting.ChartLegend Header: Items.Count:0}" that it does
exist and the code will run as it should without exception, but if I just do a hover over the string in the 
IDE the Legend oject will show a value of NULL and will exception.  Please let me know what is going on here
and what can be done to correct this.  Thanks for your help out there.

1 Answer, 1 is accepted

Sort by
0
Nikolay
Telerik team
answered on 06 Feb 2012, 09:38 AM
Hello James,

Please, try setting the marker shape from the ChartLegend in this manner :
this.RadChart1.DefaultView.ChartLegend.LegendItemMarkerShape = MarkerShape.Circle;

Hope this helps.

Regards,
Nikolay
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
Tags
Chart
Asked by
James
Top achievements
Rank 1
Answers by
Nikolay
Telerik team
Share this question
or