There are two things you can do, which you use depends on what you want to
do with the data. If you just need to access the data, then call the
#getDataTable method of the chartWrapper and use the row reference in that.
If you need to manipulate the data (or have another reason why you need to
work in the base DataTable), then you call the #getDataTable method, and
then use the #getTableRowIndex method of the object returned to get the row
index in the base DataTable.
Method 1:
google.visualization.events.addListener(chart, 'select', function () {
var selection = chart.getSelection();
var tmpData = chart.getDataTable();
alert(tmpData.getValue(selection[0].row, selection[0].column));
});
Method 2:
google.visualization.events.addListener(chart, 'select', function () {
var selection = chart.getSelection();
var tmpData = chart.getDataTable();
var baseRowIndex = tmpData.getTableRowIndex(selection[0].row);
var baseColumnIndex = tmpData.getTableColumnIndex(selection[0].column);
alert(data.getValue(baseRowIndex, baseColumnIndex));
});
On Thursday, August 30, 2012 11:59:51 AM UTC-4, abacus wrote:
>
> Hi, I am using a control wrapper of type ChartRangeFilter with a LineChart
> and I am having problems accessing the row a user has selected.
>
> When I use the getSelection method on the chart it returns a row
> corresponding to what is currently displayed on the chart. (So if the range
> is set to start at the 30th point and the user selects the first possible
> item the row number would still be 0, where as I would be wanting the value
> 30). I need to calculate the actual row number in order to know which item
> of data the user has actually clicked on. The simplest way would be to use
> getState().range.start on the control wrapper, but this is out of sync with
> the actual chart. This is because getState() gives you the row equal to or
> before the current filter position, where as the chart displays the row
> equal to or after the current filter position.
>
> I can provide screenshots if you don't understand what I mean by the chart
> and the control being out of sync.
>
> How can I get to the selected data no matter what filter is put on the
> chart? The only other idea I have is to use the toJSON method on the chart
> wrapper and parse that, but that seems like a nasty solution.
>
--
You received this message because you are subscribed to the Google Groups
"Google Visualization API" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/google-visualization-api/-/guf3rDjZJMwJ.
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.