showrealtime.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. var defaultData = './pref_realtime_get.php?api=all&item=count';
  2. var urlInput = document.getElementById('fetchURL');
  3. var pollingCheckbox = document.getElementById('enablePolling');
  4. var pollingInput = document.getElementById('pollingTime');
  5. function createChart(div,title,api,item) {
  6. Highcharts.chart(div, {
  7. chart: {
  8. type: 'spline'
  9. },
  10. title: {
  11. text: title
  12. },
  13. accessibility: {
  14. announceNewData: {
  15. enabled: true,
  16. minAnnounceInterval: 15000,
  17. announcementFormatter: function (allSeries, newSeries, newPoint) {
  18. if (newPoint) {
  19. return 'New point added. Value: ' + newPoint.y;
  20. }
  21. return false;
  22. }
  23. }
  24. },
  25. data: {
  26. csvURL: './pref_realtime_get.php?api='+api+'&item='+item,
  27. enablePolling: pollingCheckbox.checked === true,
  28. dataRefreshRate: 60
  29. }
  30. });
  31. }
  32. // We recreate instead of using chart update to make sure the loaded CSV
  33. // and such is completely gone.
  34. pollingCheckbox.onchange = createChart;
  35. // Create the chart
  36. createChart("chart-1",'总请求次数/分钟','all','count');
  37. createChart("chart-2",'总执行时间(毫秒)/分钟','all','delay');
  38. createChart("chart-3",'平均执行时间(毫秒/API)','all','average');
  39. create_live("chart-4");
  40. function create_live(container){
  41. Highcharts.chart(container, {
  42. chart: {
  43. type: 'gauge',
  44. plotBackgroundColor: null,
  45. plotBackgroundImage: null,
  46. plotBorderWidth: 0,
  47. plotShadow: false
  48. },
  49. title: {
  50. text: '实时平均执行时间'
  51. },
  52. pane: {
  53. startAngle: -150,
  54. endAngle: 150,
  55. background: [{
  56. backgroundColor: {
  57. linearGradient: { x1: 0, y1: 0, x2: 0, y2: 1 },
  58. stops: [
  59. [0, '#FFF'],
  60. [1, '#333']
  61. ]
  62. },
  63. borderWidth: 0,
  64. outerRadius: '109%'
  65. }, {
  66. backgroundColor: {
  67. linearGradient: { x1: 0, y1: 0, x2: 0, y2: 1 },
  68. stops: [
  69. [0, '#333'],
  70. [1, '#FFF']
  71. ]
  72. },
  73. borderWidth: 1,
  74. outerRadius: '107%'
  75. }, {
  76. // default background
  77. }, {
  78. backgroundColor: '#DDD',
  79. borderWidth: 0,
  80. outerRadius: '105%',
  81. innerRadius: '103%'
  82. }]
  83. },
  84. // the value axis
  85. yAxis: {
  86. min: 0,
  87. max: 5000,
  88. minorTickInterval: 'auto',
  89. minorTickWidth: 1,
  90. minorTickLength: 10,
  91. minorTickPosition: 'inside',
  92. minorTickColor: '#666',
  93. tickPixelInterval: 30,
  94. tickWidth: 2,
  95. tickPosition: 'inside',
  96. tickLength: 10,
  97. tickColor: '#666',
  98. labels: {
  99. step: 2,
  100. rotation: 'auto'
  101. },
  102. title: {
  103. text: '毫秒/API'
  104. },
  105. plotBands: [{
  106. from: 0,
  107. to: 2000,
  108. color: '#55BF3B' // green
  109. }, {
  110. from: 2000,
  111. to: 3500,
  112. color: '#DDDF0D' // yellow
  113. }, {
  114. from: 3500,
  115. to: 5000,
  116. color: '#DF5353' // red
  117. }]
  118. },
  119. series: [{
  120. name: 'Speed',
  121. data: [80],
  122. tooltip: {
  123. valueSuffix: ' ms/s'
  124. }
  125. }]
  126. },
  127. // Add some life
  128. function (chart) {
  129. if (!chart.renderer.forExport) {
  130. setInterval(function () {
  131. $.get("./pref_live.php?api=all&item=average",function(data){
  132. var point = chart.series[0].points[0];
  133. newVal = parseInt(data);
  134. point.update(newVal);
  135. });
  136. }, 3000);
  137. }
  138. });
  139. }