Binding to chart with a CategoricalAxis

2 posts, 0 answers
  1. Pat
    Pat avatar
    31 posts
    Member since:
    Mar 2009

    Posted 23 Jun 2012 Link to this post

    I have set up a chart with a Categorical horizontal axis and I am trying to bind it to data at run time.  I have a list of object defined as below

        public class ChartData
        {
             public float Value
            {
                get;
                set;
            }
             public string Category
            {
                get;
                set;
            } 
            public ChartData(float value, string category)
            {
                this.Value = value;
                this.Category = category;
            }
        }
    To bind to the chart I use the statement

    chart.Series[0].ItemsSource = series;
    


    The chart shows as empty. However If I do not assign it, then the sample data in the Xaml is shown correctly.


    How do I bind the list .

    Thaks



  2. Pat
    Pat avatar
    31 posts
    Member since:
    Mar 2009

    Posted 23 Jun 2012 Link to this post

    I eventually worked out how to do it. using the code

                        BarSeries barseries = ((BarSeries)chart.Series[0]);
                        barseries.CategoryBinding = new PropertyNameDataPointBinding() { PropertyName = "Category" };
                        barseries.ValueBinding = new GenericDataPointBinding<ChartDatadouble>() { ValueSelector = ChartData => ChartData.Value };
                        barseries.ItemsSource = series;
    
  3. DevCraft banner
Back to Top