我想添加CSS樣式到谷歌圖表表格。我嘗試這樣做:樣式谷歌圖表表格
https://developers.google.com/chart/interactive/docs/gallery/table#customproperties
在第一個單元格(麥克),但沒有奏效。我在options變量中設置了allowHtml爲true。我怎樣才能改變單個單元格的背景,文字顏色等?謝謝。
<script type="text/javascript">
google.load('visualization', '1', {packages:['table']});
google.setOnLoadCallback(drawTable);
function drawTable() {
var data = new google.visualization.DataTable();
data.addColumn('string', 'Employee Name');
data.addColumn('date', 'Start Date');
data.addRows(3);
data.setCell(0, 0, 'Mike', {style: 'background-color:red;'});
data.setCell(0, 1, new Date(2008, 1, 28));
data.setCell(1, 0, 'Bob');
data.setCell(1, 1, new Date(2007, 5, 1));
data.setCell(2, 0, 'Alice');
data.setCell(2, 1, new Date(2006, 7, 16));
var options = {
allowHtml: true
};
// Create a formatter.
// This example uses object literal notation to define the options.
var formatter = new google.visualization.DateFormat({formatType: 'long'});
// Reformat our data.
formatter.format(data, 1);
// Draw our data
var table = new google.visualization.Table(document.getElementById('dateformat_div'));
table.draw(data, options);
}
</script>
在谷歌圖表表不是SVG,它是HTML,所以你應該能夠簡單地通過增加新的CSS樣式改變風格。 – user1477388
你讀過這個嗎? https://developers.google.com/chart/interactive/docs/examples#custom_table_example –
謝謝Bondye! – carlosgg