Highcharts How to Show Loading Animation At Set Da

2019-02-16 11:00发布

I have highcharts graphics. When I create my page I show empty graphics (I don't set data attribute and there is only titles of graphics, inside of them is empty.) I get data from server asynchronously and call

setData()

function at callback. However user sees an empty page and I want to show a loading image for them. This: http://api.highcharts.com/highcharts#loading doesn't work for me.

Any ideas?

4条回答
该账号已被封号
2楼-- · 2019-02-16 11:28

"Loading.." word seems too amateur. Use that trick instead

var chart = new Highcharts.Chart(options);
chart.showLoading('<img src="/images/spinner.gif">');

$.getJSON(url, function(data){
       //load data to chart
       chart.hideLoading();
});
查看更多
老娘就宠你
3楼-- · 2019-02-16 11:28

This is a simple piece i always use to show the loading.

let's say this is our container

<div id='container'>
  <img id="spinner" src="/assets/chart_loader.gif"/>
</div>

And this is the piece of ajax that takes care to show when the getJson starts for the chart and hide when it stops.

$(document).ajaxStart ->
  $("#spinner").show()

$(document).ajaxComplete ->
  $("#spinner").hide()
查看更多
看我几分像从前
4楼-- · 2019-02-16 11:30

You can define globally for each page using this plugin JQuery Block UI

and usage is

  jQuery(document).ready(function ($) {
        $.ajaxSetup({ cache: false });
        $(document).ajaxStart(function () {
        $('body').block({
            message: '<h3><img alt="" class="GifIcon" src="Images/319.gif" />Please wait Data is Loading From Server ...... </h3>'
        });
    });
    $(document).ajaxStop(function () {
        $('body').unblock();
    });

});
查看更多
叛逆
5楼-- · 2019-02-16 11:39

I did it work as explained at given URL:

function updateGraphic(url, chartName) {
    chartName.showLoading();
    $.getJSON(url, function(data){
        chartName.series[0].setData(data);
        chartName.hideLoading();
    });
}
查看更多
登录 后发表回答