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
60
How to configure data binding against the XamDoughtnut control at runtime via C# code and not XAML
posted

We have a Semantic Dev application that acquires data via RDF data sources at runtime; the app is data-driven so the declarative approach to XAML-centric programming is not ideal. Instead what I really need to do is bind the data at runtime and assign values to the Itemsoure (Datacontext), RingSeries and other attributes. I have played around with the API but have missed on several attempts. I just need to know what the coded-workflow is to bind to the control at runtime using the XamDoughtnut control API set.

Thanks!

Parents
No Data
Reply
  • 29105
    Offline posted

    Hello Tavi, 

    I attached a sample below that demonstrates how to bind the XamDoughnutChart in code behind. Let me know if you have any questions. 

    public partial class MainWindow : Window
        {
            public MainWindow()
            {
                var source = new HierarchalDataCollection();
    
                InitializeComponent();
    			
                this.xamDoughnutChart.Series.Add(new RingSeries
                {
                    LabelMemberPath = "Label",
                    ValueMemberPath = "productionShare",
                    LabelsPosition = LabelsPosition.BestFit,
                    ItemsSource = source
                });
            }
        }
    
        public class Category
        {
            public string Label { get; set; }
            public double productionShare { get; set; }
        }
    
        public class HierarchalDataCollection : List<Category>
        {
            public HierarchalDataCollection()
            {
                this.Add(new Category { Label = "Footwear", productionShare = 46 });
                this.Add(new Category { Label = "Clothing", productionShare = 38 });
                this.Add(new Category { Label = "Accessories", productionShare = 16 });
            }

    xamDoughnutChartCodeBehind.zip 

Children
No Data