项目结构调整

This commit is contained in:
艾竹
2023-04-16 20:11:40 +08:00
parent cbfbf96033
commit 81f91f3f35
2124 changed files with 218 additions and 5516 deletions

View File

@@ -0,0 +1,30 @@
<UserControl x:Class="Wpf.CartesianChart.StackedArea.StackedAreaExample"
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:local="clr-namespace:Wpf.CartesianChart"
xmlns:lvc="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<StackPanel Orientation="Horizontal" Grid.Row="1">
<Button Height="30" Click="ChangeStackModeOnClick" Width="120" Margin="10 0">
Change StackMode
</Button>
</StackPanel>
<lvc:CartesianChart Grid.Row="2" Series="{Binding SeriesCollection}" LegendLocation="Right">
<lvc:CartesianChart.AxisX>
<lvc:Axis Title="Year" LabelFormatter="{Binding XFormatter}"></lvc:Axis>
</lvc:CartesianChart.AxisX>
<lvc:CartesianChart.AxisY>
<lvc:Axis Title="Population" LabelFormatter="{Binding YFormatter}"></lvc:Axis>
</lvc:CartesianChart.AxisY>
</lvc:CartesianChart>
</Grid>
</UserControl>

View File

@@ -0,0 +1,140 @@
using System;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Windows;
using System.Windows.Controls;
using LiveCharts;
using LiveCharts.Defaults;
using LiveCharts.Wpf;
using Wpf.Annotations;
namespace Wpf.CartesianChart.StackedArea
{
/// <summary>
/// Interaction logic for StackedLine.xaml
/// </summary>
public partial class StackedAreaExample : INotifyPropertyChanged
{
private Func<double, string> _yFormatter;
public StackedAreaExample()
{
InitializeComponent();
SeriesCollection = new SeriesCollection
{
new StackedAreaSeries
{
Title = "Africa",
Values = new ChartValues<DateTimePoint>
{
new DateTimePoint(new DateTime(1950, 1, 1), .228),
new DateTimePoint(new DateTime(1960, 1, 1), .285),
new DateTimePoint(new DateTime(1970, 1, 1), .366),
new DateTimePoint(new DateTime(1980, 1, 1), .478),
new DateTimePoint(new DateTime(1990, 1, 1), .629),
new DateTimePoint(new DateTime(2000, 1, 1), .808),
new DateTimePoint(new DateTime(2010, 1, 1), 1.031),
new DateTimePoint(new DateTime(2013, 1, 1), 1.110)
},
LineSmoothness = 0
},
new StackedAreaSeries
{
Title = "N & S America",
Values = new ChartValues<DateTimePoint>
{
new DateTimePoint(new DateTime(1950, 1, 1), .339),
new DateTimePoint(new DateTime(1960, 1, 1), .424),
new DateTimePoint(new DateTime(1970, 1, 1), .519),
new DateTimePoint(new DateTime(1980, 1, 1), .618),
new DateTimePoint(new DateTime(1990, 1, 1), .727),
new DateTimePoint(new DateTime(2000, 1, 1), .841),
new DateTimePoint(new DateTime(2010, 1, 1), .942),
new DateTimePoint(new DateTime(2013, 1, 1), .972)
},
LineSmoothness = 0
},
new StackedAreaSeries
{
Title = "Asia",
Values = new ChartValues<DateTimePoint>
{
new DateTimePoint(new DateTime(1950, 1, 1), 1.395),
new DateTimePoint(new DateTime(1960, 1, 1), 1.694),
new DateTimePoint(new DateTime(1970, 1, 1), 2.128),
new DateTimePoint(new DateTime(1980, 1, 1), 2.634),
new DateTimePoint(new DateTime(1990, 1, 1), 3.213),
new DateTimePoint(new DateTime(2000, 1, 1), 3.717),
new DateTimePoint(new DateTime(2010, 1, 1), 4.165),
new DateTimePoint(new DateTime(2013, 1, 1), 4.298)
},
LineSmoothness = 0
},
new StackedAreaSeries
{
Title = "Europe",
Values = new ChartValues<DateTimePoint>
{
new DateTimePoint(new DateTime(1950, 1, 1), .549),
new DateTimePoint(new DateTime(1960, 1, 1), .605),
new DateTimePoint(new DateTime(1970, 1, 1), .657),
new DateTimePoint(new DateTime(1980, 1, 1), .694),
new DateTimePoint(new DateTime(1990, 1, 1), .723),
new DateTimePoint(new DateTime(2000, 1, 1), .729),
new DateTimePoint(new DateTime(2010, 1, 1), .740),
new DateTimePoint(new DateTime(2013, 1, 1), .742)
},
LineSmoothness = 0
}
};
XFormatter = val => new DateTime((long) val).ToString("yyyy");
YFormatter = val => val.ToString("N") + " M";
DataContext = this;
}
public SeriesCollection SeriesCollection { get; set; }
public Func<double, string> XFormatter { get; set; }
public Func<double, string> YFormatter
{
get { return _yFormatter; }
set
{
_yFormatter = value;
OnPropertyChanged();
}
}
public StackMode StackMode { get; set; }
private void ChangeStackModeOnClick(object sender, RoutedEventArgs e)
{
foreach (var series in SeriesCollection.Cast<StackedAreaSeries>())
{
series.StackMode = series.StackMode == StackMode.Percentage
? StackMode.Values
: StackMode.Percentage;
}
if (((StackedAreaSeries) SeriesCollection[0]).StackMode == StackMode.Values)
{
YFormatter = val => val.ToString("N") + " M";
}
else
{
YFormatter = val => val.ToString("P");
}
}
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged(string propertyName = null)
{
if (PropertyChanged != null) PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
}

View File

@@ -0,0 +1,29 @@
<UserControl x:Class="Wpf.CartesianChart.StackedArea.VerticalStackedAreaExample"
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:local="clr-namespace:Wpf.CartesianChart.StackedArea"
xmlns:lvc="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" TextWrapping="Wrap">
<Bold>New in 0.7.0</Bold> use VerticalStackedAreaSeries or StackedAreaSeries classes, depending on your needs, this series also supports 2 different stack modes: Percentage and Values <LineBreak/>
</TextBlock>
<StackPanel Orientation="Horizontal" Grid.Row="1">
<Button Height="30" Click="UpdateAllOnClick" Width="100">
Move All
</Button>
<Button Height="30" Click="ChangeStackModeOnClick" Width="120" Margin="10 0">
Change StackMode
</Button>
</StackPanel>
<lvc:CartesianChart Grid.Row="2" Series="{Binding SeriesCollection}" LegendLocation="Right"/>
</Grid>
</UserControl>

View File

@@ -0,0 +1,97 @@
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.Navigation;
using System.Windows.Shapes;
using LiveCharts;
using LiveCharts.Defaults;
using LiveCharts.Wpf;
namespace Wpf.CartesianChart.StackedArea
{
/// <summary>
/// Interaction logic for VerticalStackedAreaExample.xaml
/// </summary>
public partial class VerticalStackedAreaExample : UserControl
{
public VerticalStackedAreaExample()
{
InitializeComponent();
SeriesCollection = new SeriesCollection
{
new VerticalStackedAreaSeries
{
Values = new ChartValues<ObservableValue>
{
new ObservableValue(5),
new ObservableValue(3),
new ObservableValue(6),
new ObservableValue(2)
},
DataLabels = true
},
new VerticalStackedAreaSeries
{
Values = new ChartValues<ObservableValue>
{
new ObservableValue(4),
new ObservableValue(1),
new ObservableValue(7),
new ObservableValue(9)
},
DataLabels = true
},
new VerticalStackedAreaSeries
{
Values = new ChartValues<ObservableValue>
{
new ObservableValue(2),
new ObservableValue(8),
new ObservableValue(2),
new ObservableValue(9)
},
DataLabels = true
}
};
DataContext = this;
}
public SeriesCollection SeriesCollection { get; set; }
public StackMode StackMode { get; set; }
private void UpdateAllOnClick(object sender, RoutedEventArgs e)
{
var r = new Random();
foreach (var series in SeriesCollection)
{
foreach (var observable in series.Values.Cast<ObservableValue>())
{
observable.Value = r.Next(1, 10);
}
}
}
private void ChangeStackModeOnClick(object sender, RoutedEventArgs e)
{
foreach (var series in SeriesCollection.Cast<VerticalStackedAreaSeries>())
{
series.StackMode = series.StackMode == StackMode.Percentage
? StackMode.Values
: StackMode.Percentage;
}
}
}
}