Yii2:使用GoogleChart Widget自定义PieChart颜色

时间:2018-03-20 13:46:42

标签: php yii2 pie-chart

我已尝试使用此代码更改颜色:

<?php
    echo GoogleChart::widget(array('visualization' => 'PieChart',
        'data' => array(
            array('Task', 'All Statuses'),
            //   array('Picked Up', (int) $all_vehicle['picked_up']),
            array('Car on Way', (int) $all_vehicle['car_on_way']),
            array('Shipped', (int) $all_vehicle['shipped']),
            array('On Hand', (int) $all_vehicle['on_hand']),
        ),
        'options' => array('title' => 'All','width' => 442, 'height' => 400, 'pieHole' => 0.4, 'seriesColors' => [ "#000", "#000", "#000", "#000" ])
    ));
?>

使用此数组更改颜色

seriesColors' => [ "#000", "#000", "#000", "#000" ])

1 个答案:

答案 0 :(得分:1)

您必须使用选项color而不是seriesColor作为插件的选项,请参阅DOCS。所以将您的小部件代码更改为以下

<?php
    echo GoogleChart::widget(array('visualization' => 'PieChart',
        'data' => array(
            array('Task', 'All Statuses'),
            //   array('Picked Up', (int) $all_vehicle['picked_up']),
            array('Car on Way', (int) $all_vehicle['car_on_way']),
            array('Shipped', (int) $all_vehicle['shipped']),
            array('On Hand', (int) $all_vehicle['on_hand']),
        ),
        'options' => array(
            'title' => 'All', 
            'width' => 442, 
            'height' => 400, 
            'pieHole' => 0.4, 
            'colors'=> ['#e0440e', '#e6693e', '#ec8f6e', '#f3b49f', '#f6c7b6']
        )
    ));
?>