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.
Unfortunately, activation email could not send to your email. Please try again.

Problem with displaying of the data on graph

Thread ID:

Created:

Updated:

Platform:

Replies:

130085 Apr 20,2017 10:12 AM Apr 23,2017 05:47 AM WPF 1
loading
Tags: SfChart
Michael
Asked On April 20, 2017 10:12 AM

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

Devi Aruna Maharasi Murugan [Syncfusion]
Replied On April 21, 2017 06:58 AM

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 





CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;