Hello,
I try to present the dynamic data on the sfChart, but with no result.
My chart code XAML:
<chart:SfChart x:Name="myChart" Style="{StaticResource chartStyle}">
<chart:SfChart.Header>
<TextBlock Text="Chart output" Style="{StaticResource chartHeaderDefaultStyle}"/>
</chart:SfChart.Header>
<chart:SfChart.DataContext>
<local:ChartPoints x:Name="T1"/>
</chart:SfChart.DataContext>
<chart:SfChart.PrimaryAxis>
<chart:NumericalAxis ActualRangeChanged="XAxis_ActualRangeChanged"
EnableScrollBarResizing="False" EnableTouchMode="False"
EnableScrollBar="{StaticResource showScrollInChartStyle}" x:Name="Chart1_XAxis" Header="Frequency [MHz]"
LabelFormat="" EdgeLabelsDrawingMode="Fit"
LabelTemplate="{StaticResource labelTemplate}"
AxisLineStyle="{StaticResource axisLineStyle}"
MajorTickLineStyle="{StaticResource majorTickLineStyle}"
MajorGridLineStyle="{StaticResource gridLineStyle}"/>
</chart:SfChart.PrimaryAxis>
<chart:SfChart.SecondaryAxis>
<chart:NumericalAxis x:Name="Chart1_YAxis"
Header="Amplitude"
LabelTemplate="{StaticResource labelTemplate}"
AxisLineStyle="{StaticResource axisLineStyle}"
MajorTickLineStyle="{StaticResource majorTickLineStyle}"
MajorGridLineStyle="{StaticResource gridLineStyle}">
</chart:NumericalAxis>
</chart:SfChart.SecondaryAxis>
<chart:SplineSeries StrokeThickness="2" x:Name="Chart1_Series1"
Label="Platinum" ItemsSource="{Binding FoundFrequencies}"
XBindingPath="Frequency" YBindingPath="Amplitude" Background="LightCyan"/>
<chart:LineSeries ItemsSource="{Binding UnfoundFrequencies}"
XBindingPath="Frequency" Interior="Red"
YBindingPath="Amplitude"/>
<chart:SfChart.Annotations>
<chart:RectangleAnnotation x:Name="Chart1_PossibleRange"/>
</chart:SfChart.Annotations>
</chart:SfChart>
And here my ChartPoints object (T1):
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace sfchart1_WPF
{
public class ChartPoints
{
public ObservableCollection<ChartPoint> FoundFrequencies = new ObservableCollection<ChartPoint>();
public ObservableCollection<ChartPoint> UnfoundFrequencies = new ObservableCollection<ChartPoint>();
public void Clear()
{
FoundFrequencies.Clear();
UnfoundFrequencies.Clear();
}
public ChartPoints()
{
Init();
}
private void Init()
{
FoundFrequencies.Add(new ChartPoint { Frequency = 200, Amplitude = 2 });
FoundFrequencies.Add(new ChartPoint { Frequency = 210, Amplitude = 8});
FoundFrequencies.Add(new ChartPoint { Frequency = 220, Amplitude = 5});
FoundFrequencies.Add(new ChartPoint { Frequency = 230, Amplitude = 7});
FoundFrequencies.Add(new ChartPoint { Frequency = 240, Amplitude = 4});
FoundFrequencies.Add(new ChartPoint { Frequency = 250, Amplitude = 3});
FoundFrequencies.Add(new ChartPoint { Frequency = 260, Amplitude = 5});
}
}
public class ChartPoint
{
public double Frequency { get; set; }
public double Amplitude { get; set; }
}
}
I don't see any points on the chart. I don't understand where I did a mistake.. :(
Thank you a lot!!