使用Google Charts Tools饼图,即使值= 0,也会在图例中显示项目

Luk*_*een 25 javascript google-visualization

我正在使用谷歌图表工具,特别是饼图.

当然,如果某个项的值为0,则它​​不会显示在饼图中(因为它占据饼图的0%).但是,它也不会在图例中显示.

如何操作初始化选项仍然在图例中显示0值项,以便用户可以看到该项存在,它只有0值?

oca*_*nal 58

设置sliceVisibilityThreshold为零将解决您的问题.

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
                 });
}
?
Run Code Online (Sandbox Code Playgroud)

  • 正是我在寻找 - 只是无法理解API中的描述!谢谢! (2认同)