InteractiveDataDisplay曲线图控件的使用

发布时间 2023-07-11 20:10:47作者: wzwyc

官网

https://github.com/microsoft/InteractiveDataDisplay.WPF

安装

Install-Package InteractiveDataDisplay.WPF

前台代码

 

<Window
    x:Class="InteractiveDataDisplayDemo.MainWindow"
    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:d3="clr-namespace:InteractiveDataDisplay.WPF;assembly=InteractiveDataDisplay.WPF"
    xmlns:local="clr-namespace:InteractiveDataDisplayDemo"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    Title="MainWindow"
    Width="800"
    Height="450"
    mc:Ignorable="d">
    <Grid>
        <d3:Chart BottomTitle="Argument" LeftTitle="Function">
            <d3:LineGraph
                x:Name="linegraph"
                Description="Simple linegraph"
                Stroke="Blue"
                StrokeThickness="3" />
        </d3:Chart>
    </Grid>
</Window>

 

后台代码

using System;
using System.Linq;
using System.Windows;

namespace InteractiveDataDisplayDemo
{
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();

            var x = Enumerable.Range(0, 1001).Select(i => i / 10.0).ToArray();
            var y = x.Select(v => Math.Abs(v) < 1e-10 ? 1 : Math.Sin(v) / v).ToArray();
            linegraph.Plot(x, y); // x and y are IEnumerable<double>
        }
    }
}

运行效果