🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
# 动态实时数据 * 载入数据 ~~~ <script type="text/javascript" src="{relative_root}jquery/jquery-1.12.4.min.js"></script> <script type="text/javascript" src="{relative_root}highcharts/highcharts.js"></script> ~~~ * 承载容器 ~~~ <div id="container" style="height:600px;"></div> ~~~ * 调起js ~~~ var para = {}; para.global = {useUTC: false}; Highcharts.setOptions(para); var json = {}; json.chart = { type: 'spline', events: { load: function () { var series = this.series[0], chart = this; setInterval(function () { var x = (new Date()).getTime(), // 当前时间 y = 1; // 随机值 series.addPoint([x, y], true, true); }, 3000); } } }; json.title = {text: '动态模拟实时数据'}; json.xAxis = {type: 'datetime', tickPixelInterval: 150}; json.yAxis = {title: {text: null}}; json.tooltip = { formatter: function () { return '<b>' + this.series.name + '</b><br/>' + Highcharts.dateFormat('%Y-%m-%d %H:%M:%S', this.x) + '<br/>' + Highcharts.numberFormat(this.y, 2); } }; json.legend = {enabled: false}; json.series = [{ name: '随机数据', data: (function () { // 生成随机值 var data = [],time = (new Date()).getTime(),i; for (i = 0; i <= 10; i ++) { data.push({ x: time + i * 1000, y: i }); } return data; }()) }]; $('#container').highcharts(json); ~~~