This is a migrated thread and some comments may be shown as answers.

Binding to chart with a CategoricalAxis

1 Answer 76 Views
Chart
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Pat
Top achievements
Rank 1
Pat asked on 23 Jun 2012, 05:30 PM
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



1 Answer, 1 is accepted

Sort by
0
Pat
Top achievements
Rank 1
answered on 23 Jun 2012, 06:06 PM
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;
Tags
Chart
Asked by
Pat
Top achievements
Rank 1
Answers by
Pat
Top achievements
Rank 1
Share this question
or