changing two properties using setColumns

841 views
Skip to first unread message

cavan

unread,
Nov 13, 2012, 3:02:06 PM11/13/12
to google-visua...@googlegroups.com
Hello,

I try to chnage Y axis format and color of certain columns using setColumn function. Only one of them work, but not both of them.  Here is the code

 var view = new google.visualization.DataView(data);
  view.setColumns([0,    {
      //label: chartInfo.data.getColumnLabel(1),
      type: 'number',
      label: 'mail',
      calc: function (dt, row) {
        // reformat the data in millions
        return {v:dt.getValue(row, 1)/1000000, f:dt.getFormattedValue(row, 1)};
      }
   },
 {
        type: 'number',
        label: 'mail',
        calc: function (dt, row) { day=dt.getValue(row,0);
            return (day!=2) ? dt.getValue(row, 1) : null;
        }
    }, {
        type: 'number',
        label: 'mail',
        calc: function (dt, row) {day=dt.getValue(row,0);
            return (day==2) ? dt.getValue(row, 1) : null;
        }
    }]);

So, I try to put in Y axis mln instead of six zeros and make columns different color if label is 2 or not.

If I do the following
  view.setColumns([0,    {
      //label: chartInfo.data.getColumnLabel(1),
      type: 'number',
      label: 'mail',
      calc: function (dt, row) {
        // reformat the data in millions
        return {v:dt.getValue(row, 1)/1000000, f:dt.getFormattedValue(row, 1)};
      }
   }
)]

The Y axis labeling works. And if I do the following
view.setColumns([0,    {
        type: 'number',
        label: 'mail',
        calc: function (dt, row) { day=dt.getValue(row,0);
            return (day!=2) ? dt.getValue(row, 1) : null;
        }
    }, {
        type: 'number',
        label: 'mail',
        calc: function (dt, row) {day=dt.getValue(row,0);
            return (day==2) ? dt.getValue(row, 1) : null;
        }
    }]);

the coloring works.
I need to impose both properties.
How can it be accomplished?

Thanks in advance
cavan.


asgallant

unread,
Nov 13, 2012, 3:09:57 PM11/13/12
to google-visua...@googlegroups.com
You just need to combine the returned value from the first with the split in the second:

view.setColumns([0{
    type'number',
    label'mail',
    calcfunction (dtrow{
        var day dt.getValue(row0);
        return (day != 2{vdt.getValue(row11000000fdt.getFormattedValue(row1)null;

    }
}{
    type'number',
    label'mail',
    calcfunction (dtrow{
        var day dt.getValue(row0);
        return (day == 2{vdt.getValue(row11000000fdt.getFormattedValue(row1)null;
    }
}]);

cavan

unread,
Nov 13, 2012, 3:45:26 PM11/13/12
to google-visua...@googlegroups.com
Thanks. I tried it. This code colors all column bars in two different colors. I need to have one whole color for each column bar, only those with labels that is equal 2 will have different color.
 

cavan

unread,
Nov 13, 2012, 5:25:15 PM11/13/12
to google-visua...@googlegroups.com
Actually, never mind. It work fine.

Thanks a lot.

asgallant

unread,
Nov 13, 2012, 5:33:06 PM11/13/12
to google-visua...@googlegroups.com
You're welcome.
Reply all
Reply to author
Forward
0 new messages