我试图使用c3.js没有数据选项但不知何故它对我不起作用.
我的小提琴:http: //jsfiddle.net/ymqef2ut/7/
我试图根据c3文档使用空选项:
empty: { label: { text: "No Data Available" } }
Run Code Online (Sandbox Code Playgroud)
你的小提琴有两个问题:
问题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
Run Code Online (Sandbox Code Playgroud)
空应该是数据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
},
Run Code Online (Sandbox Code Playgroud)
问题2:当数据不存在时,列数组应为空数组
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"
}
}
},
Run Code Online (Sandbox Code Playgroud)
在这里工作代码
测试用例:检查伊拉克
希望这可以帮助!