google.charts.load('current', {
callback: drawChart,
packages: ['corechart']
});
function drawChart() {
var data = google.visualization.arrayToDataTable([
['Year', 'Y1', 'Y2'],
['2010', 10, 14],
['2020', 14, 22],
['2030', 16, 24],
['2040', 22, 30],
['2050', 28, 36]
]);
var seriesColors = ['#00ffff', '#ff00ff'];
var rgbaMap = {
'#00ffff': 'rgba(0,255,0,0.5)',
'#ff00ff': 'rgba(255,0,0,0.5)'
};
var options = {
colors: seriesColors,
};
var chartDiv = document.getElementById('chart_div');
var chart = new google.visualization.ColumnChart(chartDiv);
google.visualization.events.addListener(chart, 'ready', function () {
Array.prototype.forEach.call(chartDiv.getElementsByTagName('rect'), function(rect) {
if (seriesColors.indexOf(rect.getAttribute('fill')) > -1) {
rect.setAttribute('fill', rgbaMap[rect.getAttribute('fill')]);
}
});
});
chart.draw(data, options);
}
<script src="https://www.gstatic.com/charts/loader.js"></script>
<div id="chart_div"></div>
dataOpacity
属性,它被记录为设置所有系列的透明度。但未记录的是,它可以在series:
元素内部按系列提供,然后它将控制单个系列中所有数据点的透明度。至于系列中的个别数据点,则可以从{role:"style"}
数据列中提供fill-opacity
属性。 - GSerg