简体   繁体   English

加载效果在谷歌图表刷新

[英]Loading effect on google chart refresh

I have a page with multiple google charts. 我有一个包含多个谷歌图表的页面。 I also have a drop-down at page level. 我还有一个页面级别的下拉菜单。 I refresh/ reload the charts when user changes values from this drop-down. 当用户更改此下拉列表中的值时,我会刷新/重新加载图表。

Everything is working fine but there is a few seconds delay between value selection and charts update. 一切正常,但值选择和图表更新之间有几秒钟的延迟。 I want to show a loading effect overlay and image on the page before all charts are refreshed. 我想在刷新所有图表之前在页面上显示加载效果叠加和图像。

The problem is that I am unable to overlay this effect on top of google charts. 问题是我无法在谷歌图表上覆盖此效果。 The loading effect javascript does trigger and the background gets greyed, but loading image is hidden behind the charts. 加载效果javascript确实触发并且背景变灰,但加载图像隐藏在图表后面。

Jsfiddle for the problem: https://jsfiddle.net/0tj1pzsk/14/ Jsfiddle的问题: https ://jsfiddle.net/0tj1pzsk/14/

How can I overlay spinner image on top of google charts? 如何在微软图表上叠加微调图像? Placing spinner image inside chart div will only display it for the first chart load and not subsequent refreshes 将微调器图像放置在图表div中只会显示第一个图表加载而不是后续刷新

Code: 码:

CSS CSS

#loading-img {
  background: url(https://i1.wp.com/cdnjs.cloudflare.com/ajax/libs/galleriffic/2.0.1/css/loader.gif) center center no-repeat;
  height: 100%;
  z-index: 20;
}

.loading {
  background: #a3a3a3;
  display: none;
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  opacity: 0.5;
}

Javascript

$('#test').click( function() {
  $('.loading').show(); 
});

google.charts.load("current", {packages:['corechart']});
google.charts.setOnLoadCallback(drawChart);
function drawChart() {
  var data = new google.visualization.arrayToDataTable([
    ['Threat', 'Attacks'],
    ['Chandrian', 38],
    ['Ghosts', 12],
    ['Ghouls', 6],
    ['UFOs', 44],
    ['Vampires', 28],
    ['Zombies', 88]
  ]);

  var options = {
    legend: 'none',
    colors: ['#760946'],
    vAxis: { gridlines: { count: 4 } }
  };

  var chart = new google.visualization.LineChart(document.getElementById('line-chart'));
  chart.draw(data, options);
};

 html

 <button id="test">test</button>
 <div class="loading"><div id="loading-img"></div></div>
 <div id="line-chart"></div>

try moving css... 尝试移动CSS ...

z-index: 20;

from... 从...

#loading-img

to... 至...

.loading

see following example... 见以下例子......

 $('#test').click( function() { $('.loading').show(); }); google.charts.load("current", {packages:['corechart']}); google.charts.setOnLoadCallback(drawChart); function drawChart() { var data = new google.visualization.arrayToDataTable([ ['Threat', 'Attacks'], ['Chandrian', 38], ['Ghosts', 12], ['Ghouls', 6], ['UFOs', 44], ['Vampires', 28], ['Zombies', 88] ]); var options = { legend: 'none', colors: ['#760946'], vAxis: { gridlines: { count: 4 } } }; var chart = new google.visualization.LineChart(document.getElementById('line-chart')); chart.draw(data, options); }; 
 #loading-img { background: url(https://i1.wp.com/cdnjs.cloudflare.com/ajax/libs/galleriffic/2.0.1/css/loader.gif) center center no-repeat; height: 100%; } .loading { background: #a3a3a3; display: none; position: absolute; top: 0; right: 0; bottom: 0; left: 0; opacity: 0.5; z-index: 20; } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <script src="https://www.gstatic.com/charts/loader.js"></script> <button id="test">test</button> <div class="loading"><div id="loading-img"></div></div> <div id="line-chart"></div> 

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

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