Created
March 3, 2019 07:53
-
-
Save Iyemon-018/dabe9aa3e6286a28dc2e4bc48912bc25 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Window x:Class="LiveCharts.Wpf.Example.MainWindow" | |
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | |
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | |
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | |
xmlns:local="clr-namespace:LiveCharts.Wpf.Example" | |
xmlns:lvc="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf" | |
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | |
Title="MainWindow" | |
Width="800" | |
Height="450" | |
mc:Ignorable="d"> | |
<Window.DataContext> | |
<local:MainWindowViewModel /> | |
</Window.DataContext> | |
<Grid> | |
<lvc:PieChart SeriesColors="{Binding SeriesColors, Mode=OneWay}" | |
LegendLocation="Left" | |
Series="{Binding Series}" | |
StartingRotationAngle="0" /> | |
</Grid> | |
</Window> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace LiveCharts.Wpf.Example | |
{ | |
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using Prism.Mvvm; | |
public class MainWindowViewModel : BindableBase | |
{ | |
public MainWindowViewModel() | |
{ | |
List<WorkTime> workTimes = new List<WorkTime> | |
{ | |
new WorkTime | |
{ | |
Date = DateTime.Today.AddDays(-3) | |
, ActualTime = 900 | |
} | |
, new WorkTime | |
{ | |
Date = DateTime.Today.AddDays(-3) | |
, ActualTime = 7200 | |
} | |
, new WorkTime | |
{ | |
Date = DateTime.Today.AddDays(-2) | |
, ActualTime = 1800 | |
} | |
, new WorkTime | |
{ | |
Date = DateTime.Today.AddDays(-2) | |
, ActualTime = 6000 | |
} | |
, new WorkTime | |
{ | |
Date = DateTime.Today.AddDays(-2) | |
, ActualTime = 7200 | |
} | |
}; | |
Series = new SeriesCollection(); | |
Series.AddRange(workTimes.GroupBy(x => x.Date) | |
.Select(x => new PieSeries | |
{ | |
Title = x.Key.ToString("yyyy/MM/dd") | |
, Values = new ChartValues<int>(new[] | |
{ | |
x.Sum(v => v.ActualTime) | |
}) | |
, DataLabels = true | |
, LabelPoint = p => $"{p.SeriesView.Title}{Environment.NewLine} {p.Participation:P}" | |
, FontSize = 18.0d | |
})); | |
SeriesColors = new ColorsCollection(); | |
SeriesColors.AddRange(new[] {"#FFE65100", "#FFEF6C00", "#FFF57C00", "#FFFB8C00", "#FFFF9800"} | |
.Select(System.Windows.Media.ColorConverter.ConvertFromString) | |
.OfType<System.Windows.Media.Color>() | |
.ToList()); | |
} | |
public SeriesCollection Series { get; } | |
public ColorsCollection SeriesColors { get; } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment