添加项目文件。

This commit is contained in:
akwkevin
2021-07-23 09:42:22 +08:00
commit f25a958797
2798 changed files with 352360 additions and 0 deletions

View File

@@ -0,0 +1,30 @@
<UserControl x:Class="Wpf.CartesianChart.GanttChart.GanttExample"
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.GanttChart"
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="*"></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>
</UserControl>

View File

@@ -0,0 +1,102 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using LiveCharts;
using LiveCharts.Defaults;
using LiveCharts.Wpf;
namespace Wpf.CartesianChart.GanttChart
{
/// <summary>
/// Interaction logic for GanttExample.xaml
/// </summary>
public partial class GanttExample : UserControl, INotifyPropertyChanged
{
private double _from;
private double _to;
private readonly ChartValues<GanttPoint> _values;
public GanttExample()
{
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;
protected virtual void OnPropertyChanged(string propertyName = null)
{
var handler = PropertyChanged;
if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
}
}
}