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

5 posts, 0 answers
  1. Rob Ainscough
    Rob Ainscough avatar
    262 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. Jon Barrios
    Jon Barrios avatar
    2 posts
    Member since:
    Aug 2018

    Posted 11 Apr in reply to Giuseppe Link to this post

    Hi

     

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

  4. Jon Barrios
    Jon Barrios avatar
    2 posts
    Member since:
    Aug 2018

    Posted 11 Apr in reply to Jon Barrios Link to this post

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

    Another question can we use the predefined Palettes?

  5. Dinko
    Admin
    Dinko avatar
    897 posts

    Posted 16 Apr Link to this post

    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.
Back to Top