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

Ok, I give up on PieChart colors, code samples don't work?

4 Answers 268 Views
Chart
This is a migrated thread and some comments may be shown as answers.
Rob Ainscough
Top achievements
Rank 1
Rob Ainscough asked on 18 Jan 2012, 09:05 PM
Do PieChart colors just NOT work in Q3 2011??

I followed this example here

Sample code:
<chart:RadPieChart x:Name="PieChart" Palette="{Binding Palette}" Grid.Row="1">
 
       <chartView:PieSeries ValueBinding="Value" ItemsSource="{Binding Data}" RadiusFactor="0.77">
           <chartView:PieSeries.LabelDefinitions>
               <chartView:ChartSeriesLabelDefinition Margin="-30,0,0,0" />
           </chartView:PieSeries.LabelDefinitions>
           <chartView:PieSeries.AngleRange>
               <charting:AngleRange StartAngle="270" SweepAngle="360" />
           </chartView:PieSeries.AngleRange>
       </chartView:PieSeries>
 
   </chart:RadPieChart>

My code:

xmlns:telerikChart="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Charting"
xmlns:chart="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Chart"
xmlns:charting="clr-namespace:Telerik.Charting;assembly=Telerik.Windows.Controls.Chart"
xmlns:chartView="clr-namespace:Telerik.Windows.Controls.ChartView;assembly=Telerik.Windows.Controls.Chart"
 
 
   <chart:RadPieChart x:Name="TestChart" Grid.Column="1" Margin="8" Grid.Row="1" Palette="{Binding Palette}">
 
        <chartView:PieSeries DataContext="{Binding Source={StaticResource UnitsDelinquentChartData}}" ItemsSource="{Binding Collection}" ValueBinding="PercentValue">
             
        </chartView:PieSeries>
         
    </chart:RadPieChart>

What I get is an ALL blue pie chart (binding works fine), the representation of the data is correct 80% slice and a 20% slice, but both slices are blue.

I've tried using the PaletteBrushes but all I get is "Attachable property 'PaletteBrushes' was not found in type RadPieChart.

So how the heck do I set pie chart slice colors for Q3 2011??

I know when I use the Microsoft PieSeries control it takes about 1000 lines of code just to adjust the pie slice color, I was hoping Telerik controls would be MUCH more simple?

Rob

 

4 Answers, 1 is accepted

Sort by
0
Giuseppe
Telerik team
answered on 19 Jan 2012, 09:45 AM
Hello Rob,

It seems you are mixing up our two charting solutions -- the robust and mature RadChart control and the next-generation performant RadChartView control (currently in BETA, becomes official in Q1 2012). While both controls solve similar problems, the design concepts used in RadChart / RadChartView are different and the API is different as well.

The PaletteBrushes mechanism works as expected in RadChart (example can be found here), while the equivalent functionality can be achieved with ChartPalette instance in RadChartView like this:

XAML
<UserControl x:Class="SilverlightApplication15.MainPage"
    xmlns:local="clr-namespace:SilverlightApplication15"
    mc:Ignorable="d"
    d:DesignHeight="300" d:DesignWidth="400">
     
    <UserControl.DataContext>
        <local:ViewModel />
    </UserControl.DataContext>
 
    <Grid x:Name="LayoutRoot" Background="White">
 
        <telerik:RadPieChart x:Name="PieChart" Palette="{Binding Palette}" Grid.Row="1">
 
            <telerik:PieSeries ValueBinding="Value" ItemsSource="{Binding Data}" RadiusFactor="0.77">
                <telerik:PieSeries.LabelDefinitions>
                    <telerik:ChartSeriesLabelDefinition Margin="-30,0,0,0" />
                </telerik:PieSeries.LabelDefinitions>
                <telerik:PieSeries.AngleRange>
                    <telerik:AngleRange StartAngle="270" SweepAngle="360" />
                </telerik:PieSeries.AngleRange>
            </telerik:PieSeries>
 
        </telerik:RadPieChart>
 
    </Grid>
</UserControl>

C#
using System.Collections.Generic;
using System.Windows.Controls;
using System.Windows.Media;
using Telerik.Windows.Controls;
using Telerik.Windows.Controls.ChartView;
 
namespace SilverlightApplication15
{
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();
        }
    }
 
    public class ViewModel : ViewModelBase
    {
        public ViewModel()
        {
            ChartPalette palette = new ChartPalette();
            palette.GlobalEntries.Add(new PaletteEntry(new SolidColorBrush(Colors.Red), new SolidColorBrush(Colors.White)));
            palette.GlobalEntries.Add(new PaletteEntry(new SolidColorBrush(Colors.Green), new SolidColorBrush(Colors.White)));
            palette.GlobalEntries.Add(new PaletteEntry(new SolidColorBrush(Colors.Blue), new SolidColorBrush(Colors.White)));
            palette.GlobalEntries.Add(new PaletteEntry(new SolidColorBrush(Colors.Gray), new SolidColorBrush(Colors.White)));
 
            this.Palette = palette;
 
            List<ChartData> data = new List<ChartData>();
            data.Add(new ChartData() { Value = 1 });
            data.Add(new ChartData() { Value = 2 });
            data.Add(new ChartData() { Value = 5 });
            data.Add(new ChartData() { Value = 11 });
 
            this.Data = data;
        }
 
        public List<ChartData> Data
        {
            get;
            set;
        }
 
        public ChartPalette Palette
        {
            get;
            set;
        }
    }
 
    public class ChartData
    {
        public string Category
        {
            get;
            set;
        }
 
        public double Value
        {
            get;
            set;
        }
    }
}



Greetings,
Giuseppe
the Telerik team

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

0
n/a
Top achievements
Rank 1
answered on 11 Apr 2019, 08:18 AM

Hi

 

Did you manage to solve this issue? I have the same problem

0
n/a
Top achievements
Rank 1
answered on 11 Apr 2019, 08:23 AM

Almost the same issue, I'm adding the PieChart from code in my WPF application.

Another question can we use the predefined Palettes?

0
Dinko | Tech Support Engineer
Telerik team
answered on 16 Apr 2019, 07:32 AM
Hi Jon,

I have tested your approach by adding the PieChart from code behind and the chart is visualized as expected. May I ask you to share how you are adding the chart from code behind? Also, are you using NoXAML binaries? Attached to this reply you can find the WPF sample project which I used to test your scenario. Can you take a look at it and let me know how my implementation is different from yours.

Regarding your second question. The answer is yes, you can use the predefined pellets by setting the Palette property of the PieChart. More information about this can be found in the Palletes section of our documentation of RadChartView.

Regards,
Dinko
Progress Telerik
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
Chart
Asked by
Rob Ainscough
Top achievements
Rank 1
Answers by
Giuseppe
Telerik team
n/a
Top achievements
Rank 1
Dinko | Tech Support Engineer
Telerik team
Share this question
or