mirror of
https://gitee.com/akwkevin/aistudio.-wpf.-diagram
synced 2026-03-20 16:36:36 +08:00
添加项目文件。
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
using System;
|
||||
|
||||
namespace Wpf.CartesianChart.Using_DateTime
|
||||
{
|
||||
public class DateModel
|
||||
{
|
||||
public System.DateTime DateTime { get; set; }
|
||||
public double Value { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
<UserControl x:Class="Wpf.CartesianChart.Using_DateTime.DateTime"
|
||||
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>
|
||||
<lvc:CartesianChart Series="{Binding Series}">
|
||||
<lvc:CartesianChart.AxisX>
|
||||
<lvc:Axis LabelFormatter="{Binding Formatter}"></lvc:Axis>
|
||||
</lvc:CartesianChart.AxisX>
|
||||
</lvc:CartesianChart>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
@@ -0,0 +1,74 @@
|
||||
using System;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Media;
|
||||
using LiveCharts;
|
||||
using LiveCharts.Configurations;
|
||||
using LiveCharts.Wpf;
|
||||
|
||||
namespace Wpf.CartesianChart.Using_DateTime
|
||||
{
|
||||
public partial class DateTime : UserControl
|
||||
{
|
||||
public DateTime()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
var dayConfig = Mappers.Xy<DateModel>()
|
||||
.X(dayModel => (double) dayModel.DateTime.Ticks/TimeSpan.FromHours(1).Ticks)
|
||||
.Y(dayModel => dayModel.Value);
|
||||
|
||||
//Notice you can also configure this type globally, so you don't need to configure every
|
||||
//SeriesCollection instance using the type.
|
||||
//more info at http://lvcharts.net/App/Index#/examples/v1/wpf/Types%20and%20Configuration
|
||||
|
||||
Series = new SeriesCollection(dayConfig)
|
||||
{
|
||||
new LineSeries
|
||||
{
|
||||
Values = new ChartValues<DateModel>
|
||||
{
|
||||
new DateModel
|
||||
{
|
||||
DateTime = System.DateTime.Now,
|
||||
Value = 5
|
||||
},
|
||||
new DateModel
|
||||
{
|
||||
DateTime = System.DateTime.Now.AddHours(2),
|
||||
Value = 9
|
||||
}
|
||||
},
|
||||
Fill = Brushes.Transparent
|
||||
},
|
||||
new ColumnSeries
|
||||
{
|
||||
Values = new ChartValues<DateModel>
|
||||
{
|
||||
new DateModel
|
||||
{
|
||||
DateTime = System.DateTime.Now,
|
||||
Value = 4
|
||||
},
|
||||
new DateModel
|
||||
{
|
||||
DateTime = System.DateTime.Now.AddHours(1),
|
||||
Value = 6
|
||||
},
|
||||
new DateModel
|
||||
{
|
||||
DateTime = System.DateTime.Now.AddHours(2),
|
||||
Value = 8
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Formatter = value => new System.DateTime((long) (value*TimeSpan.FromHours(1).Ticks)).ToString("t");
|
||||
|
||||
DataContext = this;
|
||||
}
|
||||
|
||||
public Func<double, string> Formatter { get; set; }
|
||||
public SeriesCollection Series { get; set; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user