06-30-2017 04:20 AM
Hello,
I am trying to plot a few Observable Collection to Graph with AxisDateTime.
Graph:
<ni:Graph x:Name="Graphs_HPT_Temperature" PreferIndexData="False" RenderMode="Raster" Margin="10,10,10,10" Interactions=""> <ni:Graph.Axes> <ni:AxisDateTime Location="Near" Label="Time (s)" Orientation="Horizontal"> <ni:AxisDateTime.MajorDivisions> <ni:RangeLabeledDivisions TickMark="Rectangle"/> </ni:AxisDateTime.MajorDivisions> </ni:AxisDateTime> <ni:AxisDouble Label="Temperature (°C)" Orientation="Vertical" Range="0, 100, System.Double"/> </ni:Graph.Axes> <ni:Graph.Plots> <ni:Plot Label="Temp 1"> <ni:PlotRendererGroup> <ni:LinePlotRenderer Stroke="IndianRed"/> <ni:PointPlotRenderer Stroke="Black" Fill="IndianRed"/> </ni:PlotRendererGroup> </ni:Plot> <ni:Plot Label="Temp 2"> <ni:PlotRendererGroup> <ni:LinePlotRenderer Stroke="DimGray" /> <ni:PointPlotRenderer Stroke="Black" Fill="DimGray"/> </ni:PlotRendererGroup> </ni:Plot> <ni:Plot Label="Temp 3"> <ni:PlotRendererGroup> <ni:LinePlotRenderer Stroke="Blue" /> <ni:PointPlotRenderer Stroke="Blue" Fill="LimeGreen"/> </ni:PlotRendererGroup> </ni:Plot> </ni:Graph.Plots> </ni:Graph>
I am defining source of data like this (all three data sources - randValues, randValues2 and randValues3 - are ObservableCollection<double> :
Graphs_HPT_Temperature.Data[0] = randValues; Graphs_HPT_Temperature.Data[1] = randValues2; Graphs_HPT_Temperature.Data[2] = randValues3;
ObservableCollections are filled with data every second. The following picture describes my problem, when I am using AxisDateTime, the showing date is relative (starting from 1.1.0001) and not absolute. How can I get the absolute date (timestamp) on my AxisDateTime?
I know I can use Waveform structure for these, but when the ObservableCollection contains more than 1000 samples, I need to delete first sample of the collection. Unfortunately, Waveform contains only Append function.
Thanks for your answer.
Solved! Go to Solution.
06-30-2017 10:36 AM
I would suggest using a ChartCollectionAnalogWaveform<double>
, or a ChartCollection<DateTime, double>
, instead of a WPF observable collection. The Capacity
on the chart collection determines the sample history, so if you append more than that number of samples they will automatically be removed from the collection (no manual removes required).