我正在使用Google组织结构图创建组织结构图,并为每个人使用不同的彩色框。但是,我无法在背景色的data.setRowProperty中使用“样式”或“ selectedStyle”。它适用于border属性。我是javascript和google可视化的新手,所以很抱歉,如果这很明显。
<head>
<script type='text/javascript' src='https://www.google.com/jsapi'></script>
<script type='text/javascript'>
google.load('visualization', '1', {packages:['orgchart']});
google.setOnLoadCallback(drawChart);
function drawChart() {
var data = new google.visualization.DataTable();
data.addColumn('string', 'Name');
data.addColumn('string', 'Manager');
data.addColumn('string', 'ToolTip');
data.addRows([
[{v:'Row0', f:'Row0'}, '', 'The President'],
[{v:'Row1', f:'Row1<div style="color:red; font-style:italic">Vice
President</div>'}, 'Row0', 'VP'],
['Row2', 'Row0', ''],
['Row3', 'Row0', ''],
['Row4', 'Row0', ''],
['Row5', 'Row0', ''],
['Row6', 'Row1', 'Bob Sponge']
]);
// This works and puts a border round the node
data.setRowProperty(3, 'style', 'border: 1px solid red');
// Neither of these work
data.setRowProperty(4, 'style', 'background-color:red');
data.setRowProperty(5, 'selectedStyle', 'background-color:red');
var chart = new
google.visualization.OrgChart(document.getElementById('chart_div'));
chart.draw(data, {allowHtml:true});
}
</script>
</head>
<body>
<div id='chart_div'></div>
</body>
</html>
最佳答案
您应该使用background:red而不是background-color:red