Google JSAPI:为标记Geocharts添加不可见数据 [英] Google JSAPI: Adding Invisible Data For Marker Geocharts

查看:83
本文介绍了Google JSAPI:为标记Geocharts添加不可见数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



类似于:

  var data = new google.visualization.DataTable(); 
data.addColumn('number','Lat'); //纬度值
data.addColumn('number','Lon'); //经度值
data.addColumn('string','Name'); //
data.addColumn('数字','消费者价格指数(CPI)','价值'); //
data.addColumn('string','Invisible'); //

稍后:

 google.visualization.events.addListener(geomap,'select',function(){
var selection = geomap.getSelection()[0];
window.location =选择[4];
});

我在加载地图时收到错误消息:

 不兼容的数据表:错误:表包含比预期多的列(期望4列)

所以它看起来像DataTable不接受我的Invisible列。



任何想法如何解决这个问题?

解决方案

没有找到我的问题的答案,我找到了一个不使用DataView的解决方法(数据转换可能会很慢),因此它可能快得多。



我使用与主DataTable相同的顺序创建了另一个包含其他数据(变量 hrefs )的数组,并且我在事件中使用它:



pre $ lt; code> google.visualization.events.addListener(chart,'select',function(){
var selection = chart.getSelection() ;
var row = selection [0] .row;
window.location = hrefs [row];
});

至少在Chrome中有效; - )


I need to add an "invisible" column, which would be triggered on select.

Something like:

  var data = new google.visualization.DataTable();
  data.addColumn('number', 'Lat'); // Latitude Value
  data.addColumn('number', 'Lon'); // Longitude Value
  data.addColumn('string', 'Name'); // 
  data.addColumn('number', 'Consumer Price Index (CPI)', 'Value'); // 
  data.addColumn('string', 'Invisible'); // 

And later on:

  google.visualization.events.addListener(geomap, 'select', function() {
      var selection = geomap.getSelection()[0];
      window.location = selection[4];
  });

I'm getting Error message while loading the map:

Incompatible data table: Error: Table contains more columns than expected (Expecting 4 columns)

So it looks like DataTable doesn't accept my Invisible column.

Any idea how to fix that?

解决方案

Although I haven't found the answer to my question, I've found a workaround which doesn't use DataView (data transform could potentially be slow) and therefore, it is probably much faster.

I've created another array with additional data (variable hrefs) in the same order as main DataTable and I do use it in the event as:

google.visualization.events.addListener(chart, 'select', function() {
    var selection = chart.getSelection();
    var row = selection[0].row;
    window.location = hrefs[row];
});

It works at least in Chrome ;-)

这篇关于Google JSAPI:为标记Geocharts添加不可见数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆