Black outline for Pie Chart and Custom Styles Delegate

6 posts, 0 answers
  1. Jeff Kershner
    Jeff Kershner avatar
    62 posts
    Member since:
    Aug 2009

    Posted 07 Sep 2010 Link to this post

    How can I get the gray lines that divide the pie slices to be black?

    Also, how can I get the spider lines to be the same colors as the pie slice?  I am using the chart.CreateItemStyleDelegate function like this:

    private Style BuildCustomItemStyle(Control item, Style style, DataPoint point, DataSeries dataSeries)
    {
        if ((item as BaseChartItem) == null)
            return style;
      
        Style newStyle = new Style();
        newStyle.BasedOn = style;
      
        newStyle.TargetType = typeof(Shape);
      
        Brush brush;
      
        switch ((item as BaseChartItem).CurrentIndex % 7)
        {
            case 0:
                brush = new SolidColorBrush(Color.FromArgb(255, 2, 123, 8));
                break;
      
            case 1:
                brush = new SolidColorBrush(Color.FromArgb(255, 238, 192, 5));
                break;
      
            case 2:
                brush = new SolidColorBrush(Color.FromArgb(255, 238, 97, 6));
                break;
      
            case 3:
                brush = new SolidColorBrush(Color.FromArgb(255, 1, 240, 6));
                break;
      
            case 4:
                brush = new SolidColorBrush(Color.FromArgb(255, 238, 240, 6));
                break;
      
            case 5:
                brush = new SolidColorBrush(Color.FromArgb(255, 179, 181, 183));
                break;
      
            default://case 6:
                brush = new SolidColorBrush(Color.FromArgb(255, 237, 240, 242));
                break;
        }
      
        newStyle.Setters.Add(new Setter(Shape.FillProperty, brush));
        return newStyle;
    }
  2. Sia
    Admin
    Sia avatar
    667 posts

    Posted 09 Sep 2010 Link to this post

    Hi Jeff Kershner,

    One possible solution is just to add the needed lines for your labels (see the code below). You can use the PaletteBrushes property instead. Please check the provided solution and let me know if it is appropriate for your scenario.

    private Style BuildCustomItemStyle(Control item, Style style, DataPoint point, DataSeries dataSeries)
    {
        if(item is ChartLegendItem)
            return style;
      
        if(point == null)
            return style;
     
     
        Style newStyle = new Style(style.TargetType);
        newStyle.BasedOn = style;
     
        Brush brush;
     
        if (item is BaseChartItem2D)
        {
                switch (index1)
                {
                    case 0:
                        brush = new SolidColorBrush(Color.FromArgb(255, 2, 123, 8));
                        break;
     
                    case 1:
                        brush = new SolidColorBrush(Color.FromArgb(255, 238, 192, 5));
                        break;
     
                    case 2:
                        brush = new SolidColorBrush(Color.FromArgb(255, 238, 97, 6));
                        break;
     
                    case 3:
                        brush = new SolidColorBrush(Color.FromArgb(255, 1, 240, 6));
                        break;
     
                    case 4:
                        brush = new SolidColorBrush(Color.FromArgb(255, 238, 240, 6));
                        break;
     
                    case 5:
                        brush = new SolidColorBrush(Color.FromArgb(255, 179, 181, 183));
                        break;
     
                    default://case 6:
                        brush = new SolidColorBrush(Color.FromArgb(255, 237, 240, 242));
                        break;
                }
                index1++;
                         
                newStyle.Setters.Add(new Setter(Shape.FillProperty, brush));
                newStyle.Setters.Add(new Setter(Shape.StrokeProperty, new SolidColorBrush(Colors.Black)));
            }
                     
            if (item is SeriesItemLabel)
            {
                switch (index2)
                {
                    case 0:
                        brush = new SolidColorBrush(Color.FromArgb(255, 2, 123, 8));
                        break;
     
                    case 1:
                        brush = new SolidColorBrush(Color.FromArgb(255, 238, 192, 5));
                        break;
     
                    case 2:
                        brush = new SolidColorBrush(Color.FromArgb(255, 238, 97, 6));
                        break;
     
                    case 3:
                        brush = new SolidColorBrush(Color.FromArgb(255, 1, 240, 6));
                        break;
     
                    case 4:
                        brush = new SolidColorBrush(Color.FromArgb(255, 238, 240, 6));
                        break;
     
                    case 5:
                        brush = new SolidColorBrush(Color.FromArgb(255, 179, 181, 183));
                        break;
     
                    default://case 6:
                        brush = new SolidColorBrush(Color.FromArgb(255, 237, 240, 242));
                        break;
                }
                index2++; 
                newStyle.Setters.Add(new Setter(SeriesItemLabel.FillProperty, brush));
                newStyle.Setters.Add(new Setter(SeriesItemLabel.StrokeProperty, brush));
            }
     
        return newStyle;
    }


    Kind regards,
    Sia
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. DevCraft banner
  4. Aaron
    Aaron avatar
    14 posts
    Member since:
    Feb 2012

    Posted 13 Apr 2012 Link to this post

    Can changing the Pie Piece (BaseChartItem2D) Stroke/StrokeThickness be accomplished with a Style or Property in XAML? (in this answer it is set to Black in the code behind)
  5. Evgenia
    Admin
    Evgenia avatar
    1406 posts

    Posted 19 Apr 2012 Link to this post

    Hi Aaron,

    The approach suggested by my colleague Sia demonstrates how to change the Stroke. 
     

    newStyle.Setters.Add(new Setter(Shape.StrokeProperty, new SolidColorBrush(Colors.Black)));

    You'll just need to extend it to change the StrokeThickness. For example:

    newStyle.Setters.Add(new Setter(Shape.StrokeThicknessProperty, 2));

    Regards,
    Evgenia
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
  6. Aaron
    Aaron avatar
    14 posts
    Member since:
    Feb 2012

    Posted 19 Apr 2012 Link to this post

    I'm looking for a solution that applies the Style or sets the Property in XAML, not code behind.  Is that possible?
  7. Sia
    Admin
    Sia avatar
    667 posts

    Posted 24 Apr 2012 Link to this post

    Hello Aaron,

    You can use the exposed Appearance API as follows:
    <telerik:PieSeriesDefinition>
        <telerik:PieSeriesDefinition.Appearance>
            <telerik:SeriesAppearanceSettings Stroke="Black" StrokeThickness="1" />
        </telerik:PieSeriesDefinition.Appearance>
    </telerik:PieSeriesDefinition>

    I hope this helps.

    All the best,
    Sia
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Back to Top
DevCraft banner