使用Google Charts Tools Pie Chart,即使值= 0,也可以在图例中显示项目 [英] Display item in legend even if value = 0 with Google Charts Tools Pie Chart
本文介绍了使用Google Charts Tools Pie Chart,即使值= 0,也可以在图例中显示项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用Google Charts Tools,特别是饼图。当然,如果一个项目的值为0,它不会显示在饼图中(因为它占据了饼图的0%)。但是,它也不会显示在图例中。
如何操作初始化选项以在图例中仍显示0值项目,以便用户可以看到项目存在,它只有0值?
解决方案
将 sliceVisibilityThreshold
设置为零即可解决您的问题。
函数drawVisualization(){
//创建并填充数据表。
var data = google.visualization.arrayToDataTable([
['Task','Hours per Day'],
['Work',11],
['Eat' ,0],
['Commute',2],
['Watch TV',2],
['Sleep',7]
]);
//创建并绘制可视化文件。
new google.visualization.PieChart(document.getElementById('visualization'))。
draw(data,{title:那么,今天过得如何?,
sliceVisibilityThreshold:0
});
}
I'm using Google Charts Tools, specifically the Pie Chart.
Naturally, if a item has a value of 0, it is not displayed in the pie (since it occupies 0% of the pie). However, it doesn't display in the legend either.
How can I manipulate the initialization options to still show a 0 value item in the legend, so that users can see that the item exists, it just has a 0 value?
解决方案
setting sliceVisibilityThreshold
as zero will solve your problem.
function drawVisualization() {
// Create and populate the data table.
var data = google.visualization.arrayToDataTable([
['Task', 'Hours per Day'],
['Work', 11],
['Eat', 0],
['Commute', 2],
['Watch TV', 2],
['Sleep', 7]
]);
// Create and draw the visualization.
new google.visualization.PieChart(document.getElementById('visualization')).
draw(data, {title:"So, how was your day?",
sliceVisibilityThreshold:0
});
}
这篇关于使用Google Charts Tools Pie Chart,即使值= 0,也可以在图例中显示项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文