Organizational Research By

Surprising Reserch Topic

different colors for google columnchart using -'javascript,php,google-visualization'

different colors for google columnchart  using -'javascript,php,google-visualization'

I am trying to draw a graph with data coming from php code as an array passed on to the draw function. Colors show if I am using PieChart, but NOT ColumnChart. How can I get the bars to show different colors?

Here is my script:

<script type="text/javascript">
  google.load("visualization", "1.1", {packages:["corechart"]});
  function drawChart() {
    var data = google.visualization.arrayToDataTable(<?php

    $baseText = '';
    $trimmedPercentbf = '';
$js_arraybf = "['Percentage','$baseText'],";

    $counter = 0;

    $getBasicFunctionality = [SQL Query Here];
        while ($basicFunctionality = dbfetch($getBasicFunctionality)):

            $baseTextbf = $basicFunctionality["sat_lower_level_text"];

    $weightsTotal = $basicFunctionality["total"];

            $average = $basicFunctionality["weightAVG"];
            $countTotal = $basicFunctionality["total_users"];

            $counter += $countTotal;

            $percentage = ($average)/5 * 100;
            $trimmedPercentbf = number_format($percentage, $decimals=2);

                    if($counter != $countTotal):
                        $sep = ",";
                        $sep = ",";

                        $js_arraybf .= "[ '$baseTextbf', $trimmedPercentbf ]".$sep;


                                    $js_array = rtrim($js_arraybf, ', ');

                print "[".$js_array."]";


    var chart = new google.visualization.ColumnChart(document.getElementById('community'));
    chart.draw(data, {width: 800, height: 800, is3D: true,/*vAxis: {format:'#%'},pieHole: 0.4,*/colors: ['#242424','#437346','#97D95C','#7D252B','#EB9781','#FFD2B5','#4A4147','#3796c8', 'red','yellow','green', 'blue'],axisFontSize:12, title: '2.Leadership Management & Communication'});


asked Sep 7, 2015 by rajesh
0 votes

Related Hot Questions

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please log in or register.