javascript - How to draw a column chart with one single field and multiple colors using google charts -


here code: jsfiddle

<!doctype html> <html> <head> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js" ></script> <script type="text/javascript" src="https://www.google.com/jsapi"></script> <script type="text/javascript"> google.load("visualization", "1", {packages:["corechart"]}); function drawcolumnchart(container, data) {         var data = google.visualization.arraytodatatable(data);     var chart = new google.visualization.columnchart(container);     var options = {fontsize: 16};     chart.draw(data, options);   } $(document).ready(function(){     drawcolumnchart($("#satisfactionbargraph")[0], [         ['satisfaction', 'percent'],         ['大変満足',          10      ],         ['満足',            22      ],         ['やや満足',          30      ],         ['やや不満',          10      ],         ['不満',            5       ]     ]); }); </script> </head> <body> <div id="satisfactionbargraph" style="width: 524px; height: 370px;" class="chartcontainer"></div> </body> </html> 

and want: enter image description here

i have 2 problems:

(1) want text below x-axis align top bottom have run through document cannot find option (2) want columns in different colors because have 1 filed, of them in same color. i'm wondering whether used right chart.

and suggestion appreciated

thanks lot answers. combined solutions , figured out:

final result

hope can meets same problem

the google visualization api's columncharts color data series, if want multiple colors bars, have split them different series.
function drawcolumnchart(container, data) {
var data = google.visualization.arraytodatatable(data);

    var columns = [0];     (var = 0; < data.getnumberofrows(); i++) {         columns.push({             type: 'number',             label: data.getcolumnlabel(1),             calc: (function (x) {                 return function (dt, row) {                     return (row == x) ? dt.getvalue(row, 1) : null;                 }             })(i)         });     }     var view = new google.visualization.dataview(data);     view.setcolumns(columns);      var chart = new google.visualization.columnchart(container);     var options = {         fontsize: 16,         // set "isstacked" option true make column spacing work         isstacked: true     };     chart.draw(view, options); } // use callback google loader draw chart rather document ready google.load("visualization", "1", {packages:["corechart"], callback: function () {     drawcolumnchart($("#satisfactionbargraph")[0], [         ['satisfaction', 'percent'],         ['大変満足', 10],         ['満足', 22],         ['やや満足', 30],         ['やや不満', 10],         ['不満', 5]     ]); }}); 

here's jsfiddle of code: http://jsfiddle.net/asgallant/rrhak/

i don't think visualization api supports vertical writing that. can rotate text aligned vertically, that's not trying achieve here.


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -