简体   繁体   English

如何同步和显示不同Google图表的工具提示?

[英]How to sync and display the tooltips of different google charts?

I'm creating different google charts on two iframes for comparison purpose. 我正在两个iframe上创建不同的Google图表,以进行比较。 To achieve that I need to sync the mouse click on both the charts and display the tooltips at the particular position of the click. 为此,我需要同步鼠标在两个图表上的单击,并在单击的特定位置显示工具提示。

Although I've achieved syncing the mouse click by using the chart_2.setSelection(chart_1.getSelection()); 尽管我已经通过使用chart_2.setSelection(chart_1.getSelection());实现了鼠标单击的同步chart_2.setSelection(chart_1.getSelection()); method. 方法。

But the tooltip doesn't get displayed on the second chart at that specific position: 但是工具提示不会在该特定位置的第二张图表上显示:

在此处输入图片说明

The only way to display the tooltip on the second chart is by clicking the chart and then the tooltip gets activated: 在第二张图表上显示工具提示的唯一方法是单击图表,然后激活工具提示:

在此处输入图片说明

After it gets activated then the tooltip syncs with the first chart and works flawlessly with each click: 激活后,工具提示会与第一个图表同步,并且每次单击都可以完美工作:

在此处输入图片说明

What I'm trying to achieve is to display the tooltip on the second chart without manually activating it but it rather gets displayed with each click on the first chart. 我要达到的目的是在第二个图表上显示工具提示,而无需手动激活它,而每次单击第一个图表就会显示它。

set the following option to cause the tooltip to be displayed on --> setSelection 设置以下选项以使工具提示显示在-> setSelection

var options = {
  tooltip: {
    trigger: 'both'
  }
};

see following working snippet, 请参阅以下工作片段,
when the 'ready' event fires, a selection is made, 'ready'事件触发时,将进行选择,
to demonstrate the tooltip is displayed 演示工具提示已显示

 google.charts.load('current', { packages: ['corechart'] }).then(function () { var data = google.visualization.arrayToDataTable([ ['x', 'y0', 'y1', 'y2', 'y3'], [1, 10, 15, 20, 25], [2, 12, 18, 24, 30], [3, 14, 21, 28, 35], [4, 16, 24, 32, 40] ]); var options = { pointSize: 4, tooltip: { trigger: 'both' }, width: 360 }; var chart = new google.visualization.LineChart(document.getElementById('chart_div')); google.visualization.events.addListener(chart, 'ready', function () { chart.setSelection([{row: 2, column: 1}]); }); chart.draw(data, options); }); 
 <script src="https://www.gstatic.com/charts/loader.js"></script> <div id="chart_div"></div> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM