项目结构调整

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,28 @@
<Page
x:Class="UWP.CartesianChart.StackedArea.StackedAreaExample"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:UWP.CartesianChart.StackedArea"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:lvc="using:LiveCharts.Uwp"
mc:Ignorable="d">
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<Button Height="30" Click="ChangeStackModeOnClick" HorizontalAlignment="Stretch" Margin="10 0">
Change StackMode
</Button>
<lvc:CartesianChart Grid.Row="1" 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>
</Page>

View File

@@ -0,0 +1,141 @@
using LiveCharts;
using LiveCharts.Defaults;
using LiveCharts.Uwp;
using System;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238
namespace UWP.CartesianChart.StackedArea
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class StackedAreaExample : Page, 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;
public void OnPropertyChanged([CallerMemberName]string propertyName = null)
{
if (PropertyChanged != null) PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
}

View File

@@ -0,0 +1,30 @@
<Page
x:Class="UWP.CartesianChart.StackedArea.VerticalStackedAreaExample"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:UWP.CartesianChart.StackedArea"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:lvc="using:LiveCharts.Uwp"
mc:Ignorable="d">
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<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>
</Page>

View File

@@ -0,0 +1,88 @@
using LiveCharts;
using LiveCharts.Defaults;
using LiveCharts.Uwp;
using System;
using System.Linq;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238
namespace UWP.CartesianChart.StackedArea
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class VerticalStackedAreaExample : Page
{
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;
}
}
}
}