| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- <!DOCTYPE html>
- <html lang="zh">
- <head>
- <meta charset="UTF-8">
- <title>Title</title>
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <script src="code/highcharts.js"></script>
- <script src="code/modules/exporting.js"></script>
- <script src="code/plugins/highcharts-zh_CN.js"></script>
- <style>
- #content div {
- float: left;
- }
- </style>
- <script>
- var time = new Date();
- window.onload = function () {
- getData();
- loopGetData(1000);
- }
- function getData() {
- var x = time.getTime(), y = Math.random() * 100; // x 时间 y 随机数据
- cpuChart.series[0].addPoint([x, y], true, true, true);
- y = Math.random() * 100; // 随机数据
- memChart.series[0].addPoint([x, y], true, true, true);
- }
- function loopGetData(loopTime) {
- setInterval(function () {
- time = new Date(time.getTime() + 1000);
- getData();
- }, loopTime);
- }
- </script>
- </head>
- <body>
- <div id="content">
- <div id="container" style="width: 400px; height:200px;"></div>
- <div id="container_mem" style="width: 400px; height:200px;"></div>
- </div>
- <script>
- function getConfig(name, count) {
- return {
- chart: {
- // type: 'spline',
- marginRight: 10
- },
- exporting: {
- buttons: {
- contextButton: {
- menuItems: null,
- onclick: function () {
- this.fullscreen.toggle();
- }
- }
- }
- },
- title: {
- text: name
- },
- xAxis: {
- type: 'datetime',
- tickPixelInterval: 150
- },
- credits: {
- enabled: false
- },
- yAxis: {
- title: {
- text: null
- }
- },
- 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);
- }
- },
- legend: {
- enabled: false
- },
- plotOptions: {
- series: {
- marker: {
- enabled: false
- }
- }
- },
- series: [{
- name: name,
- data: (function () {
- var data = [], i;
- for (i = count * -1; i <= 0; i += 1) {
- data.push({
- x: null,
- y: null
- });
- }
- return data;
- }())
- }]
- };
- }
- Highcharts.setOptions({
- global: {
- useUTC: false
- }
- });
- function activeLastPointToolip(chart) {
- var points = chart.series[0].points;
- chart.tooltip.refresh(points[points.length - 1]);
- }
- // var time = (new Date()).getTime();
- var cpuChart = Highcharts.chart('container', getConfig('CPU', 20));
- var memChart = Highcharts.chart('container_mem', getConfig('Memory', 20));
- </script>
- </body>
- </html>
|