retablissement CI

master
Maxime ROCHER 2 months ago
parent 34abbf746b
commit a16dca6156

@ -1,14 +0,0 @@
@page "/graph"
@using Syncfusion.Blazor.Charts
<script src=https://cdn.syncfusion.com/blazor/22.1.38/syncfusion-blazor.min.js type="text/javascript"></script>
<SfChart>
<ChartPrimaryXAxis ValueType="Syncfusion.Blazor.Charts.ValueType.Category"></ChartPrimaryXAxis>
<ChartSeriesCollection>
<ChartSeries DataSource="@Sales" Opacity="1" Fill="blue" XName="Month" YName="SalesValue" Type="ChartSeriesType.Column" ColumnSpacing="0.2" ColumnWidth="0.8">
</ChartSeries>
</ChartSeriesCollection>
</SfChart>

@ -1,92 +0,0 @@
using Microsoft.AspNetCore.Components;
using MudBlazor;
using Syncfusion.Blazor.Charts.Chart.Internal;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Threading.Tasks;
using WF_WebAdmin.Model;
using WF_WebAdmin.Service;
namespace WF_WebAdmin.Pages
{
public class SalesInfo
{
public string Month { get; set; }
public double SalesValue { get; set; }
}
public partial class ComposentComplex : ComponentBase
{
[Inject] public ICommentaryService CommentaryService { get; set; } = default!;
public List<string> Labels { get; set; } = new();
public List<double[]> ChartData { get; set; } = new();
public List<int> AvailableYears { get; set; } = new();
public int SelectedYear { get; set; }
private List<Commentary> AllComments = new();
public List<SalesInfo> Sales = new List<SalesInfo>
{
new SalesInfo { Month = "Jan", SalesValue = 35 },
new SalesInfo { Month = "Feb", SalesValue = 28 },
new SalesInfo { Month = "Mar", SalesValue = 34 },
new SalesInfo { Month = "Apr", SalesValue = 28 },
new SalesInfo { Month = "May", SalesValue = 40 },
new SalesInfo { Month = "Jun", SalesValue = 32 },
new SalesInfo { Month = "Jul", SalesValue = 35 },
new SalesInfo { Month = "Aug", SalesValue = 55 },
new SalesInfo { Month = "Sep", SalesValue = 38 },
new SalesInfo { Month = "Oct", SalesValue = 30 },
new SalesInfo { Month = "Nov", SalesValue = 25 },
new SalesInfo { Month = "Dec", SalesValue = 32 }
};
protected override async Task OnInitializedAsync()
{
// Charger tous les commentaires
AllComments = await CommentaryService.GetCommentsAsync();
if (!AllComments.Any())
{
Labels = new List<string> { "Aucun commentaire" };
ChartData = new List<double[]> { new double[] { 0 } };
return;
}
AvailableYears = AllComments
.Select(c => c.DateCreation.Year)
.Distinct()
.OrderBy(y => y)
.ToList();
SelectedYear = AvailableYears.Max();
UpdateChartData(SelectedYear);
}
private void UpdateChartData(int newYear)
{
SelectedYear = newYear;
var filteredComments = AllComments
.Where(c => c.DateCreation.Year == SelectedYear)
.ToList();
if (!filteredComments.Any())
{
Labels = new List<string> { "Aucun commentaire" };
ChartData = new List<double[]> { new double[] { 0 } };
return;
}
foreach (var sale in Sales)
{
sale.SalesValue = filteredComments.Count(c => c.DateCreation.Month.ToString("MMM", CultureInfo.InvariantCulture) == sale.Month);
}
}
}
}

@ -6,3 +6,7 @@
}
<component type="typeof(App)" render-mode="ServerPrerendered" />
<body>
<script src=https://cdn.syncfusion.com/blazor/22.1.38/syncfusion-blazor.min.js type="text/javascript"></script>
</body>

Loading…
Cancel
Save