mirror of
https://gitee.com/akwkevin/aistudio.-wpf.-diagram
synced 2026-04-06 01:06:37 +08:00
项目结构调整
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
<UserControl x:Class="Wpf.CartesianChart.DateAxis.DateAxisExample"
|
||||
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: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="Auto"></RowDefinition>
|
||||
<RowDefinition Height="Auto"></RowDefinition>
|
||||
<RowDefinition Height="*"></RowDefinition>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<TextBlock Background="#FFC107" HorizontalAlignment="Right" Padding="10 5" FontWeight="Bold">Experimental</TextBlock>
|
||||
|
||||
<StackPanel Grid.Row="1">
|
||||
<Label>Set `DateAxis.InitialDateTime` to configure the starting point (X=0) dateTime.</Label>
|
||||
<Label>Configure the DateAxis.Period to the PeriodUnit of your axis values. Use the buttons below to configure this property for the X axis.</Label>
|
||||
</StackPanel>
|
||||
|
||||
<StackPanel Grid.Row="2" Orientation="Horizontal">
|
||||
<Button Click="SetMilliSecondPeriod">
|
||||
Millisecond
|
||||
</Button>
|
||||
<Button Click="SetSecondPeriod">
|
||||
Second
|
||||
</Button>
|
||||
<Button Click="SetMinutePeriod">
|
||||
Minute
|
||||
</Button>
|
||||
<Button Click="SetHourPeriod">
|
||||
Hour
|
||||
</Button>
|
||||
<Button Click="SetDayPeriod">
|
||||
Day
|
||||
</Button>
|
||||
</StackPanel>
|
||||
|
||||
<StackPanel Grid.Row="3" Orientation="Horizontal">
|
||||
<Label Content="Series Period: "></Label>
|
||||
<Label Content="{Binding Period}"></Label>
|
||||
<Label Content="Seperator window: "></Label>
|
||||
<Label Content="{Binding SelectedWindow, Mode=TwoWay}"></Label>
|
||||
</StackPanel>
|
||||
|
||||
<lvc:CartesianChart Zoom="X" Grid.Row="4" DisableAnimations="False" Series="{Binding SeriesCollection}">
|
||||
<lvc:CartesianChart.AxisX>
|
||||
<lvc:DateAxis
|
||||
MinValue="0"
|
||||
MaxValue="60"
|
||||
Foreground="DarkSlateBlue"
|
||||
HeaderForeground="Black"
|
||||
Period="{Binding Period, Mode=TwoWay}"
|
||||
ShowLabels="True"
|
||||
SelectedWindow="{Binding SelectedWindow, Mode=TwoWay}"
|
||||
InitialDateTime="{Binding InitialDateTime}">
|
||||
<lvc:DateAxis.Separator>
|
||||
<lvc:Separator StrokeThickness="10" Stroke="Black"/>
|
||||
</lvc:DateAxis.Separator>
|
||||
</lvc:DateAxis>
|
||||
</lvc:CartesianChart.AxisX>
|
||||
</lvc:CartesianChart>
|
||||
|
||||
</Grid>
|
||||
</UserControl>
|
||||
@@ -0,0 +1,104 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Media;
|
||||
using LiveCharts;
|
||||
using LiveCharts.Defaults;
|
||||
using LiveCharts.Helpers;
|
||||
using LiveCharts.Wpf;
|
||||
|
||||
namespace Wpf.CartesianChart.DateAxis
|
||||
{
|
||||
public partial class DateAxisExample : UserControl, INotifyPropertyChanged
|
||||
{
|
||||
private DateTime _initialDateTime;
|
||||
|
||||
private PeriodUnits _period = PeriodUnits.Days;
|
||||
private IAxisWindow _selectedWindow;
|
||||
|
||||
public DateAxisExample()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
var now = DateTime.UtcNow;
|
||||
InitialDateTime = new DateTime(now.Year, now.Month, now.Day);
|
||||
|
||||
SeriesCollection = new SeriesCollection
|
||||
{
|
||||
new LineSeries
|
||||
{
|
||||
Title = "Series 1",
|
||||
Values = new ChartValues<double> { 4, 6, 5, 2 ,7, 8, 2, 0, 3, 5, 2, 4, 6, 4, 7, 3, 10, 4, 1, 2, 5, 8, 4, 6, 2, 4, 8, 7, 5, 4, 3, 2, 5, 6, 5, 3, 6, 4, 6, 3, 4, 1, 4, 2, 3, 2, 3, 5, 8, 6, 8, 4, 2, 4, 1, 2, 5, 6, 4, 6, 5, 2 ,7, 8, 2, 0, 3, 5, 2, 4, 6, 4, 7, 3, 10, 4, 1, 2, 5, 8, 4, 6, 2, 4, 8, 7, 5, 4, 3, 2, 5, 6, 5, 3, 6, 4, 6, 3, 4, 1, 4, 2, 3, 2, 3, 5, 8, 6, 8, 4, 2, 4, 1, 2, 5, 6 },
|
||||
},
|
||||
};
|
||||
|
||||
DataContext = this;
|
||||
}
|
||||
|
||||
public SeriesCollection SeriesCollection { get; set; }
|
||||
|
||||
public DateTime InitialDateTime
|
||||
{
|
||||
get { return _initialDateTime; }
|
||||
set
|
||||
{
|
||||
_initialDateTime = value;
|
||||
OnPropertyChanged("InitialDateTime");
|
||||
}
|
||||
}
|
||||
|
||||
public PeriodUnits Period
|
||||
{
|
||||
get { return _period; }
|
||||
set
|
||||
{
|
||||
_period = value;
|
||||
OnPropertyChanged("Period");
|
||||
}
|
||||
}
|
||||
|
||||
public IAxisWindow SelectedWindow
|
||||
{
|
||||
get { return _selectedWindow; }
|
||||
set
|
||||
{
|
||||
_selectedWindow = value;
|
||||
OnPropertyChanged("SelectedWindow");
|
||||
}
|
||||
}
|
||||
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
protected virtual void OnPropertyChanged(string propertyName = null)
|
||||
{
|
||||
if (PropertyChanged != null) PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||
}
|
||||
|
||||
private void SetDayPeriod(object sender, RoutedEventArgs e)
|
||||
{
|
||||
Period = PeriodUnits.Days;
|
||||
}
|
||||
|
||||
private void SetHourPeriod(object sender, RoutedEventArgs e)
|
||||
{
|
||||
Period = PeriodUnits.Hours;
|
||||
}
|
||||
|
||||
private void SetMinutePeriod(object sender, RoutedEventArgs e)
|
||||
{
|
||||
Period = PeriodUnits.Minutes;
|
||||
}
|
||||
|
||||
private void SetSecondPeriod(object sender, RoutedEventArgs e)
|
||||
{
|
||||
Period = PeriodUnits.Seconds;
|
||||
}
|
||||
|
||||
private void SetMilliSecondPeriod(object sender, RoutedEventArgs e)
|
||||
{
|
||||
Period = PeriodUnits.Milliseconds;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user