WPF DynamicDataDisplay 画曲线图求助

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了WPF DynamicDataDisplay 画曲线图求助相关的知识,希望对你有一定的参考价值。

DynamicDataDisplay 的曲线图控件如何能够在曲线图的基础上 填充颜色如上图效果,对DynamicDataDisplay不是很熟悉,资料少 求助各位了

参考技术A 画直线试试,虽然我不知道对应函数,但肯定也是这么画出来的
一个小循环,x从左边界到右边界,y值对应取0和f(x),假设从a到b
for(int x=a;x<=b;x++)

PointF p1=new PointF((float)x,0);

PointF p2=new PointF((float)x,f(x)-1);
这样根据这两个点画彩色直线就可以了

参考技术B 需要修改源代码,DynamicDataDisplay不提供这样的区域填充功能。
看看MarkerPointsGraph文件,里面有遍历所有点,画点形状的代码,你可以在那里添加这样的填充

WPF中使用DynamicDataDisplay画直方图应该怎么做

参考技术A 1.后台程序:加载一条随即曲线,横轴为时间

using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Text;
using System.Windows;
using System.IO;
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.Navigation;
using System.Windows.Shapes;
using System.Globalization;
using System.Diagnostics;
using System.Windows.Threading;
using Microsoft.Research.DynamicDataDisplay;
using Microsoft.Research.DynamicDataDisplay.DataSources;
using Microsoft.Research.DynamicDataDisplay.PointMarkers;
using Microsoft.Research.DynamicDataDisplay.Charts.Navigation;

namespace WpfApplication2


public partial class MainWindow : Window

Random random = new Random();
private DispatcherTimer timer = new DispatcherTimer();
CompositeDataSource compositeDataSource1;
CompositeDataSource compositeDataSource2;

EnumerableDataSource<DateTime> datesDataSource = null;
EnumerableDataSource<int> numberOpenDataSource=null;
EnumerableDataSource<int> numberClosedDataSource = null;

List<DateTime> vardatetime = new List<DateTime>();
int i = 0;

List<int> numberOpen = new List<int>();
List<int> numberClosed = new List<int>();
/*
int[] numberOpen = new int[100];
int[] numberClosed = new int[100];
*/

public MainWindow()

InitializeComponent();

// Loaded += new RoutedEventHandler(Window_Loaded);


private void Window1_Loaded(object sender, EventArgs e)


DateTime tempDateTime = new DateTime();
tempDateTime = DateTime.Now;

vardatetime.Add(tempDateTime);

numberOpen.Add(random.Next(40));
numberClosed.Add(random.Next(100));

datesDataSource.RaiseDataChanged();
numberOpenDataSource.RaiseDataChanged();
numberClosedDataSource.RaiseDataChanged();

i++;

// Window1_Loaded()
private void Window_Loaded(object sender, System.Windows.RoutedEventArgs e)


DateTime tempDateTime=new DateTime();

tempDateTime = DateTime.Now;
vardatetime.Add(tempDateTime);

numberOpen.Add(random.Next(40));
numberClosed.Add(random.Next(100));

i++;

datesDataSource = new EnumerableDataSource<DateTime>(vardatetime);
datesDataSource.SetXMapping(x => dateAxis.ConvertToDouble(x));

numberOpenDataSource = new EnumerableDataSource<int>(numberOpen);
numberOpenDataSource.SetYMapping(y => y);

numberClosedDataSource = new EnumerableDataSource<int>(numberClosed);
numberClosedDataSource.SetYMapping(y => y);

compositeDataSource1 = new CompositeDataSource(datesDataSource, numberOpenDataSource);
compositeDataSource2 = new CompositeDataSource(datesDataSource, numberClosedDataSource);

plotter.AddLineGraph(compositeDataSource2, Colors.Green, 1, "Percentage2");
plotter.Viewport.FitToView();

timer.Interval = TimeSpan.FromSeconds(1);
timer.Tick += new EventHandler(Window1_Loaded);
timer.IsEnabled = true;


// class Window1


2.前台展示程序

<Window x:Class="WpfApplication2.MainWindow"
xmlns=
xmlns:x=
xmlns:d3=
Title="Window1" Loaded="Window_Loaded" WindowState="Normal" Height="800" Width="1280" Background="Wheat">

<Grid>
<d3:ChartPlotter Name="plotter" Margin="10,10,20,10">
<d3:ChartPlotter.HorizontalAxis>
<d3:HorizontalDateTimeAxis Name="dateAxis"/>
</d3:ChartPlotter.HorizontalAxis>
<d3:ChartPlotter.VerticalAxis>
<d3:VerticalIntegerAxis Name="countAxis"/>
</d3:ChartPlotter.VerticalAxis>

<d3:Header FontFamily="Arial" Content="Bug Information"/>
<d3:VerticalAxisTitle FontFamily="Arial" Content="Count"/>
<d3:HorizontalAxisTitle FontFamily="Arial" Content="Date"/>
</d3:ChartPlotter>
</Grid>
</Window>本回答被提问者和网友采纳

以上是关于WPF DynamicDataDisplay 画曲线图求助的主要内容,如果未能解决你的问题,请参考以下文章

WPF中使用DynamicDataDisplay画直方图应该怎么做

WPF中使用DynamicDataDisplay画直方图应该怎么做

wpf DynamicDataDisplay 如何设置Y轴从上到下显示是从小到大?

关于下载DynamicDataDisplay.dll后被默认锁定的问题

WPF调用Winform Chart控件绘图

plotter for windows 怎么创建图表