如何将标签颜色应用于 Google 图表 API 中的饼图切片
How to apply a label color to a Pie Chart slice from Google Charts API
嗨,伙计们,我尝试了 2 或 3 个不同的功能,但我无法让它们中的任何一个工作。我希望来自 3 个不同统计数据的标签被着色为例如白色。下面是一张照片。
var options = {'title':'Lead statistik von<?php echo $_SESSION['user_name'];?>',
'width':400,
'height':300,
backgroundColor:'#0a0a0a',
fontSize:'14',
titleTextStyle: {color:'#FFFFFF'},
slices:
{
0: { color: 'red' },
1: { color: 'purple'},
2: { color: 'blue'}
},
pieSliceTextSlice:{color:'#FFFFFF'}
};
有人知道要使用哪个功能吗?
图片:
为了指定图例文本颜色使用legend.textStyle.color
属性,例如:
var options = {
legend: {
textStyle: { color: 'white' }
}
};
legend.textStyle
An object that specifies the legend text style. The object has this
format:
{ color: <string>,
fontName: <string>,
fontSize: <number>,
bold: <boolean>,
italic: <boolean> }
The color can be any HTML color string, for example: 'red' or '#00cc00'. Also see fontName and fontSize.
Type: object
Default: {color: 'black', fontName: <global-font-name>, fontSize: <global-font-size>}
例子
google.load("visualization", "1", {packages:["corechart"]});
google.setOnLoadCallback(drawChart);
function drawChart() {
var data = google.visualization.arrayToDataTable([
['Task', 'Hours per Day'],
['Work', 11],
['Eat', 2],
['Commute', 2],
['Watch TV', 2],
['Sleep', 7]
]);
var options = {
title: 'My Daily Activities',
width: 400,
height: 300,
backgroundColor: '#0a0a0a',
fontSize: '14',
legend: {
textStyle: { color: 'white' }
}
};
var chart = new google.visualization.PieChart(document.getElementById('piechart'));
chart.draw(data, options);
}
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<div id="piechart" style="width: 900px; height: 500px;"></div>
嗨,伙计们,我尝试了 2 或 3 个不同的功能,但我无法让它们中的任何一个工作。我希望来自 3 个不同统计数据的标签被着色为例如白色。下面是一张照片。
var options = {'title':'Lead statistik von<?php echo $_SESSION['user_name'];?>',
'width':400,
'height':300,
backgroundColor:'#0a0a0a',
fontSize:'14',
titleTextStyle: {color:'#FFFFFF'},
slices:
{
0: { color: 'red' },
1: { color: 'purple'},
2: { color: 'blue'}
},
pieSliceTextSlice:{color:'#FFFFFF'}
};
有人知道要使用哪个功能吗?
图片:
为了指定图例文本颜色使用legend.textStyle.color
属性,例如:
var options = {
legend: {
textStyle: { color: 'white' }
}
};
legend.textStyle
An object that specifies the legend text style. The object has this format:
{ color: <string>, fontName: <string>, fontSize: <number>, bold: <boolean>, italic: <boolean> } The color can be any HTML color string, for example: 'red' or '#00cc00'. Also see fontName and fontSize. Type: object Default: {color: 'black', fontName: <global-font-name>, fontSize: <global-font-size>}
例子
google.load("visualization", "1", {packages:["corechart"]});
google.setOnLoadCallback(drawChart);
function drawChart() {
var data = google.visualization.arrayToDataTable([
['Task', 'Hours per Day'],
['Work', 11],
['Eat', 2],
['Commute', 2],
['Watch TV', 2],
['Sleep', 7]
]);
var options = {
title: 'My Daily Activities',
width: 400,
height: 300,
backgroundColor: '#0a0a0a',
fontSize: '14',
legend: {
textStyle: { color: 'white' }
}
};
var chart = new google.visualization.PieChart(document.getElementById('piechart'));
chart.draw(data, options);
}
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<div id="piechart" style="width: 900px; height: 500px;"></div>