Chart.js我在 ASP.NET Blazor 頁面上實作了一個餅圖。現在我想將我的圖表更改為圓環圖。
但沒有合適的組件用于匯入圓環圖。
@using ChartJs.Blazor.donutChart //This is not correct.I tried like this
請幫我將餅圖更改為 donutChart。謝謝。
@page "/counter"
@using ChartJs.Blazor.PieChart
<h1>Pie Chart Example</h1>
<Chart Config="_config"></Chart>
@code{
private PieConfig _config;
protected override void OnInitialized()
{
_config = new PieConfig
{
Options = new PieOptions
{
Responsive = true,
Title = new OptionsTitle
{
Display = true,
Text = "ChartJs.Blazor Pie Chart"
}
}
};
foreach (string color in new[] { "Red", "Yellow", "Green", "Blue" })
{
_config.Data.Labels.Add(color);
}
PieDataset<int> dataset = new PieDataset<int>(new[] { 6, 5, 3, 7 })
{
BackgroundColor = new[]
{
ColorUtil.ColorHexString(255, 99, 132), // Slice 1 aka "Red"
ColorUtil.ColorHexString(255, 205, 86), // Slice 2 aka "Yellow"
ColorUtil.ColorHexString(75, 192, 192), // Slice 3 aka "Green"
ColorUtil.ColorHexString(54, 162, 235), // Slice 4 aka "Blue"
}
};
_config.Data.Datasets.Add(dataset);
}
}
uj5u.com熱心網友回復:
參考
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/464856.html
