Try this:
var columns = [0];
for (var i = 0; i < pausecontent.length; i++) {
columns.push({
type: 'number',
label: pausecontent[i],
calc: (function (x) {
return function (dt, row) {
return (row == pausecontent[x]) ? dt.getValue(row, 1) :
null;
}
})(i)
});
}
and then use columns to construct your view's columns:
view: {
columns: columns
}
On Tuesday, September 17, 2013 9:23:17 AM UTC-4, Ravindra Gharge wrote:
>
> I am setting the columns to use in the chart's view
> I have the javascript array ( pausecontent ) which is dynamic and have the
> name of the states
> I want to assign this to views lable
> I tryed the code which is commented
> please suggest better approach
>
> bellow code is working fine but i want to assign the array pausecontent[]
> which is dynamic
>
> my code is
>
> view: {
> // set the columns to use in the chart's view
> // calculated columns put data belonging to each country in the
> proper column
> /* columns: [0,
> for(var index=0; index<pausecontent.length; index++){
> {
> type: 'number',
> label: pausecontent[index],
> calc: function (dt, row) {
> return (dt.getValue(row, 0) == pausecontent[index]) ?
> dt.getValue(row, 1) : null;
> }
> }
> }]
> }*/
> columns: [0, {
> type: 'number',
> label: pausecontent[0],
> calc: function (dt, row) {
> return (dt.getValue(row, 0) == pausecontent[0]) ?
> dt.getValue(row, 1) : null;
> }
> },{
> type: 'number',
> label: pausecontent[1],
> calc: function (dt, row) {
> return (dt.getValue(row, 0) == pausecontent[1]) ?
> dt.getValue(row, 1) : null;
> }
> }, {
> type: 'number',
> label: pausecontent[2],
> calc: function (dt, row) {
> return (dt.getValue(row, 0) == pausecontent[2]) ?
> dt.getValue(row, 1) : null;
> }
> }, {
> type: 'number',
> label: pausecontent[3],
> calc: function (dt, row) {
> return (dt.getValue(row, 0) == pausecontent[3]) ?
> dt.getValue(row, 1) : null;
> }
> }
> ]}
>
--
You received this message because you are subscribed to the Google Groups
"Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/google-visualization-api.
For more options, visit https://groups.google.com/groups/opt_out.