Yii2:使用 Google Chart Widget 自定义饼图颜色

Yii2: Customize PieChart colors using GoogleChart Widget

我试过这个代码来改变颜色:

<?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" ])

您必须使用选项 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']
        )
    ));
?>