Commit ed182e01 authored by 潘栩锋's avatar 潘栩锋 🚴

测试

parent 32c09b3f
<?xml version="1.0" encoding="utf-8" ?>
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.2" />
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1"/>
</startup>
</configuration>
\ No newline at end of file
</configuration>
......@@ -2,7 +2,7 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WpfApp1"
StartupUri="MainWindow.xaml">
StartupUri="ColumnRangeExample.xaml">
<Application.Resources>
</Application.Resources>
......
<Window x:Class="WpfApp1.ColumnRangeExample"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:lvc="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf"
xmlns:local="clr-namespace:WpfApp1"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Grid >
<lvc:CartesianChart x:Name="chart" Series="{Binding SeriesCollection}" LegendLocation="Left"
DisableAnimations="True" Hoverable="False" DataTooltip="{x:Null}">
<lvc:CartesianChart.AxisX>
<lvc:Axis MinValue="{Binding XMin}" MaxValue="{Binding XMax}"></lvc:Axis>
</lvc:CartesianChart.AxisX>
<lvc:CartesianChart.AxisY>
<lvc:Axis Title="Sold Apps" LabelFormatter="{Binding Formatter}"></lvc:Axis>
</lvc:CartesianChart.AxisY>
</lvc:CartesianChart>
<StackPanel Orientation="Vertical" HorizontalAlignment="Left" Background="#08000000" VerticalAlignment="Top">
<StackPanel Orientation="Horizontal" Margin="5">
<TextBlock Text="XMin"/>
<TextBox Text="{Binding XMin}"/>
</StackPanel>
<StackPanel Orientation="Horizontal" Margin="5">
<TextBlock Text="XMax"/>
<TextBox Text="{Binding XMax}"/>
</StackPanel>
<StackPanel Orientation="Horizontal" Margin="5">
<TextBlock Text="运行中"/>
<TextBlock Text="{Binding IsRunning,Mode=OneWay}"/>
</StackPanel>
<Button Content="Update" Width="80" Padding="5" Click="Button_Click"/>
</StackPanel>
</Grid>
</Window>
\ No newline at end of file
using LiveCharts;
using LiveCharts.Configurations;
using LiveCharts.Defaults;
using LiveCharts.Wpf;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Windows.Threading;
namespace WpfApp1
{
/// <summary>
/// Window1.xaml 的交互逻辑
/// </summary>
public partial class ColumnRangeExample : Window
{
ColumnRangeExampleViewModel viewModel;
public ColumnRangeExample()
{
InitializeComponent();
viewModel = new ColumnRangeExampleViewModel();
viewModel.Init();
this.DataContext = viewModel;
}
private void Button_Click(object sender, RoutedEventArgs e)
{
if (viewModel.IsRunning)
viewModel.Stop();
else
viewModel.Start();
}
}
public class ColumnRangeExampleViewModel : INotifyPropertyChanged
{
DispatcherTimer timer;
public SeriesCollection SeriesCollection { get; set; }
public Func<double, string> Formatter { get; set; }
public double XMin { get; set; } = double.NaN;
public double XMax { get; set; } = double.NaN;
public bool IsRunning { get; private set; }
List<double> datas = new List<double>();
List<Bolt> boltmap = new List<Bolt>();
ChartValues<BoltValue> BoltValues = new ChartValues<BoltValue>();
ChartValues<double> Values = new ChartValues<double>();
public void Update()
{
Random random = new Random();
double[] datas2 = new double[datas.Count()];
for (int i = 0; i < datas.Count(); i++)
{
datas2[i] = datas[i] + (random.NextDouble() - 0.5) * 1;
}
//把其中一部分数据变为无效
int null_value_pos = random.Next(1000);
for (int i = 0; i < 100; i++)
{
int index = null_value_pos - 50 + i;
if (index < 0)
index += datas2.Count();
else if (index >= datas2.Count())
index -= datas2.Count();
datas2[index] = double.NaN;
}
//-----------------------------------------------------------
//转显示数据
List<BoltValue> boltValues = new List<BoltValue>();
foreach (Bolt bolt in boltmap)
{
IEnumerable<double> a = datas2.Skip(bolt.Begin - 1).Take(bolt.End - bolt.Begin + 1);
a = from d in a where !double.IsNaN(d) select d;
double v;
if (a.Count() > 0)
v = a.Average();
else
v = double.NaN;
boltValues.Add(new BoltValue(bolt.Begin, bolt.End, v));
}
BoltValues.Clear();
Values.Clear();
BoltValues.AddRange(boltValues);
Values.AddRange(datas2);
}
public void Init()
{
//-----------------------------------------------------------
//模拟数据
double target = 150;
double tolerance = 2;
Random random = new Random();
for (int i = 0; i < 1000; i++)
{
double d = Math.Sin(Math.PI * 2 * i / 350) * tolerance + (random.NextDouble() - 0.5) * 0.3 + target;
datas.Add(d);
}
//平均分为8份
double width = datas.Count() / 23;
int begin = 0;
while (true)
{
int end = (int)(begin + width);
if (end >= datas.Count())
end = datas.Count() - 1;
boltmap.Add(new Bolt(begin, end));
if (end == datas.Count()-1)
break;
begin = end;
}
boltmap[2].End = (boltmap[3].End + boltmap[3].Begin) / 2;
SeriesCollection = new SeriesCollection
{
new LineSeries
{
Title = "Line",
Values = Values,
StrokeThickness = 2,
Stroke = new SolidColorBrush(System.Windows.Media.Colors.Blue),
Fill = new SolidColorBrush(System.Windows.Media.Colors.Transparent),
PointGeometry = null,
},
new ColumnRangeSeries
{
Title = "ColumnRange",
Values = BoltValues,
StrokeThickness = 2,
Stroke = new SolidColorBrush(System.Windows.Media.Colors.DarkRed),
Fill = new SolidColorBrush(System.Windows.Media.Color.FromArgb(0x80, 0xff,0,0)),
DataLabels = true,
YAxisCrossing = 150,
Configuration = Mappers.Weighted<BoltValue>()
.X(b=>(b.From + b.To)/2)
.Weight(b=> Math.Abs(b.From-b.To))
.Y(b=>b.Value)
}
};
Formatter = value => value.ToString("N");
XMin = 100;
XMax = 900;
//-----------------------------------------------------------
//转显示数据
Update();
timer = new DispatcherTimer();
timer.Interval = TimeSpan.FromSeconds(1);
timer.Tick += Timer_Tick;
}
public void Start()
{
IsRunning = true;
timer.Start();
}
public void Stop()
{
IsRunning = false;
timer.Stop();
}
private void Timer_Tick(object sender, EventArgs e)
{
Update();
}
public event PropertyChangedEventHandler PropertyChanged;
}
public class BoltValue : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
public double Value { get; set; }
public double From { get; set; }
public double To { get; set; }
public BoltValue() { }
public BoltValue(double from, double to, double value)
{
From = from;
To = to;
Value = value;
}
}
public class Bolt
{
public int Begin;
public int End;
public Bolt(int b, int e)
{
Begin = b;
End = e;
}
}
}
//------------------------------------------------------------------------------
// <auto-generated>
// 此代码由工具生成。
// 运行时版本: 4.0.30319.42000
// 运行时版本:4.0.30319.42000
//
// 对此文件的更改可能导致不正确的行为,如果
// 重新生成代码,则所做更改将丢失。
// 对此文件的更改可能会导致不正确的行为,并且如果
// 重新生成代码,这些更改将会丢失。
// </auto-generated>
//------------------------------------------------------------------------------
namespace WpfApp1.Properties
{
namespace WpfApp1.Properties {
using System;
/// <summary>
/// 强类型资源类,用于查找本地化字符串等。
/// 一个强类型的资源类,用于查找本地化的字符串等。
/// </summary>
// 此类是由 StronglyTypedResourceBuilder
// 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。
// 若要添加或除成员,请编辑 .ResX 文件,然后重新运行 ResGen
// 若要添加或除成员,请编辑 .ResX 文件,然后重新运行 ResGen
// (以 /str 作为命令选项),或重新生成 VS 项目。
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "15.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resources
{
internal class Resources {
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal Resources()
{
internal Resources() {
}
/// <summary>
/// 返回此类使用的缓存 ResourceManager 实例。
/// 返回此类使用的缓存 ResourceManager 实例。
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager
{
get
{
if ((resourceMan == null))
{
internal static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("WpfApp1.Properties.Resources", typeof(Resources).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// 覆盖当前线程的 CurrentUICulture 属性
/// 使用此强类型的资源类的资源查找
/// 重写当前线程的 CurrentUICulture 属性
/// 重写当前线程的 CurrentUICulture 属性
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture
{
get
{
internal static global::System.Globalization.CultureInfo Culture {
get {
return resourceCulture;
}
set
{
set {
resourceCulture = value;
}
}
......
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
// 此代码由工具生成。
// 运行时版本:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// 对此文件的更改可能会导致不正确的行为,并且如果
// 重新生成代码,这些更改将会丢失。
// </auto-generated>
//------------------------------------------------------------------------------
namespace WpfApp1.Properties
{
namespace WpfApp1.Properties {
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase
{
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "15.9.0.0")]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
public static Settings Default
{
get
{
public static Settings Default {
get {
return defaultInstance;
}
}
......
......@@ -9,7 +9,7 @@
<OutputType>WinExe</OutputType>
<RootNamespace>WpfApp1</RootNamespace>
<AssemblyName>WpfApp1</AssemblyName>
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<WarningLevel>4</WarningLevel>
......@@ -17,6 +17,7 @@
<Deterministic>true</Deterministic>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
......@@ -61,6 +62,9 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</ApplicationDefinition>
<Compile Include="ColumnRangeExample.xaml.cs">
<DependentUpon>ColumnRangeExample.xaml</DependentUpon>
</Compile>
<Page Include="MainWindow.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
......@@ -73,6 +77,10 @@
<DependentUpon>MainWindow.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Page Include="ColumnRangeExample.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs">
......@@ -119,6 +127,9 @@
<Name>WpfView</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Resource Include="FodyWeavers.xml" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="..\packages\Fody.3.3.2\build\Fody.targets" Condition="Exists('..\packages\Fody.3.3.2\build\Fody.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment