Page 1 of 1

Arc and Pie Chart

Posted: 17 Dec 2015, 19:52
by cosmo
Good Afternoon,

I had the need to build an arc control and pie chart control for my current project and figured I would share.

There is a lot more that could be done and I may update in the future with a legend for the pie chart and tool-tips.

Originally I was going to have the collection be a dependency property for the pie slices but there is an issue that I was unable to resolve with the dependency property when using noesis during the build process, but it dosen't seem important.

Here are examples of both.
<UserControl 
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
        xmlns:control="clr-namespace:Assets.BrightHue.Control;assembly=Nexus.Views"
        mc:Ignorable="d"
        Height="350" Width="525">
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition></ColumnDefinition>
            <ColumnDefinition></ColumnDefinition>
        </Grid.ColumnDefinitions>
        <control:PieChartControl Width="90" Height="90" Grid.Column="0">
            <control:PieChartControl.PieSlices>
                <control:PieSlice Color="Blue" Percent="60"></control:PieSlice>
                <control:PieSlice Color="Red" Percent="10"></control:PieSlice>
                <control:PieSlice Color="Black" Percent="40"></control:PieSlice>
            </control:PieChartControl.PieSlices>
        </control:PieChartControl>
        <control:ArcControl Height="60" Width="60" ArcWidth="90" Fill="Aquamarine" Direction="90" Grid.Column="1"/>
    </Grid>
</UserControl>
Thanks,
Greg

Re: Arc and Pie Chart

Posted: 21 Dec 2015, 08:02
by jsantos
Amazing! Thanks for sharing!
Originally I was going to have the collection be a dependency property for the pie slices but there is an issue that I was unable to resolve with the dependency property when using noesis during the build process, but it dosen't seem important.
Could you elaborate more on that issue?

Re: Arc and Pie Chart

Posted: 04 Jan 2016, 17:02
by cosmo
Ive been on a Christmas Holiday for the last few weeks. Here is what I ran into.

For the pie slice collection on the PieChartControl if I use a standard collection with a backing field everything works as expected. This can be seen as follows.
        public ObservableCollection<PieSlice> _pieSlices = new ObservableCollection<PieSlice>();


        public ObservableCollection<PieSlice> PieSlices
        {
            get
            {
                return _pieSlices;
            }
            set
            {
                _pieSlices = value;
            }
        }
If I use a dependency property for the for the collection instead I am getting an invalid cast exception that occurs. I am attempting to initialize the field from the FrameworkPropertyMetadata to a new ObservableCollection<PieSlice> but it appears that it is not happening as I expect it to as an invalid cast exception occurs during runtime. For non collection types it works as expected. But for a collection, at least a generic observable collection the underlying data type seems to be getting set wrong.

Here is the code I am using for this.
        public static DependencyProperty PieSlicesProperty =
            DependencyProperty.Register("PieSlices",
            typeof(ObservableCollection<PieSlice>),
            typeof(PieChartControl),
            new FrameworkPropertyMetadata(new ObservableCollection<PieSlice>()));

        public ObservableCollection<PieSlice> PieSlices
        {
            get { return GetValue(PieSlicesProperty) as ObservableCollection<PieSlice>; }
            set { SetValue(PieSlicesProperty, value); }
        }
It has no real effect on my project having the collection as a dependency property but I can see instances where it would be an issue.

Re: Arc and Pie Chart

Posted: 07 Jan 2016, 13:09
by sfernandez
Could you please create a user account in our bugtracker and report this bug, thanks.