main
syneffort 1 year ago
parent 9171fa4a41
commit 8e4e12be6b
  1. 36
      LC_Tutorial/Tutorial/BasicPlots/DoughnutWindow.xaml
  2. 123
      LC_Tutorial/Tutorial/BasicPlots/DoughnutWindow.xaml.cs
  3. 1
      LC_Tutorial/Tutorial/MainWindow.xaml
  4. 6
      LC_Tutorial/Tutorial/MainWindow.xaml.cs

@ -0,0 +1,36 @@
<Window x:Class="Tutorial.BasicPlots.DoughnutWindow"
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:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:Tutorial.BasicPlots"
xmlns:lvc="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf"
mc:Ignorable="d"
Title="DoughnutWindow" Height="450" Width="800">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="30"/>
</Grid.RowDefinitions>
<lvc:PieChart Name="chtPie" Grid.Row="0" Series="{Binding SeriesCollection}" LegendLocation="Right" InnerRadius="100" Margin="0 15">
<lvc:PieChart.ChartLegend>
<lvc:DefaultLegend BulletSize="40"/>
</lvc:PieChart.ChartLegend>
<lvc:PieChart.DataTooltip>
<lvc:DefaultTooltip BulletSize="20"/>
</lvc:PieChart.DataTooltip>
</lvc:PieChart>
<StackPanel Grid.Row="1" Orientation="Horizontal">
<Button x:Name="btnUpdate" Content="Update" Click="btnUpdate_Click"/>
<Button x:Name="btnRestart" Content="Restart" Click="btnRestart_Click"/>
<TextBlock VerticalAlignment="Center" Padding="10 0" Text="Series"/>
<Button x:Name="btnAddSeries" Content="+" MinWidth="30" Click="btnAddSeries_Click"/>
<Button x:Name="btnRemoveSeries" Content="-" MinWidth="30" Click="btnRemoveSeries_Click"/>
<TextBlock VerticalAlignment="Center" Padding="10 0" Text="Value"/>
<Button x:Name="btnAddValue" Content="+" MinWidth="30" Click="btnAddValue_Click"/>
<Button x:Name="btnRemoveValue" Content="-" MinWidth="30" Click="btnRemoveValue_Click"/>
</StackPanel>
</Grid>
</Window>

@ -0,0 +1,123 @@
using LiveCharts;
using LiveCharts.Defaults;
using LiveCharts.Wpf;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
namespace Tutorial.BasicPlots
{
/// <summary>
/// DoughnutWindow.xaml에 대한 상호 작용 논리
/// </summary>
public partial class DoughnutWindow : Window
{
private int _index;
public SeriesCollection SeriesCollection { get; set; }
public DoughnutWindow()
{
InitializeComponent();
InitInstance();
}
private void InitInstance()
{
SeriesCollection = new SeriesCollection()
{
new PieSeries()
{
Title = "Chrome",
Values = new ChartValues<ObservableValue> { new ObservableValue(8) },
DataLabels = true,
},
new PieSeries()
{
Title = "FireFox",
Values = new ChartValues<ObservableValue> { new ObservableValue(6) },
DataLabels = true,
},
new PieSeries()
{
Title = "Opera",
Values = new ChartValues<ObservableValue> { new ObservableValue(10) },
DataLabels = true,
},
new PieSeries()
{
Title = "Edge",
Values = new ChartValues<ObservableValue> { new ObservableValue(20) },
DataLabels = true,
},
};
DataContext = this;
}
private void btnUpdate_Click(object sender, RoutedEventArgs e)
{
Random rand = new Random();
foreach (var series in SeriesCollection)
{
foreach (var observable in series.Values.Cast<ObservableValue>())
{
observable.Value = rand.Next(0, 20);
}
}
}
private void btnRestart_Click(object sender, RoutedEventArgs e)
{
chtPie.Update(true, true);
}
private void btnAddSeries_Click(object sender, RoutedEventArgs e)
{
Random rand = new Random();
int len = SeriesCollection.Count > 0 ? SeriesCollection[0].Values.Count : 5;
var vals = new ChartValues<ObservableValue>();
for (int i = 0; i < len; i++)
{
vals.Add(new ObservableValue(rand.Next(0, 10)));
}
SeriesCollection.Add(new PieSeries() { Values = vals, DataLabels = true, Title = $"Browser{++_index}" });
}
private void btnRemoveSeries_Click(object sender, RoutedEventArgs e)
{
if (SeriesCollection.Count > 0)
SeriesCollection.RemoveAt(SeriesCollection.Count - 1);
}
private void btnAddValue_Click(object sender, RoutedEventArgs e)
{
Random rand = new Random();
foreach (var series in SeriesCollection)
{
series.Values.Add(new ObservableValue(rand.Next(0, 10)));
}
}
private void btnRemoveValue_Click(object sender, RoutedEventArgs e)
{
foreach (var series in SeriesCollection)
{
if (series.Values.Count > 0)
series.Values.RemoveAt(series.Values.Count - 1);
}
}
}
}

@ -22,6 +22,7 @@
<Button x:Name="btnBubble" Content="Bubble" Margin="3" Click="btnBubble_Click"/>
<Button x:Name="btnFinancial" Content="Financial" Margin="3" Click="btnFinancial_Click"/>
<Button x:Name="btnPie" Content="Pie" Margin="3" Click="btnPie_Click"/>
<Button x:Name="btnDoughnut" Content="Doughnut" Margin="3" Click="btnDoughnut_Click"/>
</StackPanel>
</Grid>
</Window>

@ -85,5 +85,11 @@ namespace Tutorial
PieWindow win = new PieWindow();
win.Show();
}
private void btnDoughnut_Click(object sender, RoutedEventArgs e)
{
DoughnutWindow win = new DoughnutWindow();
win.Show();
}
}
}

Loading…
Cancel
Save