为什么ChartPlotter没有AddLineGraph方法

dhr2001 2018-09-11 04:49:43
手头有个项目需要通过动态曲线显示传感器的值。
网上说使用DynamicDataDisplay最方便,新建了一个WPF应用(.NET Framework)。
通过“管理NuGet程序包”方式获取的DynamicDataDisplayWpf,版本是0.4.0。
现在的情况是AddLineGraph方法不能用,导致不能动态曲线。请帮忙分析一下原因,折腾一整天了!

XAML代码如下:
<Window x:Class="DataDisplayTest.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:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:DataDisplayTest"
xmlns:dynamicdatadisplay="clr-namespace:Microsoft.Research.DynamicDataDisplay;assembly=DynamicDataDisplay"
xmlns:d3="http://research.microsoft.com/DynamicDataDisplay/1.0"
mc:Ignorable="d"
Title="DataDisplayTest" Height="450" Width="800">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<StackPanel Orientation="Horizontal">
<TextBlock Text="CPU Usage" FontSize="15" Margin="20,10,0,0" FontWeight="Bold"/>
<TextBlock x:Name="cpuUsageText" Margin="10,10,0,0" FontSize="15"/>
</StackPanel>
<d3:ChartPlotter x:Name="plotter" Margin="10,10,20,10" Grid.Row="1">
<d3:ChartPlotter.MainVerticalAxis>
<d3:VerticalIntegerAxis />
</d3:ChartPlotter.MainVerticalAxis>
<d3:ChartPlotter.MainHorizontalAxis>
<d3:HorizontalIntegerAxis/>
</d3:ChartPlotter.MainHorizontalAxis>
<d3:Header Content="传感器测试"/>
<d3:VerticalAxisTitle Content="浓度"/>
</d3:ChartPlotter>
</Grid>
</Window>


.CS代码如下:
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
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.Navigation;
using System.Windows.Shapes;
using System.Windows.Threading;
using Microsoft.Research.DynamicDataDisplay;
using Microsoft.Research.DynamicDataDisplay.DataSources;



namespace DataDisplayTest
{
/// <summary>
/// MainWindow.xaml 的交互逻辑
/// </summary>
public partial class MainWindow : Window
{

private ObservableDataSource<Point> dataSource = new ObservableDataSource<Point>(); //数据源
private PerformanceCounter cpuPerformance = new PerformanceCounter(); //关于计算机性能类
private DispatcherTimer timer = new DispatcherTimer(); //委托的定时器
int i = 0; //时间轴

public MainWindow()
{
InitializeComponent();
this.Loaded += new RoutedEventHandler(Window_Loaded);
}

//**** 时间,用于构造坐标点
private void AnimatedPlot(object sender,EventArgs e) {
cpuPerformance.CategoryName = "Processor";
cpuPerformance.CounterName = "% Processor Time";
cpuPerformance.InstanceName = "_Total";

double x = i;
double y = cpuPerformance.NextValue();

Point point = new Point(x,y); //点
dataSource.AppendAsync(base.Dispatcher,point); //将点异步委托到数据源
cpuUsageText.Text = String.Format("{0:0%}",y); //格式化显示CPU使用率
i++; //时间+1
}

//窗口加载完毕后触发
private void Window_Loaded(object sender, EventArgs e) {
//******* 这里AddLineGraph不能用
plotter.AddLineGraph(dataSource,Colors.Green,2, "Percentage"); //这里提示ChartPlotter未包含AddLineGraph
//********
timer.Interval = TimeSpan.FromSeconds(1);
timer.Tick += new EventHandler(AnimatedPlot);
timer.IsEnabled = true;
plotter.Viewport.FitToView();
}
}
}

...全文
678 1 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
dhr2001 2018-09-12
  • 打赏
  • 举报
回复 4
没找到问题原因,估计是因为DynamicDataDisplay的版本更新后,把一些方法去除了。
现调整为下面这种方式实现。

LineGraph line = new LineGraph();
line.DataSource = dataSource;
line.Stroke = Brushes.Green;
line.StrokeThickness = 2;
line.AddToPlotter(plotter);

111,088

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧