Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
370
Ho to databing XamChart?
posted

 

 

 

 

 

 

 

 

 

 

 

 

Hello, I want to bind a collection to a xamChart. My first attempt. Below is the xaml and the code behind and I am not seeing any chart after I run the application. What am I doing wrong?

Thanks

 

<Grid>

    <igCA:XamChart Name="xamChart1" DataContext="{Binding.}">

      <igCA:XamChart.Series>

        <igCA:Series ChartType="Bar" Fill="#FFD21717" Stroke="#FF000000" DataSource="{Binding Source=MothlyCharges}" Label="Monthly Total Charges" DataMapping="Lable=Month; Value=Amount">

        </igCA:Series>

     </igCA:XamChart.Series>

   </igCA:XamChart>

</Grid>

 

 

 

 

    public partial class MainWindow : Window

    {

        public MainWindow()

        {

            InitializeComponent();

            this.DataContext = new MV();

        }

    }

    public class MV

    {

        public MV()

        {

            MothlyCharges = new ObservableCollection<MonthlyCharges>();

            MothlyCharges.Add(new MonthlyCharges { Month = "Jan 2010", Amount = 213.99m });

            MothlyCharges.Add(new MonthlyCharges { Month = "Feb 2010", Amount = 1213.99m });

            MothlyCharges.Add(new MonthlyCharges { Month = "Mar 2010", Amount = 213.99m });

            MothlyCharges.Add(new MonthlyCharges { Month = "Apr 2010", Amount = 5213.99m });

        }

        public ObservableCollection<MonthlyCharges> MothlyCharges

        {

            get;

            set;

        }

 

    }

    public class MonthlyCharges

    {

        public string Month;

        public decimal Amount;

    }

 

 

 

Parents
  • 27093
    posted

    Hello Yassin,

     

    I have been looking into your issue and the code snippet you have provided and can see a few things that could cause this. The first and most important is the DataSource binding you have provided for the Series. By setting the Source property for a binding it is like setting set its DataContext, but you always need to provide a Path. Here is link from the MSDN which should clear things out: http://blogs.msdn.com/b/wpfsdk/archive/2006/10/19/wpf-basic-data-binding-faq.aspx . So in your case, as you have already set the DataContext of the XamChart,  you should use:

     DataSource="{Binding Path=MothlyCharges}"

     

    Another thing you that should actually fail while compilation is:

     <igCA:XamChart Name="xamChart1" DataContext="{Binding.}">

     

    I suppose you meant to write DataContext="{Binding}" which is actually the default behavior and is somewhat unnecessary.

     

    Please let me know if you require any further assistance on the matter.

     

    Sincerely,

    Petar Monov

    Developer Support Engineer

    Infragistics Bulgaria

    www.infragistics.com/support

     

Reply Children