WPF sfchart two column series chart not showing the data series

Hi,

I'm trying to get the WPF sfchart two column series from the sfChart Getting Started working.

https://help.syncfusion.com/wpf/sfchart/getting-started

It builds, axes, headings etc display, using VS2017 I can see the observablecollection populated with data but the two columns aren't showing. I've successfully built other Syncfusion sample charts etc so I think the sfChart column series problem is either operator error on my part or there's something missing from the Syncfusion Getting Started xaml/c# code.

I would be grateful for assistance in sorting this out

xaml and c# follows

Thanks

David


MainWindow xaml:

x:Class="SampleChart.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:syncfusion="clr-namespace:Syncfusion.UI.Xaml.Charts;assembly=Syncfusion.SfChart.WPF"
xmlns:local="clr-namespace:SampleChart"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525">
Header="Demands Comparison" Height="300" Width="500" HorizontalAlignment="Center" Margin="10" VerticalAlignment="Center">
FontSize="10" Header="Demands" ShowGridLines="False"/>
FontSize="10" Header="Values" ShowGridLines="False"/>

Visibility="Visible" />

Label="2010" ItemsSource="{Binding Demands}" XBindingPath="Demand" YBindingPath="Year2010" />

Label="2011" ItemsSource="{Binding Demands}" XBindingPath="Demand" YBindingPath="Year2011" />



MainWindow c#

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace SampleChart
{
///
/// Interaction logic for MainWindow.xaml
///

public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();

this.Demands = new ObservableCollection()
{
new GoldDemand()
{
Demand = "Jewelry", Year2010 = 1998.0, Year2011 = 2361.2
},
new GoldDemand()
{
Demand = "Electronics",Year2010 = 1284.0, Year2011 = 1328.0
},
new GoldDemand()
{
Demand = "Research",Year2010 = 1090.5, Year2011 = 1032.0
},
new GoldDemand()
{
Demand = "Investment",Year2010 = 1643.0, Year2011 = 1898.0
},
new GoldDemand()
{
Demand = "Bank Purchases", Year2010 = 987.0, Year2011 = 887.0
}
};
}

public ObservableCollection Demands { get; set; }
}
}



GoldDemand c#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SampleChart
{
public class GoldDemand
{
public string Demand { get; set; }
public double Year2010 { get; set; }
public double Year2011 { get; set; }
}
}




3 Replies

DS Durgadevi Selvaraj Syncfusion Team February 21, 2018 02:24 PM UTC

Hi David, 
  
Thanks for contacting Syncfusion Support. 
  
We have analyzed the reported problem based on the provided codes and we found that the DataContext for the chart was not set so, we are unable access data from its parent(window). 
  
However, you can resolve this problem by setting DataContext to the window as like in below code, 
  
Code Snippet[C#] 
public MainWindow() 
{ 
            InitializeComponent(); 
            this.Demands = new ObservableCollection<GoldDemand>() 
{ 
new GoldDemand() 
{ 
Demand = "Jewelry", Year2010 = 1998.0, Year2011 = 2361.2 
}, 
new GoldDemand() 
{ 
Demand = "Electronics",Year2010 = 1284.0, Year2011 = 1328.0 
}, 
new GoldDemand() 
{ 
Demand = "Research",Year2010 = 1090.5, Year2011 = 1032.0 
}, 
new GoldDemand() 
{ 
Demand = "Investment",Year2010 = 1643.0, Year2011 = 1898.0 
}, 
new GoldDemand() 
{ 
Demand = "Bank Purchases", Year2010 = 987.0, Year2011 = 887.0 
} 
}; 
            this.DataContext = this; 
} 
  
  
Please find the output screenshot below, 
 
  
You can download the reference sample from below link, 
  
Please let us know if you have any concerns. 
Regards,  
Durgadevi S 



PR Padmini Ramamurthy Syncfusion Team February 22, 2018 04:23 AM UTC

From: David Coote 
Sent: Wednesday, February 21, 2018 5:18 PM
To: Syncfusion Support <[email protected]>
Cc: Pete Cianci <[email protected]>
Subject: Fw: Syncfusion support community forum 136006, WPF sfchart two column series chart not showing the data series, has been updated. 

Hi,

Thanks for the reply. Adding the data context to the code behind fixes the problem.

A few points:

a/ Setting the data context wasn't mentioned in the Syncfusion sfChart Getting Started code or xaml.

b/ This was my first Syncfusion WPF "project" and one of my first WPF efforts. I spent hours a few days ago trying to work out why the chart wasn't presenting the series. It's important that samples like this work as is so users can develop competency with technology features with which they're not familiar. I'd ended up debugging the Syncfusion code through which process I thought the data context was missing. While this has been a useful way to develop experience with the technology I'd prefer to be debugging my own code :)

c/ What is the xaml recommended for including the data context in the sfChart Getting Started sample?

d/ Be good if Syncfusion could update the Getting Started xaml/code and ensure that all other Getting Started samples work as detailed.

e/ A useful way to help avoid problems of this nature is to have a working sample that includes the Getting Started code/xaml snippets so developers can have a known working reference.

Having said all that I'm looking forward to using more of the Syncfusion product. Great UI potential and quick/helpful support so far

Regards

David
 



DS Durgadevi Selvaraj Syncfusion Team February 24, 2018 01:25 PM UTC

  
Thanks for your valuable feedback on our user guide documentation. 
  
We already have a plan to make some changes in getting started and other features of Chart and all your concerns will be resolved shortly. 
  
For your reference, we have posted the code snippet that required for setting the data context in XAML code below. 
  
Code Snippet[XAML] 
<Window  
  
        DataContext="{Binding RelativeSource={RelativeSource Self}}" 
  
        xmlns:chart="http://schemas.syncfusion.com/wpf" 
        mc:Ignorable="d" 
        Title="MainWindow" Height="350" Width="525"> 
    <Grid> 
        <chart:SfChart > 
             
        </chart:SfChart> 
    </Grid> 
</Window> 
 
  
We are happy to hear from you that you are looking forward to use Syncfusion products. As always, we will be glad to assist you. 
  
Regards,  
Durgadevi S 


Loader.
Up arrow icon