I have a typo in there, do it like 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 (dt.getValue(row, 0) == pausecontent[x]) ?
dt.getValue(row, 1) : null;
}
})(i)
});
}
var chart = new google.visualization.ChartWrapper({
chartType: 'ColumnChart',
containerId: 'chart_div',
dataTable: data,
options: {
// setting the "isStacked" option to true fixes the spacing problem
'title': 'countries',
'isStacked': true,
'height': 300,
'width': 600
},
view: {
columns: columns
}
});
On Wednesday, September 18, 2013 4:25:22 AM UTC-4, Ravindra Gharge wrote:
>
>
> <https://lh3.googleusercontent.com/-25yzlgqRtp0/UjljZpbDJsI/AAAAAAAAAJA/VKnSItQct34/s1600/googleChart.png>
>
> Thank for the help
>
> i tried your code but is partially working
> in my column chart only the first value get displayed not the remaining
> (the value of gujarat , maharashtra , rajastan)
>
> Thanks
>
> On Tuesday, September 17, 2013 10:12:04 PM UTC+5:30, asgallant wrote:
>>
>> 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.