ant-design-charts-blazor
ant-design-charts-blazor copied to clipboard
Pie chart not show when load data from api
Hi, like this issue, but this case is Pie chart, and can't use ChangeData method to load data. Pie chart only run when initialize data manual
This is code when load data from api
<Pie @ref="pie1" Data="data2" Config="pieconfig"></Pie>
IChartComponent pie1;
object[] data_pie = new object[10];
protected override async Task OnInitializedAsync()
{
var dataApi = await client.GetFromJsonAsync<DataObject>("api/data");
if (dataApi.Data!= null && dataApi.Data.Count > 0)
{
data_pie = new object[dataApi.Data.Count];
for (var i = 0; i < dataApi.Data.Count; i++)
{
tmp = dataApi.Data[i];
data_pie [i] = new { value = tmp.A, type = tmp.B};
}
pie1.ChangeData(data_pie , true);
}
}
readonly PieConfig pieconfig = new PieConfig
{
ForceFit = true,
Title = new AntDesign.Charts.Title
{
Visible = true,
Text = "Multicolor Pie Chart"
},
Description = new Description
{
Visible = true,
Text = "Specify the color mapping field (colorField), and the pie slice will be displayed in different colors according to the field data. To specify the color, you need to configure the color as an array. \nWhen the pie chart label type is set to inner, the label will be displayed inside the slice. Set the offset value of the offset control label."
},
Radius = 0.8,
AngleField = "value",
ColorField = "type",
Label = new PieLabelConfig
{
Visible = true,
Type = "inner"
}
};
@huanbd Have you solved this problem yet?