mirror of
https://gitee.com/akwkevin/aistudio.-wpf.-diagram
synced 2026-04-12 12:16:37 +08:00
项目结构调整
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
<UserControl x:Class="Wpf.CartesianChart.Labels.LabelsExample"
|
||||
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"
|
||||
xmlns:labels="clr-namespace:Wpf.CartesianChart.Labels"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="300" d:DesignWidth="300" d:DataContext="{d:DesignInstance labels:LabelsExample}">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"></RowDefinition>
|
||||
<RowDefinition Height="Auto"></RowDefinition>
|
||||
<RowDefinition Height="*"></RowDefinition>
|
||||
</Grid.RowDefinitions>
|
||||
<TextBlock>Labels</TextBlock>
|
||||
<Button Grid.Row="1" Height="30" Click="UpdateAllOnClick">
|
||||
Move All
|
||||
</Button>
|
||||
<lvc:CartesianChart Grid.Row="2" Series="{Binding SeriesCollection}"
|
||||
DataClick="Chart_OnDataClick">
|
||||
<lvc:CartesianChart.AxisX>
|
||||
<lvc:Axis LabelsRotation="20" Labels="{Binding Labels}" Position="LeftBottom" >
|
||||
<lvc:Axis.Separator >
|
||||
<lvc:Separator Step="1"></lvc:Separator>
|
||||
</lvc:Axis.Separator>
|
||||
</lvc:Axis>
|
||||
</lvc:CartesianChart.AxisX>
|
||||
<lvc:CartesianChart.AxisY>
|
||||
<lvc:Axis Title="Sold Items" LabelFormatter="{Binding Formatter}" Position="RightTop"></lvc:Axis>
|
||||
</lvc:CartesianChart.AxisY>
|
||||
</lvc:CartesianChart>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
@@ -0,0 +1,82 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using LiveCharts;
|
||||
using LiveCharts.Defaults;
|
||||
using LiveCharts.Wpf;
|
||||
|
||||
namespace Wpf.CartesianChart.Labels
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for BarExample.xaml
|
||||
/// </summary>
|
||||
public partial class LabelsExample : UserControl
|
||||
{
|
||||
public LabelsExample()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
SeriesCollection = new SeriesCollection
|
||||
{
|
||||
new ColumnSeries
|
||||
{
|
||||
Values = new ChartValues<ObservableValue>
|
||||
{
|
||||
new ObservableValue(4),
|
||||
new ObservableValue(2),
|
||||
new ObservableValue(8),
|
||||
new ObservableValue(2),
|
||||
new ObservableValue(3),
|
||||
new ObservableValue(0),
|
||||
new ObservableValue(1),
|
||||
},
|
||||
DataLabels = true,
|
||||
LabelPoint = point => point.X + "K ," + point.Y
|
||||
}
|
||||
};
|
||||
|
||||
Labels = new[]
|
||||
{
|
||||
"Shea Ferriera",
|
||||
"Maurita Powel",
|
||||
"Scottie Brogdon",
|
||||
"Teresa Kerman",
|
||||
"Nell Venuti",
|
||||
"Anibal Brothers",
|
||||
"Anderson Dillman"
|
||||
};
|
||||
|
||||
Formatter = value => value + ".00K items";
|
||||
|
||||
DataContext = this;
|
||||
}
|
||||
|
||||
public SeriesCollection SeriesCollection { get; set; }
|
||||
public string[] Labels { get; set; }
|
||||
public Func<double, string> Formatter { 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(0, 10);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void Chart_OnDataClick(object sender, ChartPoint point)
|
||||
{
|
||||
//point instance contains many useful information...
|
||||
//sender is the shape that called the event.
|
||||
|
||||
MessageBox.Show("You clicked " + point.X + ", " + point.Y);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<UserControl x:Class="Wpf.CartesianChart.Labels.LabelsHorizontalExample"
|
||||
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.Labels"
|
||||
xmlns:wpf="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>Labels</TextBlock>
|
||||
<Button Grid.Row="1" Height="30" Click="UpdateAllOnClick">
|
||||
Move All
|
||||
</Button>
|
||||
<wpf:CartesianChart Grid.Row="2" Series="{Binding SeriesCollection}">
|
||||
<wpf:CartesianChart.DataTooltip>
|
||||
<wpf:DefaultTooltip SelectionMode="SharedYValues"></wpf:DefaultTooltip>
|
||||
</wpf:CartesianChart.DataTooltip>
|
||||
<wpf:CartesianChart.AxisX>
|
||||
<wpf:Axis Title="Sold Items" LabelFormatter="{Binding Formatter}"></wpf:Axis>
|
||||
</wpf:CartesianChart.AxisX>
|
||||
<wpf:CartesianChart.AxisY>
|
||||
<wpf:Axis Labels="{Binding Labels}" LabelsRotation="65">
|
||||
<wpf:Axis.Separator >
|
||||
<wpf:Separator Step="1"></wpf:Separator>
|
||||
</wpf:Axis.Separator>
|
||||
</wpf:Axis>
|
||||
</wpf:CartesianChart.AxisY>
|
||||
</wpf:CartesianChart>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
@@ -0,0 +1,75 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Media;
|
||||
using LiveCharts;
|
||||
using LiveCharts.Defaults;
|
||||
using LiveCharts.Wpf;
|
||||
|
||||
namespace Wpf.CartesianChart.Labels
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for LabelsHorizontalExample.xaml
|
||||
/// </summary>
|
||||
public partial class LabelsHorizontalExample : UserControl
|
||||
{
|
||||
public LabelsHorizontalExample()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
SeriesCollection = new SeriesCollection
|
||||
{
|
||||
new RowSeries
|
||||
{
|
||||
Values = new ChartValues<ObservableValue>
|
||||
{
|
||||
new ObservableValue(4),
|
||||
new ObservableValue(2),
|
||||
new ObservableValue(8),
|
||||
new ObservableValue(2),
|
||||
new ObservableValue(3),
|
||||
new ObservableValue(0),
|
||||
new ObservableValue(1),
|
||||
},
|
||||
DataLabels = true,
|
||||
LabelPoint = point => point.X + "K ," + point.Y
|
||||
}
|
||||
};
|
||||
|
||||
Labels = new[]
|
||||
{
|
||||
"Shea Ferriera",
|
||||
"Maurita Powel",
|
||||
"Scottie Brogdon",
|
||||
"Teresa Kerman",
|
||||
"Nell Venuti",
|
||||
"Anibal Brothers",
|
||||
"Anderson Dillman"
|
||||
};
|
||||
|
||||
Formatter = value => value + ".00K items";
|
||||
|
||||
DataContext = this;
|
||||
}
|
||||
|
||||
public SeriesCollection SeriesCollection { get; set; }
|
||||
public string[] Labels { get; set; }
|
||||
public Func<double, string> Formatter { 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(0, 10);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user