javascript - 谷歌可视化 map

标签 javascript google-visualization dom-events

我从阅读协会知道。 Google group使用标记 map 时,目前没有点击特定点的事件(仅实现了regionClick)。

但是在阅读文档时注意到事件 Select 说:

select Fired when the user clicks a visual entity. To learn what has been selected, call getSelection(). None

setSelection() none Selects the specified chart entities. Cancels any previous selection. Selectable entities are regions with an assigned value. A region correlates to a row in the data table (column index is null). For this chart, only one entity can be selected at a time. Extended description.

我可以使用它来获取被点击的条目吗?

例子:

       data.addRows([
        ['Rome', 2761477, 1285.31],
        ['Milan', 1324110, 181.76],
        ['Naples', 959574, 117.27],
        ['Turin', 907563, 130.17],
        ['Palermo', 655875, 158.9],
        ['Genoa', 607906, 243.60],
        ['Bologna', 380181, 140.7],
        ['Florence', 371282, 102.41]
      ]);

以某种方式得到 Milan 被点击?我该怎么做?还是我读错了?

用于地理 map 的 Google API:http://code.google.com/apis/chart/interactive/docs/gallery/geochart.html

Google Group 声明在标记模式下没有点击事件: https://groups.google.com/forum/?fromgroups#!topic/google-visualization-api/K8uJoes8ZH0

最佳答案

您需要调用getSelection调用 select 事件时的函数。该函数返回一个对象数组。每个对象都有行和列属性(如果有的话)。使用该行和第一列 (0) 检索标签名称(罗马、米兰...)。

示例(http://jsfiddle.net/VtZQh/):

google.visualization.events.addListener(chart, 'select', function() {
  var selection = chart.getSelection()[0];
  var label = data.getValue(selection.row, 0);
  alert(label);
});

请参阅文档以了解有关 getSelection 的更多信息。

关于javascript - 谷歌可视化 map ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9803588/

相关文章:

google-visualization - 更改堆叠分组 Google 柱形图的颜色

r - gvisMerge + gvisAnnotatedTimeLine 通用 RangeSelector

javascript - 将 Throttle-Debounce 与 addEventListener 结合使用

javascript - 在 JavaScript 中通过字符串调用函数

javascript - jQuery 验证成功显示 gif 加载器

javascript - Google Chart 单击图例隐藏列

javascript - 防止 "enter"按键表单提交但不选择数据列表

javascript - jQuery $ (':input' ).serializeArray();使用 native API 的功能

javascript - 如何将MediaFile对象转换为File对象?

javascript - 在 JavaScript onClick 事件处理程序中转义双引号