Google Charts stacked columns with different annotations for each piece of the column

可紊 提交于 2019-12-04 06:36:58

You need to add another annotation column after your "Good" column:

view.setColumns([{
    label: 'Date',
    type: 'string',
    calc: function (dt, row) {
        var str = dt.getValue(row, 0);
        return { v: str, f: str.toString('dd/MM/aaaa') };
    }
}, {
    label: 'Good',
    type: 'number',
    calc: function (dt, row) {
        var good = dt.getValue(row, 1);
        var bad = dt.getValue(row, 2);
        return { v: good / (good + bad), f: good.toString() };
    }
}, {
    role: 'annotation',
    type: 'string',
    calc: function (dt, row) {
        var good = dt.getValue(row, 1);
        var bad = dt.getValue(row, 2);
        var perc = (good / (good + bad)) * 100;
        var ann = perc.toFixed(2) + "%";
        return ann;
    }
}, {
    label: 'Bad',
    type: 'number',
    calc: function (dt, row) {
        var good = dt.getValue(row, 1);
        var bad = dt.getValue(row, 2);
        return { v: bad / (good + bad), f: bad.toString() };
    }
}, {
    role: 'annotation',
    type: 'string',
    calc: function (dt, row) {
        var good = dt.getValue(row, 1);
        var bad = dt.getValue(row, 2);
        var perc = (bad / (good + bad)) * 100;
        var ann = perc.toFixed(2) + "%";
        return ann;
    }
}]);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!