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

2 posts, 0 answers
  1. Rob Ainscough
    Rob Ainscough avatar
    172 posts
    Member since:
    Jan 2010

    Posted 18 Jan 2012 Link to this post

    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

     
  2. Giuseppe
    Admin
    Giuseppe avatar
    2363 posts

    Posted 19 Jan 2012 Link to this post

    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 >>

  3. DevCraft banner
Back to Top