Files
moadiran/TaxPayerFull/Layout/SaleChart.razor

62 lines
2.3 KiB
Plaintext
Raw Normal View History

2024-06-22 22:31:04 +03:30
@using Shared.DTOs
<LineChart @ref="lineChart" />
2024-06-22 16:29:44 +03:30
@code {
private LineChart lineChart = default!;
private LineChartOptions lineChartOptions = default!;
private ChartData chartData = default!;
public List<IdNameByCount<int>> items = new List<IdNameByCount<int>>();
protected override void OnInitialized()
{
items.AddRange(new List<IdNameByCount<int>>()
{
new IdNameByCount<int>{ID=0,Title="1",count=10},
new IdNameByCount<int>{ID=1,Title="2",count=5},
new IdNameByCount<int>{ID=2,Title="3",count=12},
new IdNameByCount<int>{ID=3,Title="4",count=21}
});
2024-06-22 22:31:04 +03:30
var colors = ColorBuilder.CategoricalTwelveColors;
2024-06-22 16:29:44 +03:30
2024-06-22 22:31:04 +03:30
var labels = items.OrderBy(o => o.ID).Select(s => s.Title).ToList();
2024-06-22 16:29:44 +03:30
var datasets = new List<IChartDataset>();
2024-06-22 22:31:04 +03:30
var dataset1 = new LineChartDataset
2024-06-22 16:29:44 +03:30
{
2024-06-22 22:31:04 +03:30
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] },
2024-06-22 16:29:44 +03:30
BorderWidth = new List<double> { 2 },
HoverBorderWidth = new List<double> { 4 },
2024-06-22 22:31:04 +03:30
PointBackgroundColor = new List<string> { colors[0] },
2024-06-22 16:29:44 +03:30
PointRadius = new List<int> { 0 }, // hide points
2024-06-22 22:31:04 +03:30
PointHoverRadius = new List<int> { 4 }
2024-06-22 16:29:44 +03:30
};
2024-06-22 22:31:04 +03:30
datasets.Add(dataset1);
2024-06-22 16:29:44 +03:30
2024-06-22 22:31:04 +03:30
chartData = new ChartData { Labels = labels, Datasets = datasets };
2024-06-22 16:29:44 +03:30
2024-06-22 22:31:04 +03:30
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;
2024-06-22 16:29:44 +03:30
}
2024-06-22 22:31:04 +03:30
protected override async Task OnAfterRenderAsync(bool firstRender)
2024-06-22 16:29:44 +03:30
{
2024-06-22 22:31:04 +03:30
if (firstRender)
2024-06-22 16:29:44 +03:30
{
2024-06-22 22:31:04 +03:30
await lineChart.InitializeAsync(chartData, lineChartOptions);
2024-06-22 16:29:44 +03:30
}
2024-06-22 22:31:04 +03:30
await base.OnAfterRenderAsync(firstRender);
2024-06-22 16:29:44 +03:30
}
}