ant-design-blazor / ant-design-charts-blazor

A Blazor chart library, based on G2Plot
https://ant-design-blazor.github.io/ant-design-charts-blazor/
Apache License 2.0
178 stars 40 forks source link

Pie chart not show when load data from api #35

Open huanbd opened 3 years ago

huanbd commented 3 years ago

Hi, like this issue, but this case is Pie chart, and can't use ChangeDatamethod 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"
            }
        };
hohoan commented 2 years ago

@huanbd Have you solved this problem yet?