Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
85
XamDataChart Simple with LiveDates
posted

Hi,

i need an absolute minified implementation for a DataChart with Livedata.

That what i have done:

XAML:

<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mvvm="http://prismlibrary.com/"
xmlns:ig="http://schemas.infragistics.com/xaml"
x:Name="UserControlChartCard" x:Class="TorqueLink.Presentation.Views.ChartCard"
mvvm:ViewModelLocator.AutoWireViewModel="True"
mc:Ignorable="d" Height="300" Width="500">
<Grid x:Name="LayoutRoot" Margin="0" Background="White">
<ig:XamDataChart x:Name="SignalChart" Margin="10" DataContext="{Binding ChartValues}">
<ig:XamDataChart.Series>
<ig:LineSeries ItemsSource="{Binding DataContext, ElementName=SignalChart}" ValueMemberPath="SignalData"/>
</ig:XamDataChart.Series>
<ig:XamDataChart.Axes>
<ig:CategoryDateTimeXAxis ItemsSource="{Binding DataContext, ElementName=SignalChart}" DateTimeMemberPath="SignalDateTime" />
</ig:XamDataChart.Axes>
</ig:XamDataChart>
</Grid>
</UserControl>

ViewModel (is injected to the UserControl by PRISM):

public class ViewModelChart : ViewModelBase
{
public class Signal : INotifyPropertyChanged
{
private double _signalData;
private DateTime _signalDateTime;

public double SignalData { get { return _signalData; } set { _signalData = value; OnPropertyChanged(); } }

public DateTime SignalDateTime { get { return _signalDateTime; } set { _signalDateTime = SignalDateTime; OnPropertyChanged(); } }

public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
OnPropertyChanged(new PropertyChangedEventArgs(propertyName));
}

protected virtual void OnPropertyChanged(PropertyChangedEventArgs propertyChangedEventArgs)
{
RaisePropertyChanged()?.Invoke(propertyChangedEventArgs);
}

protected Action<PropertyChangedEventArgs> RaisePropertyChanged()
{
return args => PropertyChanged?.Invoke(this, args);
}
}

[NotNull] public ObservableCollection<Signal> ChartValues { get; } = new ObservableCollection<Signal>();

public delegate void SetDataDeviceObjectDelegate(DataDeviceObject dataDeviceObject);

[NotNull] private readonly IDeviceDataManager _deviceDataManager;

public ViewModelChart([NotNull] IDeviceDataManager deviceDataManager)
{
if (deviceDataManager == null) throw new ArgumentNullException(nameof(deviceDataManager));
_deviceDataManager = deviceDataManager;

//TODO: Use EventAggregator
ChartAction = StartSignalChecker;
}

public void StartSignalChecker()
{

// ### here im starting the signal. it is using the SetDataDeviceObject delegate

}

public void SetDataDeviceObject(IDataDeviceObject dataDeviceObject)
{
if (dataDeviceObject == null || dataDeviceObject.Data == 0) return;

Signal signal = new Signal();
ChartValues.Add(signal);
OnPropertyChanged("ChartValues");
signal.SignalDateTime = DateTime.Now;
signal.SignalData = dataDeviceObject.Signal;
}
}

...............

Well, nothing happend. what is necessary and missing?

Parents Reply Children