Highcharts加载图片

时间:2013-02-04 15:55:00

标签: highcharts

使用http://api.highcharts.com/highcharts#loading

是否可以将图像作为显示的叠加层的一部分?特别是“加载”gif图像?

我尝试过使用labelStyle部分,但到目前为止还没有运气!

2 个答案:

答案 0 :(得分:5)

检查API后。这似乎是可能的。

labelStyle接受任何有效的CSS。通常为连字符的属性会删除连字符,并将下一个字母大写。这意味着我们可以使用类似background-image的内容来提供背景图片(例如加载.gif)。

var chart = new Highcharts.Chart({
    // ...

    loading: {
        labelStyle: {
            backgroundImage: 'url("http://jsfiddle.net/img/logo.png")',
            display: 'block',
            width: '136px',
            height: '26px',
            backgroundColor: '#000'
        }
    },

    // ...
});

Example fiddle here

答案 1 :(得分:1)

查看此示例以了解自定义加载



$(function () {
    // the button handler
    var isLoading = false,
        $button = $('#button');
    $button.click(function() {
        if (!isLoading) {
            chart.showLoading();
            $button.html('Hide loading');
        } else {
            chart.hideLoading();
            $button.html('Show loading');
        }
        isLoading = !isLoading;
    });
    
    
    // create the chart
    var chart = new Highcharts.Chart({
        chart: {
            renderTo: 'container'
        },
        xAxis: {
            categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
        },
        
        series: [{
            data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4]        
        }]
    });
});

.highcharts-loading {
  opacity: 1!important;
}
.highcharts-loading-inner {
  display: block;
}

.highcharts-loading-inner,
.highcharts-loading-inner:before,
.highcharts-loading-inner:after {
  background: #dfdfdf;
  -webkit-animation: load1 1s infinite ease-in-out;
  animation: load1 1s infinite ease-in-out;
  width: 1em;
  height: 4em;
}
.highcharts-loading-inner {
  color: #dfdfdf;
  text-indent: -9999em;
  margin: 0 auto;
  top: 50%!important;
  position: relative;
  font-size: 11px;
  -webkit-transform: translate3d(-50%, -50%, 0);
  -ms-transform: translate3d(-50%, -50%, 0);
  transform: translate3d(-50%, -50%, 0);
  -webkit-animation-delay: -0.16s;
  animation-delay: -0.16s;
}
.highcharts-loading-inner:before,
.highcharts-loading-inner:after {
  position: absolute;
  top: 0;
  content: '';
}
.highcharts-loading-inner:before {
  left: -1.5em;
  -webkit-animation-delay: -0.32s;
  animation-delay: -0.32s;
}
.highcharts-loading-inner:after {
  left: 1.5em;
}
@-webkit-keyframes load1 {
  0%,
  80%,
  100% {
    box-shadow: 0 0;
    height: 4em;
  }
  40% {
    box-shadow: 0 -2em;
    height: 5em;
  }
}
@keyframes load1 {
  0%,
  80%,
  100% {
    box-shadow: 0 0;
    height: 4em;
  }
  40% {
    box-shadow: 0 -2em;
    height: 5em;
  }
}

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="http://code.highcharts.com/highcharts.js"></script>

<div id="container" style="height: 400px"></div>
<button id="button">Show loading...</button>

<!-- Spinners -->
<!-- https://projects.lukehaas.me/css-loaders/ -->
&#13;
&#13;
&#13;