Select slice color based on dynamic data value

36 Views Asked by At

I am working with google charts and populating the chart with dynamic php data. I have 4 companies and want to set slice color for each one, but currently if the value is null for 3rd company then it shows 3 others with first three colors in stack. and now color of 3rd company applies to 4th one because total slice are 3. I want to set the color for each company name. is there any way?

var data_pie = google.visualization.arrayToDataTable([
    ['Value', 'Total value'],
    <?php 
        foreach( $valueas $list_item ){
            echo '["'.strtoupper( $list_item->company_name ).'", '.$list_item2->total_value.'],';
        }
    ?>
    ]);
var chartheight2 = $('#piechart_3d').height();
var options_pie = {
    title: 'Total Value',
    titleTextStyle: {
        fontSize: 16,
        color:'rgb(117, 117, 117)',
        bold: 0,
        fontName: 'Roboto'
    },
    is3D: true,
    'height':chartheight2,
    pieSliceText: 'value',
    colors: [
        '#351c15', 
        '#462895',
        '#d81013',
        '#f89729'
    ],
    legend: {position: 'bottom'},
};
var pie_chart = new google.visualization.PieChart(document.getElementById('piechart_3d'));
    pie_chart.draw( data_pie, options_pie );
0

There are 0 best solutions below