mirror of
https://gitee.com/akwkevin/aistudio.-wpf.-diagram
synced 2026-04-02 23:26:35 +08:00
项目结构调整
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
<Page
|
||||
x:Class="UWP.CartesianChart.CustomTooltipAndLegend.CustomTooltipAndLegendExample"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:local="using:UWP.CartesianChart.CustomTooltipAndLegend"
|
||||
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}">
|
||||
<lvc:CartesianChart LegendLocation="Right">
|
||||
<lvc:CartesianChart.Series>
|
||||
<lvc:ColumnSeries Title="2016 Customers" Values="{Binding Customers}"/>
|
||||
</lvc:CartesianChart.Series>
|
||||
<lvc:CartesianChart.AxisX >
|
||||
<lvc:Axis Labels="{Binding Labels}" LabelsRotation="-15">
|
||||
<lvc:Axis.Separator>
|
||||
<lvc:Separator Step="1"/>
|
||||
</lvc:Axis.Separator>
|
||||
</lvc:Axis>
|
||||
</lvc:CartesianChart.AxisX>
|
||||
<lvc:CartesianChart.DataTooltip>
|
||||
<local:CustomersTooltip/>
|
||||
</lvc:CartesianChart.DataTooltip>
|
||||
<lvc:CartesianChart.ChartLegend>
|
||||
<local:CustomersLegend/>
|
||||
</lvc:CartesianChart.ChartLegend>
|
||||
</lvc:CartesianChart>
|
||||
</Grid>
|
||||
</Page>
|
||||
@@ -0,0 +1,73 @@
|
||||
using LiveCharts;
|
||||
using LiveCharts.Configurations;
|
||||
using Windows.UI.Xaml.Controls;
|
||||
|
||||
// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238
|
||||
|
||||
namespace UWP.CartesianChart.CustomTooltipAndLegend
|
||||
{
|
||||
/// <summary>
|
||||
/// An empty page that can be used on its own or navigated to within a Frame.
|
||||
/// </summary>
|
||||
public sealed partial class CustomTooltipAndLegendExample : Page
|
||||
{
|
||||
public CustomTooltipAndLegendExample()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
Customers = new ChartValues<CustomerVm>
|
||||
{
|
||||
new CustomerVm
|
||||
{
|
||||
Name = "Irvin",
|
||||
LastName = "Hale",
|
||||
Phone = 123456789,
|
||||
PurchasedItems = 8
|
||||
},
|
||||
new CustomerVm
|
||||
{
|
||||
Name = "Malcolm",
|
||||
LastName = "Revees",
|
||||
Phone = 098765432,
|
||||
PurchasedItems = 3
|
||||
},
|
||||
new CustomerVm
|
||||
{
|
||||
Name = "Anne",
|
||||
LastName = "Rios",
|
||||
Phone = 758294026,
|
||||
PurchasedItems = 6
|
||||
},
|
||||
new CustomerVm
|
||||
{
|
||||
Name = "Vivian",
|
||||
LastName = "Howell",
|
||||
Phone = 309382739,
|
||||
PurchasedItems = 3
|
||||
},
|
||||
new CustomerVm
|
||||
{
|
||||
Name = "Caleb",
|
||||
LastName = "Roy",
|
||||
Phone = 682902826,
|
||||
PurchasedItems = 2
|
||||
}
|
||||
};
|
||||
|
||||
Labels = new[] { "Irvin", "Malcolm", "Anne", "Vivian", "Caleb" };
|
||||
|
||||
//let create a mapper so LiveCharts know how to plot our CustomerViewModel class
|
||||
var customerVmMapper = Mappers.Xy<CustomerVm>()
|
||||
.X((value, index) => index) // lets use the position of the item as X
|
||||
.Y(value => value.PurchasedItems); //and PurchasedItems property as Y
|
||||
|
||||
//lets save the mapper globally
|
||||
Charting.For<CustomerVm>(customerVmMapper);
|
||||
|
||||
DataContext = this;
|
||||
}
|
||||
|
||||
public ChartValues<CustomerVm> Customers { get; set; }
|
||||
public string[] Labels { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
namespace UWP.CartesianChart.CustomTooltipAndLegend
|
||||
{
|
||||
public class CustomerVm
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public string LastName { get; set; }
|
||||
public int Phone { get; set; }
|
||||
public int PurchasedItems { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<UserControl
|
||||
x:Class="UWP.CartesianChart.CustomTooltipAndLegend.CustomersLegend"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:local="using:UWP.CartesianChart.CustomTooltipAndLegend"
|
||||
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"
|
||||
d:DesignHeight="300"
|
||||
d:DesignWidth="400"
|
||||
>
|
||||
<Grid Background="#555555" BorderThickness="2" Padding="20 10" BorderBrush="AntiqueWhite">
|
||||
<ItemsControl ItemsSource="{x:Bind Series}">
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate x:DataType="lvc:SeriesViewModel">
|
||||
<Grid Margin="2">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Rectangle Grid.Column="0" Stroke="{Binding Stroke}" Fill="{Binding Fill}"
|
||||
Width="15" Height="15"/>
|
||||
<TextBlock Grid.Column="1" Margin="4 0" Text="{Binding Title}" Foreground="White" VerticalAlignment="Center" />
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
</ItemsControl.ItemTemplate>
|
||||
</ItemsControl>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
@@ -0,0 +1,39 @@
|
||||
using LiveCharts.Uwp;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using Windows.UI.Xaml.Controls;
|
||||
|
||||
// The User Control item template is documented at http://go.microsoft.com/fwlink/?LinkId=234236
|
||||
|
||||
namespace UWP.CartesianChart.CustomTooltipAndLegend
|
||||
{
|
||||
public sealed partial class CustomersLegend : UserControl, IChartLegend
|
||||
{
|
||||
private List<SeriesViewModel> _series;
|
||||
|
||||
public CustomersLegend()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
DataContext = this;
|
||||
}
|
||||
|
||||
public List<SeriesViewModel> Series
|
||||
{
|
||||
get { return _series; }
|
||||
set
|
||||
{
|
||||
_series = value;
|
||||
OnPropertyChanged("Series");
|
||||
}
|
||||
}
|
||||
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
public void OnPropertyChanged(string propertyName = null)
|
||||
{
|
||||
if (PropertyChanged != null)
|
||||
PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
<UserControl
|
||||
x:Class="UWP.CartesianChart.CustomTooltipAndLegend.CustomersTooltip"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:local="using:UWP.CartesianChart.CustomTooltipAndLegend"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:lvc="using:LiveCharts.Uwp"
|
||||
xmlns:converter="using:LiveCharts.Uwp.Converters"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="300"
|
||||
d:DesignWidth="400"
|
||||
>
|
||||
|
||||
<Grid Background="#E4555555" Padding="20 10" BorderThickness="2" BorderBrush="#555555">
|
||||
<Grid.Resources>
|
||||
<converter:StringFormatConverter x:Key="StringFormatConverter"/>
|
||||
</Grid.Resources>
|
||||
<ItemsControl ItemsSource="{Binding Data.Points}">
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate x:DataType="lvc:DataPointViewModel">
|
||||
<Grid Margin="2">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Rectangle Grid.Column="0" Stroke="{Binding Series.Stroke}" Fill="{Binding Series.Fill}"
|
||||
Height="15" Width="15"/>
|
||||
<TextBlock Grid.Column="1" Text="{Binding ChartPoint.Instance.Name}"
|
||||
Margin="5 0 0 0" VerticalAlignment="Center" Foreground="White"/>
|
||||
<TextBlock Grid.Column="2" Text="{Binding ChartPoint.Instance.LastName}"
|
||||
Margin="5 0 0 0" VerticalAlignment="Center" Foreground="White"/>
|
||||
<TextBlock Grid.Column="3" Text="{Binding ChartPoint.Instance.Phone, Converter={StaticResource StringFormatConverter}, ConverterParameter=Phone: \{0\}}"
|
||||
Margin="5 0 0 0" VerticalAlignment="Center" Foreground="White"/>
|
||||
<TextBlock Grid.Column="4" Text="{Binding ChartPoint.Instance.PurchasedItems, Converter={StaticResource StringFormatConverter}, ConverterParameter=Purchased Items: \{0:N\}}"
|
||||
Margin="5 0 0 0" VerticalAlignment="Center" Foreground="White"/>
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
</ItemsControl.ItemTemplate>
|
||||
</ItemsControl>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
@@ -0,0 +1,44 @@
|
||||
using LiveCharts;
|
||||
using LiveCharts.Uwp;
|
||||
using System.ComponentModel;
|
||||
using Windows.UI.Xaml.Controls;
|
||||
|
||||
// The User Control item template is documented at http://go.microsoft.com/fwlink/?LinkId=234236
|
||||
|
||||
namespace UWP.CartesianChart.CustomTooltipAndLegend
|
||||
{
|
||||
public sealed partial class CustomersTooltip : IChartTooltip
|
||||
{
|
||||
private TooltipData _data;
|
||||
|
||||
public CustomersTooltip()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
//LiveCharts will inject the tooltip data in the Data property
|
||||
//your job is only to display this data as required
|
||||
|
||||
DataContext = this;
|
||||
}
|
||||
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
public TooltipData Data
|
||||
{
|
||||
get { return _data; }
|
||||
set
|
||||
{
|
||||
_data = value;
|
||||
OnPropertyChanged("Data");
|
||||
}
|
||||
}
|
||||
|
||||
public TooltipSelectionMode SelectionMode { get; set; }
|
||||
|
||||
public void OnPropertyChanged(string propertyName = null)
|
||||
{
|
||||
if (PropertyChanged != null)
|
||||
PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user