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

Pie Chart

4 Answers 78 Views
Chart
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Darin
Top achievements
Rank 1
Darin asked on 09 May 2013, 06:09 AM
The question I have is how would I go about adding slice styles to the pie chart programmatically.  Every time I try to do so I get a 'Catastrophic Error' exception.  I'm trying to implement this control into a Windows Phone 8 app. 

4 Answers, 1 is accepted

Sort by
0
Victor
Telerik team
answered on 09 May 2013, 07:39 AM
Hello Darin,

Can you please post the code snippet that you use to add slice styles?

Kind regards,
Victor
the Telerik team
Have a suggestion or face a problem - you can use the Ideas & Feedback portal to submit ideas, feedback and vote for them.
0
Darin
Top achievements
Rank 1
answered on 09 May 2013, 12:45 PM
Yeah, so here are some snippets of code below:

XAML:
<Grid.Resources>
      <Style x:Key="BasePieStyle" TargetType="Path" x:Name="BasePieStyle">               
<
Setter Property="StrokeThickness" Value="2"/>
        <Setter Property="Stroke" Value="{StaticResource PhoneForegroundBrush}"/>
      </Style>
</Grid.Resources>

C#:
for (int i = 0; i < benchmarkCount; i++)
{
      Style style1 =
new Style();
      style1.BasedOn = BasePieStyle;                
      style1.TargetType =
typeof(PropertyPath);
      Setter setter1 =
new Setter();
      setter1.Property = DependencyProperty.Register(
"Fill", typeof(SolidColorBrush), typeof(PieSeries), new PropertyMetadata((SolidColorBrush)App.Current.Resources["PhoneAccentBrush"]));
      setter1.Value = (SolidColorBrush)App.Current.Resources["PhoneAccentBrush"];
      style1.Setters.Add(setter1);
      
this.pieTimesCompleted.Series[0].SliceStyles.Add(style1);
}

So in the example that was provided in the trial download it looks like you guys have a static number of slice styles, which is 6.  And then you add the percents as an itemssource like below:

this.pieTimesCompleted.Series[0].ItemsSource = new double[] { 10, 20, 15, 5, 35, 15 };

However, I have an x number of slices and I need to add that number of slicestyles to my pie chart.  X being benchmarkCount in this example.   When it goes to render the pie chart that's when I get the catastrophic error.  I took the example you guys provided and just tried to take out the slice style definition from the xaml and put it in the C# with no luck.
0
Accepted
Victor
Telerik team
answered on 10 May 2013, 12:05 PM
Hi Darin,

There are two lines in the C# that are not equivalent to the XAML lines.
First your are setting the target type to PropertyPath which has nothing to do with the Path type. PropertyPath is a part of the dependency property system of Silverlight while Path is a UIElement that can rendered on screen. The target type should be typeof(Path).

Second you are dynamically registering a completely new property with the same name and type as the original Fill property and are then setting the owner type to be PieSeries. You should not create a new property but simply provide the existing one which is Path.FillProperty.

Regards,
Victor
the Telerik team
Have a suggestion or face a problem - you can use the Ideas & Feedback portal to submit ideas, feedback and vote for them.
0
Darin
Top achievements
Rank 1
answered on 10 May 2013, 01:22 PM
Awesome thanks!  That worked!
Tags
Chart
Asked by
Darin
Top achievements
Rank 1
Answers by
Victor
Telerik team
Darin
Top achievements
Rank 1
Share this question
or