Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strange issue on a SimpleBarChartComponent realized in code behind #145

Closed
fededim opened this issue Aug 27, 2020 · 4 comments
Closed

Strange issue on a SimpleBarChartComponent realized in code behind #145

fededim opened this issue Aug 27, 2020 · 4 comments
Labels
bug Something isn't working

Comments

@fededim
Copy link

fededim commented Aug 27, 2020

In my Blazor WebAssembly solution I have these 2 files

CameraReliability.razor

@page "/CameraReliability"

<h1>CameraReliability</h1>

<p>Current count: @currentCount</p>

<button class="btn btn-primary" @onclick="IncrementCount">Click me</button>

<Chart @ref="_barChart"
       Config="@_barChartConfig"
       TConfig="ChartJs.Blazor.ChartJS.BarChart.BarConfig"
       Width="600"
       Height="300" />

CameraReliability.razor.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using ChartJs.Blazor.ChartJS.BarChart;
using ChartJs.Blazor.ChartJS.BarChart.Axes;
using ChartJs.Blazor.ChartJS.Common.Axes;
using ChartJs.Blazor.ChartJS.Common.Axes.Ticks;
using ChartJs.Blazor.ChartJS.Common.Properties;
using ChartJs.Blazor.Charts;
using ChartJs.Blazor.Util;
using Microsoft.AspNetCore.Components;

namespace SincroADR_GUI.Client.Pages
{
    public partial class CameraReliability
    {
        private readonly HttpClient Http;
        private int currentCount = 0;

        private BarConfig _barChartConfig;
        private ChartJsBarChart _barChart;
        private BarDataset<double> _barDataSet;

        protected override void OnInitialized()
        {
            _barChartConfig = new BarConfig
            {
                Options = new BarOptions
                {
                    Title = new OptionsTitle
                    {
                        Display = true,
                        Text = "Simple Bar Chart"
                    },
                    Scales = new BarScales
                    {
                        XAxes = new List<CartesianAxis>
                    {
                        new BarCategoryAxis
                        {
                            BarPercentage = 0.5,
                            BarThickness = BarThickness.Flex
                        }
                    },
                        YAxes = new List<CartesianAxis>
                    {
                        new BarLinearCartesianAxis
                        {
                            Ticks = new LinearCartesianTicks
                            {
                                BeginAtZero = true
                            }
                        }
                    }
                    }
                }
            };

            _barChartConfig.Data.Labels.AddRange(new[] { "A", "B", "C", "D" });

            _barDataSet = new BarDataset<double>
            {
                Label = "My double dataset",
                BackgroundColor = new[] { ColorUtil.RandomColorString(), ColorUtil.RandomColorString(), ColorUtil.RandomColorString(), ColorUtil.RandomColorString() },
                BorderWidth = 0,
                HoverBackgroundColor = ColorUtil.RandomColorString(),
                HoverBorderColor = ColorUtil.RandomColorString(),
                HoverBorderWidth = 1,
                BorderColor = "#ffffff"
            };

            _barDataSet.AddRange(new double[] { 8, 5, 3, 7 });
            _barChartConfig.Data.Datasets.Add(_barDataSet);

            _barChart.Config = _barChartConfig;
        }


        public CameraReliability()
        {
        }

        public CameraReliability(HttpClient httpClient) : this()
        {
            Http = httpClient;
        }


        public void IncrementCount()
        {
            currentCount++;
        }
    }
}

which are extracted (separeted into code behind) from the SimpleBarChartComponent.razor of the examples of your ChartsJs.Blazor library. If I try to compile the code I get these 2 errors:

  1. Error CS0452 The type 'double' must be a reference type in order to use it as parameter 'TData' in the generic type or method 'BarDataset' SincroADR_GUI.Client C:\Users\dimarco\source\repos\SincroADR\SincroADR_GUI\Client\Pages\CameraReliability.razor.cs 23 Active
  2. Error CS1503 Argument 1: cannot convert from 'ChartJs.Blazor.ChartJS.BarChart.BarDataset' to 'ChartJs.Blazor.ChartJS.MixedChart.IMixableDataset' SincroADR_GUI.Client C:\Users\dimarco\source\repos\SincroADR\SincroADR_GUI\Client\Pages\CameraReliability.razor.cs 74 Active

    For the first problem if you check the class BarDataset it requires a class in the generic type (hence double is not possible), however I am wondering why if you use it in a pure razor file it compiles and works fine. For the second problem it's again the same reason.

    Can anybody tell me why this happens ?

@fededim fededim added the bug Something isn't working label Aug 27, 2020
@fededim
Copy link
Author

fededim commented Aug 27, 2020

Ok the problem was that the latest released Nuget package (1.1.0) was not updated, I switched to the prerelease v.2.0.0-preview1 and the errors are gone (now BarDataset accept also non class types). I close the issue.

@fededim fededim closed this as completed Aug 27, 2020
@fededim
Copy link
Author

fededim commented Aug 27, 2020

I closed the issue too early. With the prerelease package the previous compilation errors are gone, however I have now this error:

  1. Error TS18003 No inputs were found in config file 'C:/Users/dimarco/.nuget/packages/chartjs.blazor/2.0.0-preview1/contentFiles/any/netstandard2.1/tsbuild/release/tsconfig.json'. Specified 'include' paths were '["../../wwwroot/ts/*.ts"]' and 'exclude' paths were '[]'. C:\Users\dimarco.nuget\packages\chartjs.blazor\2.0.0-preview1\contentFiles\any\netstandard2.1\tsbuild\release\tsconfig.json 1 Active

The content of tsconfig.json (inside .nuget folder, not a file of my solution)

{
    "compilerOptions": {
        "allowJs": true,
        "module": "none",
        "target": "es2018",
        "lib": [
            "dom",
            "es2018"
        ],
        "outFile": "../../wwwroot/ChartJsBlazorInterop.js",
        "sourceMap": false,
        "typeRoots": [
            "../../wwwroot/ts/types/"
        ],
        "alwaysStrict": true
    },
    "include": [
        "../../wwwroot/ts/*.ts"
    ],
    "compileOnSave": true
}

It seems that VisualStudio is trying to compile TypeScript files, why ? Since there are no typescript files, I am wondering why it returns an error.

@fededim fededim reopened this Aug 27, 2020
@fededim
Copy link
Author

fededim commented Aug 27, 2020

I have also tried to add the package Microsoft.TypeScript.MSBuild as suggested by VisualStudio, however the error remains.

@fededim
Copy link
Author

fededim commented Aug 27, 2020

There is already an issue about my problem, I close again this one and I'll continue there.

@fededim fededim closed this as completed Aug 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant