3
我已經創建了一個谷歌條形圖使用谷歌的可視化API,我試圖添加一個將用於樣式的列。以下是使用.addcolumn()在下面的實現,然後將顏色字段添加到每一行,但每個小節仍然是默認的藍色。谷歌條形圖不能改變個別條形顏色
<script type="text/javascript">
// Runs onload to build the first default chart and load the bar chart package
var jsonCoachCount;
window.onload = function(){
jsonCoachCount = JSON.parse('[{"Service_Count":"4","Name":"Other"}, {"Service_Count":"4","Name":"Campus Network"},{"Service_Count":"3","Name":"[email protected]"},{"Service_Count":"2","Name":"Customer Service"},{"Service_Count":"1","Name":"Blackboard Collaborate"},{"Service_Count":"1","Name":"Office 365"},{"Service_Count":"1","Name":"Multiple"},{"Service_Count":"1","Name":"Office-ionado"},{"Service_Count":"1","Name":"Case Notes"},{"Service_Count":"1","Name":"ResNet"}]');
// Load the Visualization API and the barchart package.
google.charts.load('current', {'packages': ['bar']});
// Set a callback to run when the Google Visualization API is loaded.
google.charts.setOnLoadCallback(drawChart);
};
function drawChart(){
var servicesData = new google.visualization.DataTable();
servicesData.addColumn('string', 'Service');
servicesData.addColumn('number', 'Number of Coaches');
servicesData.addColumn({type:'string', role:'style'});
for(i = 0; i < jsonCoachCount.length; i++){
tempArray =[];
tempArray.push(String (jsonCoachCount[i]['Name']),
parseInt(jsonCoachCount[i]['Service_Count']),
'color:Red');
servicesData.addRow(tempArray);
}
var options = {
backgroundColor: {
fill: '#E8E4D8'
},
legend: { position: 'none' },
titleTextStyle:{
bold: 'true'
},
chart: {
title: 'Coaches by Service',
subtitle: 'Coaches by Services: From 2016-09-10 until Today'
},
bar: {
groupWidth: '60%'
},
'hAxis': {
textStyle: {
fontSize: 11
}
}
};
var chart = new google.charts.Bar(document.getElementById('servicesChart'));
chart.draw(servicesData, google.charts.Bar.convertOptions(options));
}
<html>
<head>
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
</head>
<body>
</body>
</html>
我不知道我要去哪裏錯了,或者如果我誤解了一塊文檔。非常感謝幫助我更改條形圖上酒吧的顏色,謝謝!
一個很好的解釋,我已經明白了,謝謝! – chaseshak
有沒有什麼辦法讓標籤與水平材料條一起工作? – bfritz
對不起,哪些標籤?你是指註釋嗎?如果是這樣,不用標準圖表選項,但你可以嘗試添加你自己的... – WhiteHat