[英]Googlechart javascript chart.getSelection fails with ampersand
[英]chart.getSelection() does not work properly with google bar charts
drawBarChart = function (data) {
//few statements goes here which sets options which are being passed to chartDraw i.e. t.options.chart.options
gChart = new google.visualization.BarChart(chartingPlace);
//setTimeout(function () {
// t.options.chart.options.height = ((t.chart.size.height) - 40) + "px";
////console.log(JSON.stringify(t.options.chart.options));
//google.visualization.events.addListener(gChart, 'ready', function () {
// grab a few details before redirecting
google.visualization.events.addListener(gChart, 'select', function () {
var selectedItem = gChart.getSelection()[0];
console.log(gChart.getSelection());
if (selectedItem) {
var topping = data.getValue(selectedItem.row, 0);
alert('The user selected ' + topping);
}
// });
});
gChart.draw(data, t.options.chart.options);
}
我的應用程序具有許多針對不同情況顯示的圖表。 我的要求是,點擊Google條形圖中的條形,然后打開一個與條形名稱相關聯的新標簽。 為此,我嘗試在條形圖上使用直接的“ select”事件,如下所示:
google.visualization.events.addListener(gChart, 'select', function () {
var selectedItem = gChart.getSelection()[0];
console.log(gChart.getSelection());
if (selectedItem) {
var topping = data.getValue(selectedItem.row, 0);
alert('The user selected ' + topping);
}
});
但是我聽不到,這為gChart.getSelection()返回了空數組,所以我嘗試了上面第一個代碼中提到的“ ready”事件代碼。 它可以工作,但不能輸出不一致。 有時會給出空數組,有時會給出選定的對象。
我仍然無法找到為什么它表現出這種行為
更多信息:我的應用程序具有不同的選項卡,在其上顯示條形圖,折線圖,面積圖,組合圖的數量。 getSelection()與折線圖搭配使用效果很好,但無法獲得條形圖的一致輸出。
任何幫助都是可觀的。
請不要將其標記為重復項,因為我已經經歷了其他類似的問題,但是它們沒有回答我的問題,我沒有這種特權,因此我無法在回復中發表評論以尋求更多的說明。 類似的問題在這里: 條形圖isStacked上的Google可視化單擊事件:true
請幫忙!
先感謝您!
更新:我無法從這里得到任何答案或任何回應。 這真的很令人失望。
解決方案 :這是我解決此問題的方法:getSelection無法為我工作,因此我嘗試了條形文本上的click事件。 通過單擊事件,我可以在欄上看到文本,並將其鏈接到opn新選項卡。
如果有人需要代碼中的解決方案,請告訴我。
謝謝。
請更正下面的代碼段,我已更正,或者您可以說以不同的方式組織了代碼。 如果您需要進一步的解釋,請告訴我。
google.visualization.events.addListener(googleChartObj, 'select', function () {
var selectedBar = googleChartObj.getSelection();
////console.log(selectedBar);
data.getRowLabel(selectedBar[0].row);
/// for Bar charts, normally row-parameters are used
/// manipulate on 'data' which refers to data-table to get desired results
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.