I don't know how many plots I need to graph at runtime, so I make a WPF Graph DataSource binding to the a collection of a collection of points. The graph binding works fine when I have more than 2 collections of points (2 plots), but I cannot get the graph to bind when there is only one collection of points. Should this work, or is this approach way off base?
Binding Object:
private ObservableCollection<ObservableCollection<System.Windows.Point>> _PlotXYData = new ObservableCollection<ObservableCollection<System.Windows.Point>>(); public ObservableCollection<ObservableCollection<System.Windows.Point>> PlotXYData { get { return _PlotXYData; } set { _PlotXYData = value; RaisePropertyChanged("PlotXYData"); } }
XAML Binding:
<ni:Graph Name="graph1" DataSource="{Binding Path=ViewModel.PlotXYData}"><ni:Graph.Axes><ni:AxisDouble x:Name="HorizontalAxis1" Orientation="Horizontal" Range="{Binding Path=ViewModel.NIGraph.Axes[0].Range}" Adjuster="FitLoosely"></ni:AxisDouble><ni:AxisDouble x:Name="VerticalAxis1" Orientation="Vertical" Range="{Binding Path=ViewModel.NIGraph.Axes[1].Range}" Adjuster="FitLoosely"></ni:AxisDouble><ni:AxisDouble x:Name="VerticalAxis2" Orientation="Vertical" Range="{Binding Path=ViewModel.NIGraph.Axes[2].Range}" Adjuster="FitLoosely" Location="Far" MajorGridLines="{x:Null}"></ni:AxisDouble></ni:Graph.Axes><ni:Graph.Plots><ni:Plot Label="Plots[0]" VerticalScale="{Binding ElementName=VerticalAxis1}" ><ni:LinePlotRenderer Stroke="#FF0070B0" /></ni:Plot><ni:Plot Label="Plots[1]" VerticalScale="{Binding ElementName=VerticalAxis2}" ><ni:LinePlotRenderer Stroke="#FFB90E30" /></ni:Plot></ni:Graph.Plots></ni:Graph>