如何解决如何在 blazor 中使用 chart.js?
我正在尝试遵循 mariusmuntean/ChartJs.Blazor 中的这个示例:
https://github.com/mariusmuntean/ChartJs.Blazor
InvalidOperationException:“Project.Shared.Chart”类型的对象确实如此 没有与名称“@Config”匹配的属性。
@page "/charts/bar/horizontal"
@using ChartJs.Blazor.PieChart
@using System.Drawing
@* @layout SampleLayout *@
@using ChartJs.Blazor.Util
@using ChartJs.Blazor.Common
@using ChartJs.Blazor.Common.Axes
@using ChartJs.Blazor.Common.Axes.Ticks
@using ChartJs.Blazor.Common.Enums
@using ChartJs.Blazor.Common.Handlers
@using ChartJs.Blazor.Common.Time
@using ChartJs.Blazor.Interop
<Chart Config="_config"></Chart>
@code {
private PieConfig _config;
protected override void OnInitialized()
{
_config = new PieConfig
{
Options = new PieOptions
{
Responsive = true,Title = new OptionsTitle
{
display = true,Text = "ChartJs.Blazor Pie Chart"
}
}
};
foreach (string color in new[] { "Red","Yellow","Green","Blue" })
{
_config.Data.Labels.Add(color);
}
PieDataset<int> dataset = new PieDataset<int>(new[] { 6,5,3,7 })
{
BackgroundColor = new[]
{
ColorUtil.ColorHexString(255,99,132),// Slice 1 aka "Red"
ColorUtil.ColorHexString(255,205,86),// Slice 2 aka "Yellow"
ColorUtil.ColorHexString(75,192,192),// Slice 3 aka "Green"
ColorUtil.ColorHexString(54,162,235),// Slice 4 aka "Blue"
}
};
_config.Data.Datasets.Add(dataset);
}
}
解决方法
经过多次试验后,我发现应该这样写:
<ChartJs.Blazor.Chart Config="_config"></ChartJs.Blazor.Chart>
代替:
<Chart Config="_config"></Chart>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。