The values that you want to get should be taken from the first cell (column
0) of the row of the selected cell.Its a bit tricky: when you select a
value, you select a cell. But if you want the legend, ('2005'), then it is
the first cell of the cell's row. You will get the same label for all of the
cells of the same row.
Use then: alert(data.getValue(row, 0));
The reason you get nothing for the formatter and for the id, is that you
haven't specified them, which is ok. You can specify column id as an
optional parameter in data.addColumn(type, label, id);
VizGuy
On Tue, Nov 25, 2008 at 8:20 AM, [EMAIL PROTECTED] <
[EMAIL PROTECTED]> wrote:
>
> Hi Team,
>
> I need to get a value in the chart when im click. ao i add a listner
> and can get the column & row index too.
> but i fail to get the value.
>
> Please help me to find it
>
> here is my code
>
> I want to get 2004 ,2005 & ....
> when i was click on a column.
>
> Data Table
>
> data = new google.visualization.DataTable();
> data.addColumn('string', 'Year');
> data.addColumn('number', 'Sales');
> data.addRows(4);
> data.setValue(0, 0, '2004');
> data.setValue(0, 1, 1000);
> data.setValue(1, 0, '2005');
> data.setValue(1, 1, 1170);
> data.setValue(2, 0, '2006');
> data.setValue(2, 1, 660);
> data.setValue(3, 0, '2007');
> data.setValue(3, 1, 1030);
>
> var chart = new google.visualization.ColumnChart
> (document.getElementById('chart_div'));
> chart.draw(data, {width: 400, height: 240, is3D: true, title:
> 'Company Performance'});
>
> google.visualization.events.addListener(chart, 'select',
> handleSelect);
>
>
>
> function handleSelect() {
>
> var selection = this.getSelection();
>
> var message = '';
> var col = 0;
> var row = 0;
> for (var i = 0; i < selection.length; i++) {
> var item = selection[i];
> if (item.row != null && item.column != null) {
> row = item.row;
> col = item.column;
> message += '{row:' + item.row + ',column:' + item.column
> + '}';
> } else if (item.row != null) {
> message += '{row:' + item.row + '}';
> } else if (item.column != null) {
> message += '{column:' + item.column + '}';
> }
> }
> if (message == '') {
> message = 'nothing';
> }
> alert('You selected ' + message);
> //alert(message);
>
> alert('1',data.getColumnLabel(col));
> alert('2',data.getValue(row, col));
> alert('3',data.getDistinctValues(col));
> alert('4',data.getColumnType(col));
> alert('5',data.getColumnRange(col));
> alert('6',data.getColumnPattern(col)); //from this i get
> nothing
> alert('7',data.getColumnId(col)); //from this i get
> nothing
>
> I didnt get 2004, 2005..... from any of the ways.
> Please help me to find it
>
> Thanks & best Regards,
> Sajeevi
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Google Visualization API" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/google-visualization-api?hl=en
-~----------~----~----~----~------~----~------~--~---