ant-design-blazor / ant-design-blazor/ant-design-charts-blazor

用@ref无法捕获StackedArea组件的引用

未关闭
#26 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
C#
星标
186
派生
44
PR 合并指标
30 天内没有已合并 PR

描述

我按照[堆积面积图的示例代码](https://ant-design-blazor.gitee.io/zh-CN/charts/area)编写了以下内容:
```
@using AntDesign.Charts
@using Title = AntDesign.Charts.Title
@using BlazorApp.Data
@inject MyService Service;

@code{
IChartComponent chart1;
IChartComponent chart2;

protected override async Task OnInitializedAsync()
{
await base.OnInitializedAsync();
var records = await Service.GetRecordsAsync();
List chartData = new List();
foreach (var item in records)
{
chartData.Add(new { date = item.RecordTime.ToString("yyyy/MM/dd"), type = "a", value = item.a});
chartData.Add(new { date = item.RecordTime.ToString("yyyy/MM/dd"), type = "b", value = item.b});
chartData.Add(new { date = item.RecordTime.ToString("yyyy/MM/dd"), type = "c", value = item.c> 0 ? item.c: 0 });
}
await chart1.ChangeData(chartData.ToArray());
}

readonly StackedAreaConfig config = new StackedAreaConfig
{
Title = new Title
{
Visible = true,
Text = "余额"
},
Description = new Description
{
Visible = false,
Text = "当label类型设置为line时,label与面积区域尾端顶部对齐。"
},
XField = "date",
YField = "value",
StackField = "type",
Color = new[] { "#6897a7", "#8bc0d6", "#60d7a7", "#dedede", "#fedca9", "#fab36f", "#d96d6f" },
XAxis = new ValueCatTimeAxis
{
Type = "dateTime",
TickCount = 5
},
Label = new StackedAreaLabel
{
Visible = true,
Type = "line",
},
Legend = new Legend
{
Visible = false,
}
};
}
```
但是执行到`await chart1.ChangeData(chartData.ToArray());`这行的时候会报错

> System.NullReferenceException:“Object reference not set to an instance of an object.”
>
> <>4__this.chart1 是 null。

不知道问题出在哪里

贡献指南

这个仓库没有索引到贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。