We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Problem with displaying of the data on graph

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!!

1 Reply

DA Devi Aruna Maharasi Murugan Syncfusion Team April 21, 2017 10:58 AM UTC

Hi Michael, 
  
Thanks for contacting Syncfusion Support. 
  
We have checked your provided code and to bind the collection to chart, we have to define the collection field as property as shown in the below code 

public ObservableCollection<ChartPoint> FoundFrequencies { get; set; }  
 
public ObservableCollection<ChartPoint> UnfoundFrequencies { get; set; }  
 

  
We have created a demo sample by modifying the provided code and it can be downloaded from below link, 
Sample: Chart130085 
  
Regards, 
Devi 





Loader.
Up arrow icon