如何将标签颜色应用于Google Charts API的饼图切片

时间:2015-06-06 13:34:27

标签: google-visualization

Hej伙计们,我尝试了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'}
                  };

有人提示使用哪种功能?

图片:

enter image description here

1 个答案:

答案 0 :(得分:3)

要指定图例文字颜色,请使用legend.textStyle.color属性,例如:

var options = {
    legend: {
        textStyle: { color: 'white' }
    }
};

根据Configuration Options

legend.textStyle
     

指定图例文本样式的对象。对象有这个   格式:

{ 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>