数据中的一条记录使用浮动图时未创建饼图

Pie Chart not created when one record in data uses Flot chart

本文关键字:创建 一条 记录 数据      更新时间:2023-09-26

如果数据中只有一条记录,则不会显示饼图。我正在使用Flot图表。

<script type='text/javascript'>
$(function () {
    var data = [{
        label: "Series1",
        data: 1
    }, ];
    $.plot($("#graph11"), data, {
        series: {
            pie: {
                show: true,
                radius: 1,
                tilt: 0.5,
                label: {
                    show: true,
                    radius: 1,
                    formatter: function (label, series) {
                        return '<div style="font-size:8pt;text-align:center;padding:2px;color:white;">' + label + '<br/>' + Math.round(series.percent) + '%</div>';
                    },
                    background: {
                        opacity: 0.8
                    }
                },
                combine: {
                    color: '#999',
                    threshold: 0.1
                }
            }
        },
        legend: {
            show: false
        }
    });
});
</script>

如果数据中只有一条记录,则不会显示饼图。

代码看起来不错。

如果您在旧版本的IE(<=7)中运行此程序:

var data = [{
    label: "Series1",
    data: 1
}, ];  // <--remove the trailing comma

它会死在后面的逗号上。