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

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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>本回答被提问者和网友采纳

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

问题:命名空间 d3:“http://research.microsoft.com/DynamicDataDisplay/1.0”不存在ChartPlotter元素

原因:下载DynamicDataDisplay后,出于安全性考虑,DynamicDataDisplay.dll文件被锁定了,即便在WPF程序中引用了DynamicDataDisplay.dll,当你在XAML中使用相关绘图标签时,会提示在xmlns:d3="http://research.microsoft.com/DynamicDataDisplay/1.0"中,不存在该元素。

解决办法:打开你WPF源程序存放的文件夹,找到DynamicDataDisplay.dll文件,然后右键点击该文件的属性,你就会发现属性弹出框下边有个关于解锁该文件的勾。勾上就OK了

以上是关于WPF中使用DynamicDataDisplay画直方图应该怎么做的主要内容,如果未能解决你的问题,请参考以下文章

WPF DynamicDataDisplay 画曲线图求助

适用于 WPF 应用程序的 DynamicDataDisplay 和其他图表库

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

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

WPF调用Winform Chart控件绘图

plotter for windows 怎么创建图表