首页 > 解决方案 > 如何将图表绑定到列表在 Xamarin.Forms 中的 XamDataChart 中?

问题描述

我有一个清单如下

public List<MonthlyData> MonthlyList;

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

列表 MonthlyList 填充了 12 个项目,其中包含每个月的计数。

我试图在 XamDataChart 中显示列表,但它只显示一个空白页。

XAML 代码:

<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>

标签: xamarinxamarin.formsinfragisticsxamdatachart

解决方案


从文件:

数据绑定允许链接两个对象的属性,以便一个对象的更改导致另一个对象的更改。

所以你只能绑定到公共属性而不是变量。

解决方案:

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

推荐阅读