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

Set Color of RadChartItem by its Value

1 Answer 71 Views
Chart
This is a migrated thread and some comments may be shown as answers.
Bhaskar Khaund
Top achievements
Rank 1
Bhaskar Khaund asked on 29 Nov 2010, 07:59 AM
Hi,

I am using a RadChart in my silvelight application, and I am using a 2-d pie-chart. I need to set the color of the item based in its value.

My current code is:

 

var series = new DataSeries();
var myDataSource = <my data source>;
var pointCount = 0;
DataPoint point = null;
  
RiskChartArea.PaletteBrushes.Add(new SolidBrushColor(Colors.Red));
RiskChartArea.PaletteBrushes.Add(new SolidBrushColor(Colors.Blue));
RiskChartArea.PaletteBrushes.Add(new SolidBrushColor(Colors.Green));
RiskChartArea.PaletteBrushes.Add(new SolidBrushColor(Colors.Black));
RiskChartArea.PaletteBrushes.Add(new SolidBrushColor(Colors.Yellow));
              
myCollection.ToList().ForEach(x =>
{
                pointCount = openItem.Where(y => y["Status"].GetString().Equals(x.Code, StringComparison.CurrentCultureIgnoreCase)).Count();
                point = new DataPoint(pointCount);
                point.LegendLabel = x.Code;
                point.Tooltip = x.Code;
                series.Add(point);
});
  
DataSeries doughnutSeries = series;
doughnutSeries.LegendLabel = "Doughnut Series";
doughnutSeries.Definition = new DoughnutSeriesDefinition();
doughnutSeries.Definition.InteractivitySettings.HoverScope = InteractivityScope.Item;
doughnutSeries.Definition.InteractivitySettings.SelectionScope = InteractivityScope.Item;
doughnutSeries.Definition.InteractivitySettings.SelectionMode = ChartSelectionMode.Single;
  
((DoughnutSeriesDefinition)doughnutSeries.Definition).LabelSettings.LabelOffset = 0.7d;
//doughnutSeries.Definition.ItemLabelFormat = "#%{p0}";
MyChartArea.DataSeries.Clear();
MyChartArea.DataSeries.Add(doughnutSeries);
MyChartArea.SmartLabelsEnabled = false;
MyChartLegend.Header = " ";


What I want is, if the value of the DataPoint is "ABC", I wnat its slice red in color, and if its valye is "XYZ" I wnat its slice to be green in color.

Can you please help me, how can I acheive this?

Regards,
Bhaskar

1 Answer, 1 is accepted

Sort by
0
Ves
Telerik team
answered on 01 Dec 2010, 08:15 AM
Hi Bhaskar Khaund,

You can find a similar example here. While the example does not specifically address the requirement for a pie chart, it demonstrates how to achieve conditional fill settings for each item within the chart.

Here is an example of a pie slice template:

<ControlTemplate TargetType="telerikCharting:Pie">
    <Canvas x:Name="PART_MainContainer">
        <Ellipse Clip="{TemplateBinding FigurePath}"
             Width="{TemplateBinding ItemActualWidth}"
         Height="{TemplateBinding ItemActualHeight}"
         StrokeThickness="0"
         Style="{TemplateBinding ItemStyle}" />
        <Path x:Name="PART_DefiningGeometry"
            Data="{TemplateBinding FigurePath2}"
        Fill="Transparent"
        Style="{TemplateBinding ItemStyle}" />
    <Ellipse Clip="{TemplateBinding FigurePath3}"
         Fill="{Binding DataItem.MyColor}"
         Width="{TemplateBinding ItemActualWidth}"
         Height="{TemplateBinding ItemActualHeight}" />
    </Canvas>
</ControlTemplate>


Best regards,
Ves
the Telerik team
Browse the videos here>> to help you get started with RadControls for Silverlight
Tags
Chart
Asked by
Bhaskar Khaund
Top achievements
Rank 1
Answers by
Ves
Telerik team
Share this question
or