title: Set column color in google chart
body: <p>I am using google charts to build a line chart. I am using a Category Filter to toggle what columns are displayed like is shown in the fiddle below. </p>
  
  <p><a href="http://jsfiddle.net/asgallant/WaUu2/" rel="nofollow">http://jsfiddle.net/asgallant/WaUu2/</a></p>
  
  <p>How can you set colors for each column so that they will always have that color. For example if you remove the column Foo in the fiddle example, the column Bar will get its color.</p>
  
  <pre><code>google.load('visualization', '1', {packages: ['controls']});
  google.setOnLoadCallback(drawChart);
  
  function drawChart () {
      var data = new google.visualization.DataTable();
      data.addColumn('string', 'Year');
      data.addColumn('number', 'Foo');
      data.addColumn('number', 'Bar');
      data.addColumn('number', 'Baz');
      data.addColumn('number', 'Cad');
      data.addRows([
          ['2005',  45, 60, 89, 100],
          ['2006',  155, 50, 79, 24],
          ['2007',  35, 31, 140, 53],
          ['2008',  105, 23, 43, 82],
          ['2009',  120, 56, 21, 67],
          ['2010',  65, 19, 34, 134],
          ['2011',  80, 23, 130, 40],
          ['2012',  70, 140, 83, 90]
      ]);
  
      var columnsTable = new google.visualization.DataTable();
      columnsTable.addColumn('number', 'colIndex');
      columnsTable.addColumn('string', 'colLabel');
      var initState= {selectedValues: []};
      // put the columns into this data table (skip column 0)
      for (var i = 1; i &lt; data.getNumberOfColumns(); i++) {
          columnsTable.addRow([i, data.getColumnLabel(i)]);
          // you can comment out this next line if you want to have a default selection other than the whole list
          initState.selectedValues.push(data.getColumnLabel(i));
      }
      // you can set individual columns to be the default columns (instead of populating via the loop above) like this:
      // initState.selectedValues.push(data.getColumnLabel(4));
  
      var chart = new google.visualization.ChartWrapper({
          chartType: 'BarChart',
          containerId: 'chart_div',
          dataTable: data,
          options: {
              title: 'Foobar',
              width: 600,
              height: 400
          }
      });
  
      var columnFilter = new google.visualization.ControlWrapper({
          controlType: 'CategoryFilter',
          containerId: 'colFilter_div',
          dataTable: columnsTable,
          options: {
              filterColumnLabel: 'colLabel',
              ui: {
                  label: 'Columns',
                  allowTyping: false,
                  allowMultiple: true,
                  allowNone: false,
                  selectedValuesLayout: 'belowStacked'
              }
          },
          state: initState
      });
  
      function setChartView () {
          var state = columnFilter.getState();
          var row;
          var view = {
              columns: [0]
          };
          for (var i = 0; i &lt; state.selectedValues.length; i++) {
              row = columnsTable.getFilteredRows([{column: 1, value: state.selectedValues[i]}])[0];
              view.columns.push(columnsTable.getValue(row, 0));
          }
          // sort the indices into their original order
          view.columns.sort(function (a, b) {
              return (a - b);
          });
          chart.setView(view);
          chart.draw();
      }
      google.visualization.events.addListener(columnFilter, 'statechange', setChartView);
  
      setChartView();
      columnFilter.draw();
  }
  </code></pre>