From cc272cac29d6472bd2bb218c7b1748b864286de1 Mon Sep 17 00:00:00 2001 From: "zaccaria.majid" Date: Mon, 10 Oct 2022 17:12:09 +0200 Subject: [PATCH] Plot ODL --- MP.SPEC/Components/Chart/Doughnut.razor.cs | 200 ++++++--------------- MP.SPEC/Components/ListODL.razor | 88 +++++++-- MP.SPEC/Components/ListODL.razor.cs | 25 ++- MP.SPEC/Components/ODLPlot.razor | 77 ++------ MP.SPEC/Components/ODLPlot.razor.cs | 73 +++++++- MP.SPEC/MP.SPEC.csproj | 2 +- MP.SPEC/Resources/ChangeLog.html | 2 +- MP.SPEC/Resources/VersNum.txt | 2 +- MP.SPEC/Resources/manifest.xml | 2 +- 9 files changed, 241 insertions(+), 230 deletions(-) diff --git a/MP.SPEC/Components/Chart/Doughnut.razor.cs b/MP.SPEC/Components/Chart/Doughnut.razor.cs index 04c95853..49abb269 100644 --- a/MP.SPEC/Components/Chart/Doughnut.razor.cs +++ b/MP.SPEC/Components/Chart/Doughnut.razor.cs @@ -6,155 +6,61 @@ namespace MP.SPEC.Components.Chart { public partial class Doughnut { - #region Public Properties - - [Parameter] - public double AspRatio { get; set; } = 0; - - [Parameter] - public List backColor { get; set; } = new List(); - - [Parameter] - public int ChartId - { - get - { - return Id; - } - set - { - Id = value; - } - } - - //[Parameter] - //public List DataTS - //{ - // get - // { - // return _DataTS; - // } - - // set - // { - // _DataTS = value; - // //var pUpd = Task.Run(async () => await renderChart()); - // //pUpd.Wait(); - // } - //} - - [Parameter] - public List Labels { get; set; } = new List(); - - //[Parameter] - //public List lineColor { get; set; } = new List(); - - [Parameter] - public int lTens { get; set; } = 0; - - //[Parameter] - //public string MaxValue { get; set; } = "0"; - - //[Parameter] - //public string MinValue { get; set; } = "0"; - - //[Parameter] - //public List pointColor { get; set; } = new List(); - - [Parameter] - public string Title { get; set; } = "Demo Line"; - - #endregion Public Properties - - #region Protected Properties - - protected int Id { get; set; } = 0; - - #endregion Protected Properties - - #region Protected Methods - - /// - /// Inizializzazione rendering componente - /// - /// partendo da qui: https://www.williamleme.com/posts/2020/003-chartjs-blazor/ - /// https://www.puresourcecode.com/dotnet/blazor/using-chart-js-with-blazor/ https://www.tutorialsteacher.com/csharp/csharp-anonymous-type - /// - /// - /// - protected override async Task OnAfterRenderAsync(bool firstRender) - { - await renderChart(); - } - - /// - /// Inizializzazione rendering componente - /// - /// partendo da qui: https://www.williamleme.com/posts/2020/003-chartjs-blazor/ - /// https://www.puresourcecode.com/dotnet/blazor/using-chart-js-with-blazor/ https://www.tutorialsteacher.com/csharp/csharp-anonymous-type - /// - /// - /// - protected async Task renderChart() - { - // creazione di un oggetto anonymous type con tutte le opzioni da passare a chart.js - var config = new - { - type = "doughnut", - options = new - { - responsive = true, - //scales = new - //{ - // yAxes = new - // { - // display = true, - // position = "right", - // ticks = new - // { - // maxTicksLimit = 10 - // } - // }, - // xAxes = new - // { - // type = "time", - // distribution = "linear", - // } - //}, - plugins = new - { - legend = new - { - display = false - }, - }, - Animation = false, - AspectRatio = AspRatio == 0 ? "auto" : $"{AspRatio}" - }, - data = new - { - labels = Labels, - datasets = new[]{new - { - data = 300, pointBorderColor = backColor, backgroundColor = backColor, fill = true, PointRadius = 2, BorderWidth = 1, lineTension = lTens, stepped = false, label = Title - } - } - } - } - - ; - await JSRuntime.InvokeVoidAsync("setup", Id, config); - } - - #endregion Protected Methods - - #region Private Properties - - private List _DataTS { get; set; } = null!; - [Inject] private IJSRuntime JSRuntime { get; set; } = null!; - #endregion Private Properties + + public enum ChartType + { + Pie, + Bar, + Doughnut + } + + [Parameter] + public string Id { get; set; } + + [Parameter] + public ChartType Type { get; set; } + + [Parameter] + public double[] Data { get; set; } + + [Parameter] + public string[] BackgroundColor { get; set; } + + [Parameter] + public string[] Labels { get; set; } + + protected override async Task OnAfterRenderAsync(bool firstRender) + { + var config = new + { + Type = Type.ToString().ToLower(), + Options = new + { + Responsive = true, + Scales = new + { + YAxes = new[] + { + new { Ticks = new { + BeginAtZero=true + } } + } + } + }, + Data = new + { + Datasets = new[] + { + new { Data = Data, BackgroundColor = BackgroundColor} + }, + Labels = Labels + } + }; + + await JSRuntime.InvokeVoidAsync("setup", Id, config); + } } } \ No newline at end of file diff --git a/MP.SPEC/Components/ListODL.razor b/MP.SPEC/Components/ListODL.razor index 9bcc651b..08e70a35 100644 --- a/MP.SPEC/Components/ListODL.razor +++ b/MP.SPEC/Components/ListODL.razor @@ -87,27 +87,91 @@ else