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

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

Đang mở
#26 0 bình luận 0 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
C#
Star
186
Fork
44
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

我按照[堆积面积图的示例代码](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。

不知道问题出在哪里

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.