mirror of
https://gitee.com/akwkevin/aistudio.-wpf.-diagram
synced 2026-04-05 16:56:34 +08:00
项目结构调整
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
<Page
|
||||
x:Class="UWP.CartesianChart.GanttChart.GanttExample"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:local="using:UWP.CartesianChart.GanttChart"
|
||||
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>
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<Button Click="ResetZoomOnClick">Reset zoom</Button>
|
||||
<TextBlock Margin="10" TextWrapping="Wrap">Use your mouse wheel to zoom in/out, click hold and drag for panning</TextBlock>
|
||||
</StackPanel>
|
||||
<lvc:CartesianChart Grid.Row="1" Series="{Binding Series}" Zoom="X">
|
||||
<lvc:CartesianChart.AxisX>
|
||||
<lvc:Axis LabelFormatter="{Binding Formatter}"
|
||||
MinValue="{Binding From, Mode=TwoWay}"
|
||||
MaxValue="{Binding To, Mode=TwoWay}"></lvc:Axis>
|
||||
</lvc:CartesianChart.AxisX>
|
||||
<lvc:CartesianChart.AxisY>
|
||||
<lvc:Axis Labels="{Binding Labels}"></lvc:Axis>
|
||||
</lvc:CartesianChart.AxisY>
|
||||
</lvc:CartesianChart>
|
||||
</Grid>
|
||||
</Page>
|
||||
@@ -0,0 +1,104 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using Windows.UI.Xaml;
|
||||
using Windows.UI.Xaml.Controls;
|
||||
using LiveCharts;
|
||||
using LiveCharts.Defaults;
|
||||
using LiveCharts.Uwp;
|
||||
|
||||
// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238
|
||||
|
||||
namespace UWP.CartesianChart.GanttChart
|
||||
{
|
||||
/// <summary>
|
||||
/// An empty page that can be used on its own or navigated to within a Frame.
|
||||
/// </summary>
|
||||
public sealed partial class GanttExample : Page, INotifyPropertyChanged
|
||||
{
|
||||
private double _from;
|
||||
private double _to;
|
||||
private readonly ChartValues<GanttPoint> _values;
|
||||
|
||||
public GanttExample()
|
||||
{
|
||||
this.InitializeComponent();
|
||||
|
||||
var now = DateTime.Now;
|
||||
|
||||
_values = new ChartValues<GanttPoint>
|
||||
{
|
||||
new GanttPoint(now.Ticks, now.AddDays(2).Ticks),
|
||||
new GanttPoint(now.AddDays(1).Ticks, now.AddDays(3).Ticks),
|
||||
new GanttPoint(now.AddDays(3).Ticks, now.AddDays(5).Ticks),
|
||||
new GanttPoint(now.AddDays(5).Ticks, now.AddDays(8).Ticks),
|
||||
new GanttPoint(now.AddDays(6).Ticks, now.AddDays(10).Ticks),
|
||||
new GanttPoint(now.AddDays(7).Ticks, now.AddDays(14).Ticks),
|
||||
new GanttPoint(now.AddDays(9).Ticks, now.AddDays(12).Ticks),
|
||||
new GanttPoint(now.AddDays(9).Ticks, now.AddDays(14).Ticks),
|
||||
new GanttPoint(now.AddDays(10).Ticks, now.AddDays(11).Ticks),
|
||||
new GanttPoint(now.AddDays(12).Ticks, now.AddDays(16).Ticks),
|
||||
new GanttPoint(now.AddDays(15).Ticks, now.AddDays(17).Ticks),
|
||||
new GanttPoint(now.AddDays(18).Ticks, now.AddDays(19).Ticks)
|
||||
};
|
||||
|
||||
Series = new SeriesCollection
|
||||
{
|
||||
new RowSeries
|
||||
{
|
||||
Values = _values,
|
||||
DataLabels = true
|
||||
}
|
||||
};
|
||||
Formatter = value => new DateTime((long)value).ToString("dd MMM");
|
||||
|
||||
var labels = new List<string>();
|
||||
for (var i = 0; i < 12; i++)
|
||||
labels.Add("Task " + i);
|
||||
Labels = labels.ToArray();
|
||||
|
||||
ResetZoomOnClick(null, null);
|
||||
|
||||
DataContext = this;
|
||||
}
|
||||
|
||||
public SeriesCollection Series { get; set; }
|
||||
public Func<double, string> Formatter { get; set; }
|
||||
public string[] Labels { get; set; }
|
||||
|
||||
public double From
|
||||
{
|
||||
get { return _from; }
|
||||
set
|
||||
{
|
||||
_from = value;
|
||||
OnPropertyChanged("From");
|
||||
}
|
||||
}
|
||||
|
||||
public double To
|
||||
{
|
||||
get { return _to; }
|
||||
set
|
||||
{
|
||||
_to = value;
|
||||
OnPropertyChanged("To");
|
||||
}
|
||||
}
|
||||
|
||||
private void ResetZoomOnClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
From = _values.First().StartPoint;
|
||||
To = _values.Last().EndPoint;
|
||||
}
|
||||
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
private void OnPropertyChanged(string propertyName = null)
|
||||
{
|
||||
var handler = PropertyChanged;
|
||||
if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user