admin管理员组文章数量:1022569
Is there a way to change the entire background color of the header row (and rows) in Google Charts?
In the docs they said you can do it using:
dataTable.setCell(22, 2, 15, 'Fifteen', {style: 'font-style:bold; font-size:22px;'});
But I need to dinamicly change the color, according to some values I get from the database using PHP.
Currently this is my working code (without changing any styles)
var data = new google.visualization.DataTable();
<?php foreach($table['TITLES'] as $title) { ?>
data.addColumn('string', '<?php echo $title['TITLE_TEXT']; ?>');
<?php } ?>
<?php foreach($table['ROWS'] as $row) {
$cols = "";
foreach($row['COLS'] as $col)
$cols .= "'".$col['VALUE']."',";
$cols = rtrim($cols,",");
?>
data.addRow([<?php echo $cols; ?>]);
<?php } ?>
var table = new google.visualization.Table(document.getElementById('chart_div_<?php echo $item; ?>'));
table.draw(data, {showRowNumber: true});
Any help would by appreciated!
Is there a way to change the entire background color of the header row (and rows) in Google Charts?
In the docs they said you can do it using:
dataTable.setCell(22, 2, 15, 'Fifteen', {style: 'font-style:bold; font-size:22px;'});
But I need to dinamicly change the color, according to some values I get from the database using PHP.
Currently this is my working code (without changing any styles)
var data = new google.visualization.DataTable();
<?php foreach($table['TITLES'] as $title) { ?>
data.addColumn('string', '<?php echo $title['TITLE_TEXT']; ?>');
<?php } ?>
<?php foreach($table['ROWS'] as $row) {
$cols = "";
foreach($row['COLS'] as $col)
$cols .= "'".$col['VALUE']."',";
$cols = rtrim($cols,",");
?>
data.addRow([<?php echo $cols; ?>]);
<?php } ?>
var table = new google.visualization.Table(document.getElementById('chart_div_<?php echo $item; ?>'));
table.draw(data, {showRowNumber: true});
Any help would by appreciated!
Share Improve this question asked Sep 23, 2013 at 20:36 arielcrarielcr 1,6632 gold badges23 silver badges34 bronze badges3 Answers
Reset to default 2With the Table Visualizations you can control colors a few different ways:
- use the
cssClassNames
option (see available options). This allows you to set your own classes for the various different table elements, which you can then use CSS to style however you like. - Set the
style
property of individual cells. - Set the
className
property of individual cells.
Using the last two ways, you can set the styling on cells individually if you want to make them different from the default (or different from any custom styling applied using the first method).
There are also some formatters you can use to adjust the appearance of the cells in a table (the ColorFormatter may help you).
Create a options variable, and then use in chart declaration.
var options = {
title: 'Markup by Period',
legend:'bottom',
hAxis: {title: 'Period', titleTextStyle: {color: 'black'}} ,
vAxis: {title: 'Amount', titleTextStyle: {color: 'black'}} ,
width:400,
height:250,
backgroundColor: '#F4F4F4',
chartArea:{width:300, left:60}};
var chart = new google.visualization.LineChart(document.getElementById('chart_div2'));
// You can pass the options array in draw method.
chart.draw(data, options);
That: backgroundColor: '#F4F4F4',
[EDIT]
Maybe this answers help you: Google Chart Background Color
Sorry for my english
function drawSettingsTable() {
document.settingsData = new google.visualization.DataTable();
document.settingsData.addColumn('string', 'Setting');
document.settingsData.addColumn('string', 'Current Value');
document.settingsData.addColumn('string', 'Meaning');
document.settingsData.addRows(
[[" ", " ", " "],
[" ", " ", " "],
[" ", " ", " "],
[" ", " ", " "]
]
);
document.settingsTable = new google.visualization.Table(document.getElementById('settingsDiv'));
document.settingsTable.draw(document.settingsData, {
showRowNumber: false,
allowHtml: true,
width: "100%",
cssClassNames: {headerRow:'columnTitle'}
});
And create the class .columnTitle in your css file with the desired proper tie, for example:
.columnTitle {
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
font-size: 14px;
color:white;
background-color: #607A75
}
Is there a way to change the entire background color of the header row (and rows) in Google Charts?
In the docs they said you can do it using:
dataTable.setCell(22, 2, 15, 'Fifteen', {style: 'font-style:bold; font-size:22px;'});
But I need to dinamicly change the color, according to some values I get from the database using PHP.
Currently this is my working code (without changing any styles)
var data = new google.visualization.DataTable();
<?php foreach($table['TITLES'] as $title) { ?>
data.addColumn('string', '<?php echo $title['TITLE_TEXT']; ?>');
<?php } ?>
<?php foreach($table['ROWS'] as $row) {
$cols = "";
foreach($row['COLS'] as $col)
$cols .= "'".$col['VALUE']."',";
$cols = rtrim($cols,",");
?>
data.addRow([<?php echo $cols; ?>]);
<?php } ?>
var table = new google.visualization.Table(document.getElementById('chart_div_<?php echo $item; ?>'));
table.draw(data, {showRowNumber: true});
Any help would by appreciated!
Is there a way to change the entire background color of the header row (and rows) in Google Charts?
In the docs they said you can do it using:
dataTable.setCell(22, 2, 15, 'Fifteen', {style: 'font-style:bold; font-size:22px;'});
But I need to dinamicly change the color, according to some values I get from the database using PHP.
Currently this is my working code (without changing any styles)
var data = new google.visualization.DataTable();
<?php foreach($table['TITLES'] as $title) { ?>
data.addColumn('string', '<?php echo $title['TITLE_TEXT']; ?>');
<?php } ?>
<?php foreach($table['ROWS'] as $row) {
$cols = "";
foreach($row['COLS'] as $col)
$cols .= "'".$col['VALUE']."',";
$cols = rtrim($cols,",");
?>
data.addRow([<?php echo $cols; ?>]);
<?php } ?>
var table = new google.visualization.Table(document.getElementById('chart_div_<?php echo $item; ?>'));
table.draw(data, {showRowNumber: true});
Any help would by appreciated!
Share Improve this question asked Sep 23, 2013 at 20:36 arielcrarielcr 1,6632 gold badges23 silver badges34 bronze badges3 Answers
Reset to default 2With the Table Visualizations you can control colors a few different ways:
- use the
cssClassNames
option (see available options). This allows you to set your own classes for the various different table elements, which you can then use CSS to style however you like. - Set the
style
property of individual cells. - Set the
className
property of individual cells.
Using the last two ways, you can set the styling on cells individually if you want to make them different from the default (or different from any custom styling applied using the first method).
There are also some formatters you can use to adjust the appearance of the cells in a table (the ColorFormatter may help you).
Create a options variable, and then use in chart declaration.
var options = {
title: 'Markup by Period',
legend:'bottom',
hAxis: {title: 'Period', titleTextStyle: {color: 'black'}} ,
vAxis: {title: 'Amount', titleTextStyle: {color: 'black'}} ,
width:400,
height:250,
backgroundColor: '#F4F4F4',
chartArea:{width:300, left:60}};
var chart = new google.visualization.LineChart(document.getElementById('chart_div2'));
// You can pass the options array in draw method.
chart.draw(data, options);
That: backgroundColor: '#F4F4F4',
[EDIT]
Maybe this answers help you: Google Chart Background Color
Sorry for my english
function drawSettingsTable() {
document.settingsData = new google.visualization.DataTable();
document.settingsData.addColumn('string', 'Setting');
document.settingsData.addColumn('string', 'Current Value');
document.settingsData.addColumn('string', 'Meaning');
document.settingsData.addRows(
[[" ", " ", " "],
[" ", " ", " "],
[" ", " ", " "],
[" ", " ", " "]
]
);
document.settingsTable = new google.visualization.Table(document.getElementById('settingsDiv'));
document.settingsTable.draw(document.settingsData, {
showRowNumber: false,
allowHtml: true,
width: "100%",
cssClassNames: {headerRow:'columnTitle'}
});
And create the class .columnTitle in your css file with the desired proper tie, for example:
.columnTitle {
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
font-size: 14px;
color:white;
background-color: #607A75
}
本文标签: javascriptChange table header background color in Google ChartsStack Overflow
版权声明:本文标题:javascript - Change table header background color in Google Charts - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745504281a2153533.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论