hi i'm newer in telerik and i would like to know how to set the color of the pie chart.
the best for me is binding the color using series
for example if i have a class ValuePieChart with the following properties
legend color value
cats white 12
dog red 19
rubbit black 2
i would like to have a pie white/red/black colored.
this is my code in the xaml
and this in the code behind
Can anyone help me?
thx from Italy
the best for me is binding the color using series
for example if i have a class ValuePieChart with the following properties
legend color value
cats white 12
dog red 19
rubbit black 2
i would like to have a pie white/red/black colored.
this is my code in the xaml
<telerikChart:RadChart Width="Auto" Height="Auto" x:Name="RadChartPie" Background="{x:Null}" Style="{StaticResource RadChartPieStyle}" /> |
and this in the code behind
public partial class UCStatistics : UserControl |
{ |
public UCStatistics() |
{ |
// Required to initialize variables |
InitializeComponent(); |
this.FillSampleChartData(); |
} |
private void FillSampleChartData() |
{ |
ValuePieChart v1 = new ValuePieChart("non riuscito", 30, this.Resources["strokeBrushPie1"] as LinearGradientBrush); |
ValuePieChart v2 = new ValuePieChart("attivo", 30, this.Resources["strokeBrushPie2"] as LinearGradientBrush); |
ValuePieChart v3 = new ValuePieChart("riuscito", 40, this.Resources["strokeBrushPie3"] as LinearGradientBrush); |
List<ValuePieChart> series = new List<ValuePieChart>(); |
series.Add(v1); series.Add(v2); series.Add(v3); |
PieSeriesDefinition seriesDefinition = new PieSeriesDefinition(); |
seriesDefinition.ShowItemToolTips = true; |
seriesDefinition.LabelOffset = 0.5; |
seriesDefinition.Appearance.Stroke = this.Resources["strokeBrushPie"] as LinearGradientBrush; |
//seriesDefinition.Appearance.Fill = |
RadChartPie.DefaultView.ChartArea.SeriesStyles = new SeriesStyles(); |
RadChartPie.DefaultSeriesDefinition = seriesDefinition; |
SeriesMapping seriesMapping = new SeriesMapping(); |
seriesMapping.SeriesDefinition = seriesDefinition; |
ItemMapping itemMapping = new ItemMapping(); |
itemMapping.DataPointMember = DataPointMember.LegendLabel; |
itemMapping.FieldName = "legend"; |
seriesMapping.ItemMappings.Add(itemMapping); |
ItemMapping itemMapping2 = new ItemMapping(); |
itemMapping2.DataPointMember = DataPointMember.YValue; |
itemMapping2.FieldName = "value"; |
seriesMapping.ItemMappings.Add(itemMapping2); |
RadChartPie.SeriesMappings.Add(seriesMapping); |
RadChartPie.ItemsSource = series; |
} |
} |
public class ValuePieChart |
{ |
public string legend {get; set;} |
public int value { get; set; } |
public Brush color { get; set; } |
public ValuePieChart(string l, int v, Brush c) |
{ |
this.legend = l; |
this.value = v; |
this.color = c; |
} |
} |
Can anyone help me?
thx from Italy