我正在使用谷歌圖表API繪製區域圖表。 該圖表代表高度剖面,當我將鼠標移過該圖表時,它會顯示底層數據表的位置(lat和long)。google areachart無法訪問數據錶行
所以我創造了我的圖表:
data = new google.visualization.DataTable(json);
chart = new google.visualization.AreaChart(document.getElementById("chart-output"));
,並繪製它:
chart.draw(data, options);
並添加處理鼠標懸停事件
當事件觸發,我想要得到的來自底層數據源的行
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"];
我知道這不是財產使用一個很好的做法(TF ),我應該使用getValue()之類的訪問器,但是使用getValue方法我無法訪問'coords'對象及其子對象。
任何幫助將不勝感激