After creating a table in Google Visualization with the provided code, I am struggling to customize the formatting of the header row and table rows using CSS. Despite going through the Configuration Options, I am unclear on how to proceed and would appreciate a clear step-by-step explanation due to my limited coding experience.
I am specifically seeking guidance on what modifications to make in the existing code to apply my custom CSS, as well as how to structure my main CSS stylesheet. Should I use #headerRow { }
or .headerRow { }
for the header styling?
It is important to note that I am inserting this code via a custom field in Wordpress, in case that affects the solution.
If my question is unclear, please feel free to ask for further clarification. Thank you.
UPDATE: @asgallant - I am still encountering issues even after changing to headerCell and tableCell.
Here is my updated code:
<html>
<head>
<script type='text/javascript' src='https://www.google.com/jsapi'></script>
<script type='text/javascript'>
google.load('visualization', '1', {packages:['table']});
google.setOnLoadCallback(drawTable);
function drawTable() {
var cssClassNames = {
headerCell: 'headerCell',
tableCell: 'tableCell'};
var options = {'allowHtml': true, 'cssClassNames': cssClassNames, 'alternatingRowStyle': true};
var data = new google.visualization.DataTable();
data.addColumn('string', 'Username',{style: 'background-color:red;'});
data.addColumn('number', 'Won');
data.addColumn('number', 'Lost');
data.addColumn('number', 'Win/Loss Ratio');
data.addColumn('number', 'Goals For');
data.addColumn('number', 'Goals Against');
data.addColumn('number', 'Score');
data.addRows([
['Mike', 22, 13, 0.63, 65, 30, 600],
['Andy', 25, 10, 0.71, 60, 18, 630],
['Steve', 5, 20, 0.20, 10, 50, 475],
['Chris', 40, 10, 0.80, 120, 20, 670],
['Jake', 15, 15, 0.50, 70, 50, 525],
]);
var table = new google.visualization.Table(document.getElementById('table_div'));
table.draw(data, {showRowNumber: true});
}
</script>
</head>
<body>
<div id='table_div'></div>
</body>
</html>
This is my CSS:
#table_div table {
color: #000;
margin-top: 10px;
}
.headerRow {
color: #000;
}
While the above CSS affects the table as a whole, attempts to modify background color using background-color: #ff0000;
or to style the .headerRow have no impact. The styles seem to be inherited from the Google CSS at https://ajax.googleapis.com/ajax/static/modules/gviz/1.0/table/table.css and cannot be overridden.
Any insights into why this may be happening?
If necessary, I am willing to disable the Google CSS altogether and rely solely on my own stylesheet for customization.