Ich versuche, Diagramme mit dynamischen Datenanzeige zu machen. Ich benutze MVVM. Mein senderviewmodel Code ist der folgendeBindung Diagrammplotter mit MVVM
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.";
}
Meine view.xaml Datei ist die folgende
<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>
Das Problem in der Leitung ist
plotter.AddLineGraph(ds, Colors.Green, 2, "Volts");
Er sagt, dass der Plotter nicht existiert in der aktuelle Kontext. Aber bindende MaxVoltage und MinVoltage funktionieren. Könnten Sie mir bitte Änderungen mitteilen, damit ich plotter.addline in meiner SenderViewmodel.cs Datei verwenden kann.