Mvvm syncfusion图表不显示数据

Mvvm syncfusion图表不显示数据,mvvm,xamarin.ios,Mvvm,Xamarin.ios,我添加了SFchart,它没有错误,并且可以编译。它显示一个空的图表视图。 我在Xamarin.IOS中使用MVVMcross 我请求的数据就在那里,它包含大约200行,数据是通过方法override void viewsing从我的api请求的 viewdidload中的我的视图: //Initialize the Chart with required frame. This frame can be any rectangle, which bounds inside the view.

我添加了SFchart,它没有错误,并且可以编译。它显示一个空的图表视图。 我在Xamarin.IOS中使用MVVMcross

我请求的数据就在那里,它包含大约200行,数据是通过方法
override void viewsing
从我的api请求的

viewdidload中的我的视图:

 //Initialize the Chart with required frame. This frame can be any rectangle, which bounds inside the view.
        SFChart chart = new SFChart();
        chart.Frame = this.headerView.Frame;

        //Adding Primary Axis for the Chart.
        SFCategoryAxis primaryAxis = new SFCategoryAxis();
        chart.PrimaryAxis = primaryAxis;

        //Adding Secondary Axis for the Chart.
        SFNumericalAxis secondaryAxis = new SFNumericalAxis();
        chart.SecondaryAxis = secondaryAxis;
        chart.Series.Add(new SFColumnSeries()
        {

            ItemsSource = (this.ViewModel as UserCoinViewModel).CoinHistory,

            XBindingPath = "price_btc",

            YBindingPath = "timestamp"

        });


        this.View.AddSubview(chart);
视图模型:

private List<CoinHistoryModel> _CoinHistory;

    public List<CoinHistoryModel> CoinHistory
    {
        get
        {
            return _CoinHistory;
        }
        set
        {
            _CoinHistory = value;
            RaisePropertyChanged(() => CoinHistory);
        }
    }
private List\u历史记录;
公共列表历史
{
得到
{
返回历史;
}
设置
{
_历史=价值;
RaisePropertyChanged(()=>CoinHistory);
}
}

因为您使用的是MVVMcross,所以应该使用
bind
方法来设置
系列
项目资源。您只需将
ItemsSource
设置为viewModel实例的属性,当值更改时,它不会通知视图。因此,它似乎显示了一个空的图表

修改代码以绑定,如下所示:

SFColumnSeries series = new SFColumnSeries()
{
    XBindingPath = "price_btc",

    YBindingPath = "timestamp"
};
chart.Series.Add(series);

var set = this.CreateBindingSet<YourView, UserCoinViewModel>();
...
        set.Bind(series).For(s => s.ItemsSource).To(vm => vm.CoinHistory);
...
set.Apply();

在您的最后一部分中,我得到一个错误,即ViewModel在当前上下文中不存在?这是我应该更改的值吗?编辑:我也不能使用bool动画部分也得到一个错误,绑定失败?唯一的区别是我使用了“MvxFluentBindingDescriptionSet”,另一个绑定成功了。您使用了
this.ViewModel作为UserCoinViewModel
,所以我猜这是您的ViewModel。它是否继承自
MvxViewModel
?您的视图是否继承自
MvxViewController
?是的“userCoinViewModel”确实是viewmodel。是的,它们都继承自mvxViewModel和mvxViewControllerHi@AchielVolckaert,我制作了一个简单的示例,说明这两种方法工作得很好。你可以参考一下。
private MvxCommand loadDataCommand;
public ICommand LoadDataCommand
{
    get
    {
        return loadDataCommand ?? (loadDataCommand = new MvxCommand(ExecuteloadDataCommand));
    }
}
private void ExecuteloadDataCommand()
{
    CoinHistory = new List<CoinHistoryModel>()
    {
        new CoinHistoryModel{ price_btc = "First", timestamp = 10 },
        new CoinHistoryModel{ price_btc = "Second", timestamp = 20 },
        new CoinHistoryModel{ price_btc = "Third", timestamp = 30 }
    };
    // Change it to your data request here
}
public override void ViewWillAppear(bool animated)
{
    base.ViewWillAppear(animated);

    (ViewModel as UserCoinViewModel).LoadDataCommand.Execute(null);
    // You can also bind a button to this command to trigger it manually.
}