Arc and Pie Chart
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.
Thanks,
Greg
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.
Code: Select all
<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>
Greg
- Attachments
-
- controls.7z
- (1.92 KiB) Downloaded 973 times
Re: Arc and Pie Chart
Amazing! Thanks for sharing!
Could you elaborate more on that issue?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.
Re: Arc and Pie Chart
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.
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.
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.
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.
Code: Select all
public ObservableCollection<PieSlice> _pieSlices = new ObservableCollection<PieSlice>();
public ObservableCollection<PieSlice> PieSlices
{
get
{
return _pieSlices;
}
set
{
_pieSlices = value;
}
}
Here is the code I am using for this.
Code: Select all
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); }
}
-
sfernandez
Site Admin
- Posts: 2991
- Joined:
Re: Arc and Pie Chart
Could you please create a user account in our bugtracker and report this bug, thanks.
Who is online
Users browsing this forum: No registered users and 15 guests