erossini / BlazorChartjs

Creates beautiful charts in Blazor using Chart.js. Library for NET6, NET7 and NET8. Source code and demo available.
https://www.puresourcecode.com/dotnet/blazor/blazor-component-for-chartjs/
MIT License
111 stars 43 forks source link

When I initialize a Chart, I get an error #30

Closed erossini-chi closed 1 year ago

erossini-chi commented 1 year ago

I have a simple Razor page

@page "/test"

<Chart Config="_config1" @ref="_chart1" Height="400px"></Chart>

@code {
    private BarChartConfig? _config1;
    private Chart? _chart1;

    protected override async Task OnInitializedAsync()
    {
        _config1 = new BarChartConfig()
            {
                Options = new Options()
                {
                    IndexAxis = "y",
                    Responsive = true,
                    MaintainAspectRatio = false,
                    Plugins = new Plugins()
                    {
                        Legend = new Legend()
                        {
                            Align = Align.Center,
                            Display = false,
                            Position = LegendPosition.Right
                        }
                    },
                    Scales = new Dictionary<string, Axis>()
                {
                    {
                        Scales.XAxisId, new Axis()
                        {
                            Stacked = true,
                            Ticks = new Ticks()
                            {
                                MaxRotation = 0,
                                MinRotation = 0
                            }
                        }
                    },
                    {
                        Scales.YAxisId, new Axis()
                        {
                            Stacked = true
                        }
                    }
                }
                }
            };

        _config1.Data.Labels = new List<string>() { "1900", "1950", "1999", "2050" };
        _config1.Data.Datasets.Add(new BarDataset()
            {
                Label = "Value",
                Data = new List<decimal>() { 408, 547, 675, 734 },
                BackgroundColor = ColorPalettes.MainPalette,
                BorderColor = ColorPalettes.MainPalette,
                BorderWidth = 1
            });
    }
}

The error I get is

Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100] Unhandled exception rendering component: Object reference not set to an instance of an object.

image

erossini commented 1 year ago

I can't replicate the issue