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

Black outline for Pie Chart and Custom Styles Delegate

5 Answers 89 Views
Chart
This is a migrated thread and some comments may be shown as answers.
Jeff Kershner
Top achievements
Rank 1
Jeff Kershner asked on 08 Sep 2010, 01:04 AM
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;
}

5 Answers, 1 is accepted

Sort by
0
Sia
Telerik team
answered on 09 Sep 2010, 12:26 PM
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
0
Aaron
Top achievements
Rank 1
answered on 14 Apr 2012, 04:07 AM
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)
0
Evgenia
Telerik team
answered on 19 Apr 2012, 10:54 AM
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 >>
0
Aaron
Top achievements
Rank 1
answered on 19 Apr 2012, 03:02 PM
I'm looking for a solution that applies the Style or sets the Property in XAML, not code behind.  Is that possible?
0
Sia
Telerik team
answered on 24 Apr 2012, 09:52 AM
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 >>

Tags
Chart
Asked by
Jeff Kershner
Top achievements
Rank 1
Answers by
Sia
Telerik team
Aaron
Top achievements
Rank 1
Evgenia
Telerik team
Share this question
or