【发布时间】:2016-11-27 05:58:28
【问题描述】:
我正在尝试使用动态数据显示制作图表。我正在使用 MVVM。我的 senderviewmodel 代码如下
voltagePointCollection = new VoltagePointCollection();
updateCollectionTimer = new DispatcherTimer();
updateCollectionTimer.Interval = TimeSpan.FromMilliseconds(1);
updateCollectionTimer.Tick += new EventHandler(updateCollectionTimer_Tick);
updateCollectionTimer.Start();
var ds = new EnumerableDataSource<VoltagePoint>(voltagePointCollection);
ds.SetXMapping(x => dateAxis.ConvertToDouble(x.Date));
ds.SetYMapping(y => y.Voltage);
((MainWindow)System.Windows.Application.Current.MainWindow).TextBlock1.Text = "Setting Text from My Program";
((MainWindow)System.Windows.Application.Current.MainWindow).plotter.AddLineGraph(ds, Colors.Green, 2, "Volts");
plotter.AddLineGraph(ds, Colors.Green, 2, "Volts"); // to use this method you need "using Microsoft.Research.DynamicDataDisplay;"
MaxVoltage = 3;
MinVoltage = -3;
//System.IO.StreamReader file = new System.IO.StreamReader("C:\\Users\\niranjan\\Desktop\\sample.txt");
//var sample = file.ReadToEnd();
//tokens = sample.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None);
// here graph ending
ResultValue = "N/D";
var wasSent = await _senderBluetoothService.Send(SelectDevice, Data);
if (wasSent)
{
ResultValue = "The data was sent.";
}
else
{
ResultValue = "The data was not sent.";
}
我的 view.xaml 文件如下
<d3:ChartPlotter Name= "plotter" Grid.Row="1" Grid.Column="1" Height="244" HorizontalAlignment="Left" Width="1076">
<d3:ChartPlotter.HorizontalAxis>
<d3:HorizontalDateTimeAxis Name="dateAxis"/>
</d3:ChartPlotter.HorizontalAxis>
<d3:Header FontFamily="Georgia" Content="Voltage chart"/>
<d3:VerticalAxisTitle FontFamily="Georgia" Content="Voltage [V]" />
<d3:HorizontalAxisTitle FontFamily="Georgia" Content="Time"/>
<d3:HorizontalLine Value="{Binding MaxVoltage}" Stroke="Red" StrokeThickness="2"/>
<d3:HorizontalLine Value="{Binding MinVoltage}" Stroke="Red" StrokeThickness="2"/>
</d3:ChartPlotter>
问题出在一行
plotter.AddLineGraph(ds, Colors.Green, 2, "Volts");
它说绘图仪在当前上下文中不存在。但是绑定 MaxVoltage 和 MinVoltage 有效。您能否告诉我更改,以便我可以在我的 SenderViewmodel.cs 文件中使用 plotter.addline。
【问题讨论】:
标签: wpf data-binding mvvm-light dynamic-data-display