Pie Chart

5 posts, 1 answers
  1. Darin
    Darin avatar
    11 posts
    Member since:
    Sep 2012

    Posted 09 May 2013 Link to this post

    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. 
  2. Victor
    Admin
    Victor avatar
    1351 posts

    Posted 09 May 2013 Link to this post

    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.
  3. DevCraft banner
  4. Darin
    Darin avatar
    11 posts
    Member since:
    Sep 2012

    Posted 09 May 2013 Link to this post

    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.
  5. Answer
    Victor
    Admin
    Victor avatar
    1351 posts

    Posted 10 May 2013 Link to this post

    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.
  6. Darin
    Darin avatar
    11 posts
    Member since:
    Sep 2012

    Posted 10 May 2013 Link to this post

    Awesome thanks!  That worked!
Back to Top
DevCraft banner