gpt4 book ai didi

javascript - 在 Google 堆积图中添加并显示单列中的列值

转载 作者:行者123 更新时间:2023-11-28 06:37:22 32 4
gpt4 key购买 nike

我正在使用 Google 图表创建一个堆叠图。

enter image description here

这里我有两列(一列是蓝色,另一列是红色)。在每个中我都显示了值。

我的代码是:

var view = new google.visualization.DataView(data);
view.setColumns([0, 1, {
calc: "stringify",
sourceColumn: 1,
type: "string",
role: "annotation"
}, 2, {
calc: "stringify",
sourceColumn: 2,
type: "string",
role: "annotation"
}]);

但我必须显示总值(value)(蓝色+红色)。

我的图表应该如下所示:

enter image description here

我该怎么做?任何帮助都非常感激......

最佳答案

提供calc函数并丢失sourceColumn
像这样的东西应该有效...

var view = new google.visualization.DataView(data);
view.setColumns([0, 1, 2, {
calc: getRowTotal,
type: "number",
role: "annotation"
}]);

function getRowTotal(dataView, row) {
var val1;
var val2;

val1 = dataView.getValue(row, 1) || 0;
val2 = dataView.getValue(row, 2) || 0;

return val1 + val2;
}

关于javascript - 在 Google 堆积图中添加并显示单列中的列值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34157604/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com