图例显示 true 时 Chartjs 不渲染

问题描述 投票:0回答:0

我正在尝试使用chartjs(pie)在屏幕上显示一些数据。第一次加载时,屏幕工作正常,但是当尝试更新饼图(使用创建饼图时使用的相同代码)时,它会消失并且不会在控制台中显示错误。

当我尝试更新图表数据时,下面的代码不起作用

chartList[0].destroy();
chartList[0] = new Chart($("#chart"), {
                type: "pie",
                data: {
                    datasets: [{
                        data: [15,20,30],
                        backgroundColor: ["rgba(255, 99, 132, 1)","rgba(255, 206, 86, 1)","rgba(54, 162, 235, 1)"],
                    }],
                    labels: ["Red","Yellow","Blue"],
                },
                options: {
                    legend: {
                        display: true,
                        position: 'bottom',
                    }
                }
            });

但是如果我输入“display: false”,它会正常渲染,但没有标题。

chartList[0].destroy();
chartList[0] = new Chart($("#chart"), {
                type: "pie",
                data: {
                    datasets: [{
                        data: [15,20,30],
                        backgroundColor: ["rgba(255, 99, 132, 1)","rgba(255, 206, 86, 1)","rgba(54, 162, 235, 1)"],
                    }],
                    labels: ["Red","Yellow","Blue"],
                },
                options: {
                    legend: {
                        display: false,
                        position: 'bottom',
                    }
                }
            });

https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.1.4/Chart.min.js

我已经尝试使用最新版本的 ChartJS,但问题仍然存在。

chart.js destroy redraw
© www.soinside.com 2019 - 2024. All rights reserved.