How to bind a chart to a List<T> in XamDataChart in Xamarin.Forms?

210 Views Asked by At

I have a list as follows

public List<MonthlyData> MonthlyList;

public class MonthlyData
{
    public int Count;
    public string Month;
}

The list MonthlyList is populated with 12 items containing count for each month.

I'm trying to display the list in a XamDataChart but it just shows a blank page.

XAML Code:

<ig:XamDataChart x:Name="Chart" >
    <ig:XamDataChart.Axes>
        <ig:CategoryXAxis x:Name="XAxis"  ItemsSource="{Binding MonthlyList}" Label="{}{Month}"  />
        <ig:NumericYAxis x:Name="YAxis"  />
    </ig:XamDataChart.Axes>
    <ig:XamDataChart.Series>
        <ig:StackedColumnSeries x:Name="series" ItemsSource="{Binding MonthlyList}" Title="Data" XAxis="{x:Reference XAxis}" YAxis="{x:Reference YAxis}">
            <ig:StackedColumnSeries.Series>
                <ig:StackedFragmentSeries ValueMemberPath="Count" />
             </ig:StackedColumnSeries.Series>
        </ig:StackedColumnSeries>
    </ig:XamDataChart.Series>
</ig:XamDataChart>
1

There are 1 best solutions below

0
On BEST ANSWER

From the document:

Data bindings allow properties of two objects to be linked so that a change in one causes a change in the other.

So you can only bind to public properties instead of variables.

Solution:

    public List<MonthlyData> MonthlyList { get; set; }