如何使用c3.js无数据选项

How to use c3.js No data option

我正在尝试使用 c3.js 中的无数据选项,但不知何故它对我不起作用。

我的 js fiddle: http://jsfiddle.net/ymqef2ut/7/

我正在尝试根据 c3 文档使用空选项:

 empty: { label: { text: "No Data Available" }   }

您的 fiddle 中有两个问题:

问题 1:

   data: {
        columns: [
            ['electricity plants', elec_plants],
            ['CHP plants', chp_planrs],
            ['Unallocated autoproducers / Other energy industry own use', auto_pro],
            ['Other', other_elec],
        ],
        type : 'pie'
    },
        empty: { label: { text: "No Data Available" }   },//this is wrong should be a part of data 

空应该是数据的一部分json如下

   data: {
        columns: [
            ['electricity plants', elec_plants],
            ['CHP plants', chp_planrs],
            ['Unallocated autoproducers / Other energy industry own use', auto_pro],
            ['Other', other_elec],
        ],
        type : 'pie',
        empty: { label: { text: "No Data Available" }   },//this is correct
    },

问题二: 当数据不存在时,列数组应该是一个空数组

var col5 = [];//set empty array
            if (resi || com || agri || other_sec){
                col5 = [['Residential', resi],
                        ['Commercial and public services', com],
                        ['Agriculture/forestry', agri],
                        ['Other', other_sec]]
            }
            //if all are 0 then col = []
            var chart = c3.generate({
                bindto: "#chart_5",
                data: {
                    columns: col5,
                    type: 'pie',
                    empty: {
                        label: {
                            text: "No Data Available"
                        }
                    }
                },       

工作代码here

测试用例:检查伊拉克

希望对您有所帮助!