56 lines
2.0 KiB
Plaintext
56 lines
2.0 KiB
Plaintext
@using Shared.DTOs
|
|
<LineChart @ref="lineChart" />
|
|
|
|
@code {
|
|
private LineChart lineChart = default!;
|
|
private LineChartOptions lineChartOptions = default!;
|
|
private ChartData chartData = default!;
|
|
[Parameter] public List<IdNameByCount<int>> items { get;set; }
|
|
protected override void OnInitialized()
|
|
{
|
|
|
|
|
|
var colors = ColorBuilder.CategoricalTwelveColors;
|
|
|
|
var labels = items.OrderBy(o => o.ID).Select(s => s.Title).ToList();
|
|
var datasets = new List<IChartDataset>();
|
|
|
|
var dataset1 = new LineChartDataset
|
|
{
|
|
|
|
Label = "فروش",
|
|
Data = items.OrderBy(o => o.ID).Select(s => decimal.ToDouble(s.count.Value)).ToList(),
|
|
BackgroundColor = new List<string> { colors[0] },
|
|
BorderColor = new List<string> { colors[0] },
|
|
BorderWidth = new List<double> { 2 },
|
|
HoverBorderWidth = new List<double> { 4 },
|
|
PointBackgroundColor = new List<string> { colors[0] },
|
|
PointRadius = new List<int> { 0 }, // hide points
|
|
PointHoverRadius = new List<int> { 4 }
|
|
};
|
|
datasets.Add(dataset1);
|
|
|
|
|
|
chartData = new ChartData { Labels = labels, Datasets = datasets };
|
|
|
|
lineChartOptions = new();
|
|
lineChartOptions.Responsive = true;
|
|
lineChartOptions.Interaction = new Interaction { Mode = InteractionMode.Index };
|
|
|
|
lineChartOptions.Scales.X!.Title = new ChartAxesTitle { Text = "روز", Display = true };
|
|
lineChartOptions.Scales.Y!.Title = new ChartAxesTitle { Text = "میران", Display = true };
|
|
|
|
lineChartOptions.Plugins.Title!.Text = "گزارش (ماه جاری)";
|
|
lineChartOptions.Plugins.Title.Display = true;
|
|
}
|
|
|
|
protected override async Task OnAfterRenderAsync(bool firstRender)
|
|
{
|
|
if (firstRender)
|
|
{
|
|
await lineChart.InitializeAsync(chartData, lineChartOptions);
|
|
}
|
|
await base.OnAfterRenderAsync(firstRender);
|
|
}
|
|
|
|
} |