如何在堆叠条中设置一列的样式?

How to style one column in a stacked bar?

我希望最后一列中的所有条都具有特定颜色。 使用以下代码,只有最上面的栏被设置样式(参见 http://jsfiddle.net/kalyfe/gvczd6nx/):

var data = google.visualization.arrayToDataTable([
    ['week', 'apples', 'bananas', {role: 'style'}],
    ['last week', 5, 17, ''],
    ['this week', 9, 22, ''],
    ['projection', 11, 27, 'color:#ddd;']
]);

我还能如何将样式应用到堆积条形图中的列?

设置苹果栏的样式,就像香蕉栏的样式一样

var data = google.visualization.arrayToDataTable([
    ['week', 'apples', {role: 'style'}, 'bananas', {role: 'style'}],
    ['last week', 5, '', 17, ''],
    ['this week', 9, '', 22, ''],
    ['projection', 11, 'color:#ddd;', 27, 'color:#ddd;']
]);

http://jsfiddle.net/gvczd6nx/3/

如果你想为每一列单独设置样式,那么按照@R3tep 提到的那样给出颜色值,但如果你想为一组列设置它,那么可以这样尝试:

   var data = google.visualization.arrayToDataTable([
        ['week', 'apples', 'bananas','oranges'],
        ['last week', 5, 17, 11],
        ['this week', 9, 22, 12],
        ['projection', 11, 27,10]
    ]);

  new google.visualization.ColumnChart(document.getElementById('chart')).
    draw(data, {
        title: "Weekly fruit intake",
        width: 600,
        height: 400,
        isStacked: true,
        colors: ['#0f0', '#ddd', '#ec8f6e', '#f3b49f', '#f6c7b6']
    });
}

查看演示 here

也看到这个:https://developers.google.com/chart/interactive/docs/gallery/columnchart