Skip to content

Commit

Permalink
Create ChartPie
Browse files Browse the repository at this point in the history
  • Loading branch information
yanjinhuagood committed Jul 24, 2024
1 parent 72c619b commit e2632a8
Show file tree
Hide file tree
Showing 8 changed files with 374 additions and 0 deletions.
40 changes: 40 additions & 0 deletions src/WPFDevelopers.Samples.Shared/ExampleViews/ChartPieExample.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<UserControl
x:Class="WPFDevelopers.Samples.ExampleViews.ChartPieExample"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="clr-namespace:WPFDevelopers.Samples.Controls"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:WPFDevelopers.Samples.ExampleViews"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:wd="https://github.com/WPFDevelopersOrg/WPFDevelopers"
d:DesignHeight="450"
d:DesignWidth="800"
mc:Ignorable="d">
<controls:CodeViewer>
<Grid Background="{DynamicResource WD.BackgroundSolidColorBrush}">
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">
<Border
Height="300"
Margin="30,0"
Background="{DynamicResource WD.BackgroundSolidColorBrush}">
<wd:ChartPie Datas="{Binding Datas, RelativeSource={RelativeSource AncestorType=local:ChartPieExample}}" />
</Border>
</ScrollViewer>
<Button
Grid.Row="1"
Width="200"
VerticalAlignment="Bottom"
Click="Button_Click"
Content="刷新"
Style="{StaticResource WD.PrimaryButton}" />
</Grid>
<controls:CodeViewer.SourceCodes>
<controls:SourceCodeModel CodeSource="/WPFDevelopers.SamplesCode;component/ExampleViews/ChartPieExample.xaml" CodeType="Xaml" />
<controls:SourceCodeModel CodeSource="/WPFDevelopers.SamplesCode;component/ExampleViews/ChartPieExample.xaml.cs" CodeType="CSharp" />
</controls:CodeViewer.SourceCodes>
</controls:CodeViewer>
</UserControl>
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Net.NetworkInformation;
using System.Windows;
using System.Windows.Controls;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.Rebar;

namespace WPFDevelopers.Samples.ExampleViews
{
/// <summary>
/// ChartPieExample.xaml 的交互逻辑
/// </summary>
public partial class ChartPieExample : UserControl
{
public IEnumerable<KeyValuePair<string, double>> Datas
{
get { return (IEnumerable<KeyValuePair<string, double>>)GetValue(DatasProperty); }
set { SetValue(DatasProperty, value); }
}

public static readonly DependencyProperty DatasProperty =
DependencyProperty.Register("Datas", typeof(IEnumerable<KeyValuePair<string, double>>), typeof(ChartPieExample), new PropertyMetadata(null));

private Dictionary<string, IEnumerable<KeyValuePair<string, double>>> keyValues = new Dictionary<string, IEnumerable<KeyValuePair<string, double>>>();
private int _index = 0;
public ChartPieExample()
{
InitializeComponent();
var models1 = new[]
{
new KeyValuePair<string, double>("Mon", 120),
new KeyValuePair<string, double>("Tue", 530),
new KeyValuePair<string, double>("Wed", 1060),
new KeyValuePair<string, double>("Thu", 140),
new KeyValuePair<string, double>("Fri", 8000.123456) ,
new KeyValuePair<string, double>("Sat", 200) ,
new KeyValuePair<string, double>("Sun", 300) ,
};
var models2 = new[]
{
new KeyValuePair<string, double>("Bing", 120),
new KeyValuePair<string, double>("Google", 170),
new KeyValuePair<string, double>("Baidu", 30),
new KeyValuePair<string, double>("Github", 200),
new KeyValuePair<string, double>("Stack Overflow", 100) ,
new KeyValuePair<string, double>("Runoob", 180) ,
new KeyValuePair<string, double>("Open AI", 90) ,
new KeyValuePair<string, double>("Open AI2", 93) ,
new KeyValuePair<string, double>("Open AI3", 94) ,
new KeyValuePair<string, double>("Open AI4", 95) ,
};
keyValues.Add("1", models1);
keyValues.Add("2", models2);
Datas = models1;
}

private void Button_Click(object sender, RoutedEventArgs e)
{
_index++;
if (_index >= keyValues.Count)
{
_index = 0;
}
Datas = keyValues.ToList()[_index].Value;
}
}
}
1 change: 1 addition & 0 deletions src/WPFDevelopers.Samples.Shared/Helpers/MenuEnum.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ public enum MenuEnum
WaterfallPanel,
ChartLine,
Drap,
ChartPie,
VirtualizingWrapPanel,
AcrylicBlur,
TaskbarInfo
Expand Down
3 changes: 3 additions & 0 deletions src/WPFDevelopers.Samples.Shared/ViewModels/MainVM.cs
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,9 @@ void MenuItemSelection(string _menuName)
case MenuEnum.Drap:
ControlPanel = new DrapViewExample();
break;
case MenuEnum.ChartPie:
ControlPanel = new ChartPieExample();
break;
case MenuEnum.VirtualizingWrapPanel:
ControlPanel = new VirtualizingWrapPanel();
new VirtualizingWrapPanelExample().MaskShowDialog();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@
<Compile Include="$(MSBuildThisFileDirectory)ExampleViews\ChartLineExample.xaml.cs">
<DependentUpon>ChartLineExample.xaml</DependentUpon>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)ExampleViews\ChartPieExample.xaml.cs">
<DependentUpon>ChartPieExample.xaml</DependentUpon>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)ExampleViews\ChatEmojiExample.xaml.cs">
<SubType>Code</SubType>
<DependentUpon>ChatEmojiExample.xaml</DependentUpon>
Expand Down Expand Up @@ -584,6 +587,10 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="$(MSBuildThisFileDirectory)ExampleViews\ChartPieExample.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="$(MSBuildThisFileDirectory)ExampleViews\ChatEmojiExample.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@
<Resource Include="..\WPFDevelopers.Samples.Shared\ExampleViews\TimePickerExample.xaml.cs" Link="ExampleViews\TimePickerExample.xaml.cs" DependentUpon="TimePickerExample.xaml" />
<Resource Include="..\WPFDevelopers.Samples.Shared\ExampleViews\WaterfallPanelExample.xaml.cs" Link="ExampleViews\WaterfallPanelExample.xaml.cs" DependentUpon="WaterfallPanelExample.xaml" />
<Resource Include="..\WPFDevelopers.Samples.Shared\ExampleViews\ChartLineExample.xaml.cs" Link="ExampleViews\ChartLineExample.xaml.cs" DependentUpon="ChartLineExample.xaml" />
<Resource Include="..\WPFDevelopers.Samples.Shared\ExampleViews\ChartPieExample.xaml.cs" Link="ExampleViews\ChartPieExample.xaml.cs" DependentUpon="ChartPieExample.xaml" />
</ItemGroup>
<ItemGroup>
<Resource Include="..\WPFDevelopers.Samples.Shared\ExampleViews\AboutWindow.xaml">
Expand Down Expand Up @@ -488,5 +489,8 @@
<Resource Include="..\WPFDevelopers.Samples.Shared\ExampleViews\ChartLineExample.xaml">
<Link>ExampleViews\ChartLineExample.xaml</Link>
</Resource>
<Resource Include="..\WPFDevelopers.Samples.Shared\ExampleViews\ChartPieExample.xaml">
<Link>ExampleViews\ChartPieExample.xaml</Link>
</Resource>
</ItemGroup>
</Project>
Loading

0 comments on commit e2632a8

Please sign in to comment.