Bar Chat with date in Axis X C# BLaZor
sblb
1,231
Reputation points
Hi,
I can't get the months of January to December on the X axis.
The only month that is good is where I have data ie in my case November.
How can I do this?
The code of API :
public IActionResult RevenueByMonth()
{
var result = context.Developers
.Where(opportunity => opportunity.Statut == "Closed")
.ToList()
.GroupBy(opportunity => new DateTime(opportunity.DateSolde.Year, opportunity.DateSolde.Month, 1))
.Select(group => new
{
Revenue = group.Count(),
Month = group.Key
});
return Ok(JsonSerializer.Serialize(result, new JsonSerializerOptions
{
PropertyNamingPolicy = null
}));
}
In razor page
<RadzenFieldset Text="Graphique">
<RadzenChart>
<RadzenColumnSeries Data="@graphSales" CategoryProperty="Month" ValueProperty="Revenue" LineType="LineType.Dashed" />
<RadzenColumnOptions Radius="5" />
<RadzenCategoryAxis Padding="20" FormatString="{0:MMM}" />
<RadzenValueAxis>
<RadzenGridLines Visible="true" />
<RadzenAxisTitle Text="Quantité" />
</RadzenValueAxis>
</RadzenChart>
</RadzenFieldset>
@code {
private IEnumerable<RevenueByMonth> graphSales;
protected override async Task OnInitializedAsync()
{
graphSales = await RevenueByMonth();
}
}
I use the class
public class RevenueByMonth
{
public DateTime Month { get; set; }
public int Revenue { get; set; }
}
Thanks in advance to your help!
Developer technologies | .NET | Blazor
1,674 questions
Developer technologies | C#
11,578 questions
Sign in to answer