我正在使用谷歌图表API绘制面积图。 该图表表示高度图,当我将鼠标移到它上面时,它会显示基础数据表中的位置(纬度和长度)。
所以我创建了我的图表:
data = new google.visualization.DataTable(json);
chart = new google.visualization.AreaChart(document.getElementById("chart-output"));
并绘制它:
chart.draw(data, options);
并为mouseover事件添加处理程序
当事件触发时,我想从基础数据源获取行
if (event.row != null && event.column != null){
//data is the chart datasource
var o = data.D[event.row];
var sel_x = o.c[0]["coords"]["x"];
var sel_y = o.c[0]["coords"]["y"];
... //show x, y
}
重点是,当项目于去年首次发布时,一切正常,属性data.D
实际上包含了所需的值。
但是现在,我发现相同的属性是未定义的,而行数组是在属性data.tf
中找到的。
我希望通过getter方法访问数据源行,但我找不到合适的行。数据表方法ǵetRowProperties(rowIndex)
不提供任何内容。
我做错了什么?
谢谢和问候
**编辑12/09 **
@Juvian 谢谢你的回复,但它比这复杂一点。 我的数据源是这样的:
{"cols":
[
{"id":"distance","label":"Distance","type":"number"},
{"id":"asfaltocemento","label":"Asphalt/Beton","type":"number"},
{"id":"rocciaghiaia","label":"Fels/Schotter","type":"number"},
{"id":"ghiaccio","label":"Eis","type":"number"},
{"id":"terraprato","label":"Erde/Wiese","type":"number"},
{"id":"sassolastricato","label":"Stein/Pflaster","type":"number"},
{"id":"sconosciuto","label":"Unbekannt","type":"number"}],
"rows":
[
{"c":[{"v":0,"coords": {"x":1296400.1245177952,"y":5885847.104437432,"z":1345.275458520788,"segment_no":0}},{},{"v":1345.275458520788},{},{},{},{}]},
{"c":[{"v":2.8740587294156668,"coords":{"x":1296395.9416741736,"y":5885847.412533606,"z":1345.4754191288682,"segment_no":0}},{},{"v":1345.4754191288682},{},{},{},{}]},
{"c":[{"v":17.583008965075226,"coords":{"x":1296374.532888888,"y":5885848.966197753,"z":1346.3169989102385,"segment_no":0}},{},{"v":1346.3169989102385},{},{},{},{}]},
{"c":[{"v":23.830815143830804,"coords":{"x":1296365.4205057025,"y":5885849.273363226,"z":1346.724445260275,"segment_no":0}}, {},{"v":1346.724445260275},{},{},{},{}]},
....
]}
当我从图形中获取事件时,我会以这种方式检索所需的值:
var o = data.tf[event.row];
var sel_x = o.c[0]["coords"]["x"];
var sel_y = o.c[0]["coords"]["y"];
我知道使用property(tf)不是一个好习惯,我应该使用getValue()这样的访问器,但是使用getValue方法我无法访问'coords'对象及其子对象。
任何帮助将不胜感激
答案 0 :(得分:0)
嗯,data.d不是一个公共方法,所以谷歌可以对其进行更改,你应该使用公共方法来保持一致性。
试试这个:
var sel_x = data.getValue(event.row, 0); // supposing your x value is in fisrt column
var sel_y = data.getValue(event.row, 1); // supposing your y value is in second column
此处有更多信息:Google DataTable