Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I set color range in Google Chart?
    primarykey
    data
    text
    <p>I've created a <code>ColumnChart</code> and it has two bars. How can I set different colours on these two bars?</p> <p>I'm currently only able to set one color for both bars,</p> <p>This is part of the code I use:</p> <pre><code>var d = [['', ''], ['Bar 1', 100], ['Bar 2', 300]]; data = new google.visualization.arrayToDataTable(d); var option = { title: 'Betalingsoppf&amp;oslash;lging', width: '300', height: '250', min: '0', legend: 'none', colors: ['#b2cedc', '#7b7b7b','#e2e2e2', '#747c1f'] } wrap.setOptions(option); wrap.draw(data); </code></pre> <p>The intention with <code>colors: ['#b2cedc', '#7b7b7b','#b2cedc', '#7b7b7b']</code> is to set start-end colour for bar1 and bar 2. But all i does, is to use the first color defined.</p> <p>And is there a way to chagne the background color through options?</p> <p><strong>Test code for Visualization tool</strong> </p> <p>Cut and paste this into <a href="http://code.google.com/apis/ajax/playground/?type=visualization#column_chart">Code Playground</a>.</p> <pre><code>function drawVisualization() { // Create and populate the data table. var data = new google.visualization.DataTable(); var raw_data = [['Austria', 150000, 225000]]; var years = [2003, 2004]; data.addColumn('string', 'Year'); for (var i = 0; i &lt; raw_data.length; ++i) { data.addColumn('number', raw_data[i][0]); } data.addRows(years.length); for (var j = 0; j &lt; years.length; ++j) { data.setValue(j, 0, years[j].toString()); } for (var i = 0; i &lt; raw_data.length; ++i) { for (var j = 1; j &lt; raw_data[i].length; ++j) { data.setValue(j-1, i+1, raw_data[i][j]); } } // Create and draw the visualization. new google.visualization.ColumnChart(document.getElementById('visualization')). draw(data, {title:"Color testing", width:600, height:400, hAxis: {title: "Year"}, colors: ['#dedb70', '#747c1f','yellow', 'red'], min: '0', legend: 'none' } ); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload