javascript - Loading effect on google chart refresh -
i have page multiple google charts. have drop-down @ page level. refresh/ reload charts when user changes values drop-down.
everything working fine there few seconds delay between value selection , charts update. want show loading effect overlay , image on page before charts refreshed.
the problem unable overlay effect on top of google charts. loading effect javascript trigger , background gets greyed, loading image hidden behind charts.
jsfiddle problem: https://jsfiddle.net/0tj1pzsk/14/
how can overlay spinner image on top of google charts? placing spinner image inside chart div display first chart load , not subsequent refreshes
code:
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...
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>
Comments
Post a Comment