gauge.html 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  1. <html>
  2. <head>
  3. <meta charset="utf-8">
  4. <script src="lib/esl.js"></script>
  5. <script src="lib/config.js"></script>
  6. <script src="lib/dat.gui.min.js"></script>
  7. <meta name="viewport" content="width=device-width, initial-scale=1" />
  8. </head>
  9. <body>
  10. <style>
  11. html, body, #main {
  12. width: 100%;
  13. height: 100%;
  14. }
  15. </style>
  16. <div id="main"></div>
  17. <script>
  18. require([
  19. 'echarts'
  20. // 'echarts/chart/gauge',
  21. // 'echarts/component/legend',
  22. // 'echarts/component/tooltip'
  23. ], function (echarts) {
  24. var chart = echarts.init(document.getElementById('main'), null, {
  25. });
  26. var option ={
  27. aria: {
  28. show: true
  29. },
  30. tooltip : {
  31. formatter: '{a} <br/>{c} {b}'
  32. },
  33. toolbox: {
  34. show : true,
  35. feature : {
  36. mark : {show: true},
  37. restore : {show: true},
  38. saveAsImage : {show: true}
  39. }
  40. },
  41. series : [
  42. {
  43. name:'速度',
  44. type:'gauge',
  45. z: 3,
  46. min:0,
  47. max:220,
  48. splitNumber:11,
  49. axisLine: { // 坐标轴线
  50. lineStyle: { // 属性lineStyle控制线条样式
  51. width: 10
  52. }
  53. },
  54. axisTick: { // 坐标轴小标记
  55. length :15, // 属性length控制线长
  56. lineStyle: { // 属性lineStyle控制线条样式
  57. color: 'auto'
  58. }
  59. },
  60. splitLine: { // 分隔线
  61. length :20, // 属性length控制线长
  62. lineStyle: { // 属性lineStyle(详见lineStyle)控制线条样式
  63. color: 'auto'
  64. }
  65. },
  66. axisLabel: {
  67. formatter: '{a|{value}} km/h',
  68. rich: {
  69. a: {
  70. color: '#222',
  71. textBorderColor: '#fff',
  72. textBorderWidth: 2,
  73. backgroundColor: 'auto',
  74. padding: [2, 4],
  75. borderRadius: 3
  76. }
  77. }
  78. },
  79. title : {
  80. textStyle: { // Test compat
  81. fontWeight: 'bolder',
  82. fontSize: 26,
  83. },
  84. offsetCenter: [0, 0],
  85. formatter: '{a|单位:}{value}',
  86. backgroundColor: '#aabbcc',
  87. padding: 10,
  88. borderRadius: 5,
  89. fontStyle: 'italic'
  90. },
  91. detail : {
  92. fontSize: 24,
  93. fontWeight: 'bold',
  94. textStyle: { // Test compat
  95. backgroundColor: '#eeffee',
  96. },
  97. offsetCenter: [0, '70%'],
  98. borderRadius: 10,
  99. borderWidth: 2,
  100. borderColor: '#33aa33',
  101. shadowBlur: 2,
  102. shadowColor: '#222',
  103. shadowOffsetX: 5,
  104. shadowOffsetY: 5,
  105. width: 'auto',
  106. rotate: 15,
  107. textShadowBlur: 2,
  108. textShadowColor: '#66eeaa',
  109. textShadowOffsetX: 2,
  110. textShadowOffsetY: 3,
  111. formatter: [
  112. '{a|码表}',
  113. '{b|{value}}{c|km/h}',
  114. '{j|width is this line is 400}',
  115. '{d|left}{lineHeight|}{f|top}{g|bottom}middle{e|right}{e1|右边}'
  116. ].join('\n'),
  117. rich: {
  118. a: {
  119. fontSize: 34,
  120. color: 'auto',
  121. },
  122. b: {
  123. fontSize: 20,
  124. color: '#12294f',
  125. align: 'center',
  126. padding: [0, 5, 0, 0]
  127. },
  128. c: {
  129. fontSize: 14,
  130. color: '#aa99bb',
  131. rotate: 30,
  132. backgroundColor: '#223344',
  133. borderRadius: 3,
  134. padding: [2, 10]
  135. },
  136. d: {
  137. align: 'left'
  138. },
  139. e: {
  140. align: 'right'
  141. },
  142. e1: {
  143. color: '#33aa99',
  144. fontSize: 16,
  145. align: 'right'
  146. },
  147. f: {
  148. verticalAlign: 'top'
  149. },
  150. g: {
  151. verticalAlign: 'bottom'
  152. },
  153. h: {
  154. align: 'center'
  155. },
  156. i: {
  157. align: 'center'
  158. },
  159. j: {
  160. width: 400,
  161. backgroundColor: '#aabbcc',
  162. color: '#123'
  163. },
  164. lineHeight: {
  165. lineHeight: 46
  166. }
  167. }
  168. },
  169. data:[{value: 40, name: 'km/h'}]
  170. },
  171. {
  172. name:'转速',
  173. type:'gauge',
  174. center : ['25%', '55%'], // 默认全局居中
  175. radius : '50%',
  176. min:0,
  177. max:7,
  178. endAngle:45,
  179. splitNumber:7,
  180. axisLine: { // 坐标轴线
  181. lineStyle: { // 属性lineStyle控制线条样式
  182. width: 8
  183. }
  184. },
  185. axisTick: { // 坐标轴小标记
  186. length :12, // 属性length控制线长
  187. lineStyle: { // 属性lineStyle控制线条样式
  188. color: 'auto'
  189. }
  190. },
  191. splitLine: { // 分隔线
  192. length :20, // 属性length控制线长
  193. lineStyle: { // 属性lineStyle(详见lineStyle)控制线条样式
  194. color: 'auto'
  195. }
  196. },
  197. pointer: {
  198. width:5
  199. },
  200. title : {
  201. // x, y,单位px
  202. offsetCenter: [0, '-30%']
  203. },
  204. detail : {
  205. textStyle: { // 其余属性默认使用全局文本样式,详见TEXTSTYLE
  206. fontWeight: 'bolder',
  207. fontSize: 12
  208. },
  209. },
  210. data:[{value: 1.5, name: 'x1000 r/min'}]
  211. },
  212. {
  213. name:'油表',
  214. type:'gauge',
  215. center : ['75%', '50%'], // 默认全局居中
  216. radius : '50%',
  217. min:0,
  218. max:2,
  219. startAngle:135,
  220. endAngle:45,
  221. splitNumber:2,
  222. axisLine: { // 坐标轴线
  223. lineStyle: { // 属性lineStyle控制线条样式
  224. color: [[0.2, '#ff4500'],[0.8, '#48b'],[1, '#228b22']],
  225. width: 8
  226. }
  227. },
  228. axisTick: { // 坐标轴小标记
  229. splitNumber:5,
  230. length :10, // 属性length控制线长
  231. lineStyle: { // 属性lineStyle控制线条样式
  232. color: 'auto'
  233. }
  234. },
  235. axisLabel: {
  236. formatter:function(v){
  237. switch (v + '') {
  238. case '0' : return 'E';
  239. case '1' : return 'Gas';
  240. case '2' : return 'F';
  241. }
  242. }
  243. },
  244. splitLine: { // 分隔线
  245. length :15, // 属性length控制线长
  246. lineStyle: { // 属性lineStyle(详见lineStyle)控制线条样式
  247. color: 'auto'
  248. }
  249. },
  250. pointer: {
  251. width:2
  252. },
  253. title : {
  254. show: false
  255. },
  256. detail : {
  257. show: false
  258. },
  259. data:[{value: 0.5, name: 'gas'}]
  260. },
  261. {
  262. name:'水表',
  263. type:'gauge',
  264. center : ['75%', '50%'], // 默认全局居中
  265. radius : '50%',
  266. min:0,
  267. max:2,
  268. startAngle:315,
  269. endAngle:225,
  270. splitNumber:2,
  271. axisLine: { // 坐标轴线
  272. lineStyle: { // 属性lineStyle控制线条样式
  273. color: [[0.2, '#ff4500'],[0.8, '#48b'],[1, '#228b22']],
  274. width: 8
  275. }
  276. },
  277. axisTick: { // 坐标轴小标记
  278. show: false
  279. },
  280. axisLabel: {
  281. formatter:function(v){
  282. switch (v + '') {
  283. case '0' : return 'H';
  284. case '1' : return 'Water';
  285. case '2' : return 'C';
  286. }
  287. }
  288. },
  289. splitLine: { // 分隔线
  290. length :15, // 属性length控制线长
  291. lineStyle: { // 属性lineStyle(详见lineStyle)控制线条样式
  292. color: 'auto'
  293. }
  294. },
  295. pointer: {
  296. width: 2
  297. },
  298. title : {
  299. show: false
  300. },
  301. detail : {
  302. show: false
  303. },
  304. data:[{value: 0.5, name: 'gas'}]
  305. }
  306. ]
  307. };
  308. chart.setOption(option);
  309. setInterval(function () {
  310. option.series[0].data[0].value = (Math.random()*100).toFixed(2) - 0;
  311. option.series[1].data[0].value = (Math.random()*7).toFixed(2) - 0;
  312. option.series[2].data[0].value = (Math.random()*2).toFixed(2) - 0;
  313. option.series[3].data[0].value = (Math.random()*2).toFixed(2) - 0;
  314. chart.setOption(option,true);
  315. }, 2000);
  316. // var config = {
  317. // labelPosition: 'outside',
  318. // clockwise: true,
  319. // labelLineLen: 20,
  320. // labelLineLen2: 5
  321. // };
  322. // function update() {
  323. // chart.setOption({
  324. // series: [{
  325. // name: 'pie',
  326. // clockwise: config.clockwise,
  327. // label: {
  328. // normal: {
  329. // position: config.labelPosition
  330. // }
  331. // },
  332. // labelLine: {
  333. // length: config.labelLineLen,
  334. // length2: config.labelLineLen2
  335. // }
  336. // }]
  337. // });
  338. // }
  339. // var gui = new dat.GUI();
  340. // gui.add(config, 'clockwise')
  341. // .onChange(update);
  342. // gui.add(config, 'labelPosition', ['inside', 'outside'])
  343. // .onChange(update);
  344. // gui.add(config, 'labelLineLen', 0, 100)
  345. // .onChange(update);
  346. // gui.add(config, 'labelLineLen2', 0, 100)
  347. // .onChange(update);
  348. })
  349. </script>
  350. </body>
  351. </html>