lines-grid.html 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. <!DOCTYPE>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <script src="lib/esl.js"></script>
  6. <script src="lib/config.js"></script>
  7. <script src="lib/jquery.min.js"></script>
  8. <script src="lib/facePrint.js"></script>
  9. <meta name="viewport" content="width=device-width, initial-scale=1" />
  10. <link rel="stylesheet" href="lib/reset.css">
  11. </head>
  12. <body>
  13. <style>
  14. #main {
  15. height: 500px;
  16. }
  17. </style>
  18. <div id="main"></div>
  19. <script>
  20. var echarts;
  21. var colorTool;
  22. var chart;
  23. var myChart;
  24. var groupCategories = [];
  25. var groupColors = [];
  26. require([
  27. 'echarts'
  28. // 'zrender/tool/color',
  29. // 'echarts/chart/lines',
  30. // 'echarts/chart/line',
  31. // 'echarts/component/grid',
  32. // 'echarts/component/legend',
  33. // 'echarts/component/tooltip',
  34. // 'echarts/component/toolbox',
  35. // 'echarts/component/visualMap'
  36. ], function (ec, ct) {
  37. echarts = ec;
  38. colorTool = echarts.color;
  39. chart = myChart = echarts.init(document.getElementById('main'));
  40. var json = {
  41. chart0:{
  42. text: '未来一周气温变化',
  43. subtext: '纯属虚构',
  44. legend: [['最高气温', '最低气温'],['A','B']],
  45. xcategory: ['周一', '周二', '周三', '周四', '周五', '周六', '周日'],
  46. high: [11, 11, 15, 13, 12, 13, 10],
  47. highLine: [],
  48. low: [1, -2, 2, 5, 3, 2, 0],
  49. lowLine:[],
  50. avg:[]
  51. }
  52. };
  53. var zrUtil = echarts.util;
  54. var zrVector = echarts.vector;
  55. var zrMatrix = echarts.matrix;
  56. var zrNumber = echarts.number;
  57. var zrFormat = echarts.format;
  58. var zrGraphic = echarts.graphic;
  59. zrUtil.each(json.chart0.xcategory, function(item, index){
  60. json.chart0.highLine.push([{coord:[index,json.chart0.high[index]] },{coord:[index+1,json.chart0.high[index+1]]}]);
  61. });
  62. zrUtil.each(json.chart0.xcategory, function(item, index){
  63. json.chart0.lowLine.push([{coord:[index,json.chart0.low[index]] },{coord:[index+1,json.chart0.low[index+1]]}]);
  64. });
  65. zrUtil.each(json.chart0.high, function(item, index){
  66. json.chart0.avg.push((json.chart0.low[index] + json.chart0.high[index]) / 2);
  67. });
  68. var option = {
  69. title: {
  70. text: json.chart0.text,
  71. subtext: json.chart0.subtext
  72. },
  73. animationEasing: 'ElasticOut',
  74. legend: [{
  75. data: json.chart0.legend[0]
  76. },{
  77. data: json.chart0.legend[1],
  78. top:15,
  79. }],
  80. calculable: true,
  81. xAxis: [{
  82. type: 'category',
  83. axisLabel:{
  84. formatter:function(value){
  85. var sepCount = 1;//每几个字符分隔
  86. return value.replace(/(\S{1})(?=[^$])/g, "$1\n\n")
  87. }
  88. },
  89. boundaryGap: false,
  90. data: json.chart0.xcategory
  91. }],
  92. yAxis: [{
  93. type: 'value',
  94. axisLabel: {
  95. formatter: '{value} °C'
  96. }
  97. }],
  98. series: [{
  99. name: '最高气温',
  100. type: 'line',
  101. data: json.chart0.high
  102. }, {
  103. name: '最低气温',
  104. type: 'line',
  105. data: json.chart0.low
  106. },{
  107. name: '平均气温',
  108. type: 'line',
  109. data: json.chart0.avg
  110. },{
  111. name: 'A',
  112. type: 'lines',
  113. coordinateSystem: 'cartesian2d',
  114. zlevel: 2,
  115. effect: {
  116. show: true,
  117. smooth: false,
  118. period: 6,
  119. //trailLength: 0,
  120. //symbol: planePath,
  121. //color:'rgba(55,155,255,0.5)',
  122. symbolSize: 8
  123. },
  124. data: json.chart0.highLine
  125. },{
  126. name: 'B',
  127. type: 'lines',
  128. coordinateSystem: 'cartesian2d',
  129. zlevel: 2,
  130. effect: {
  131. show: true,
  132. smooth: false,
  133. period: 6,
  134. symbolSize: 8
  135. },
  136. data: json.chart0.lowLine
  137. }]
  138. };
  139. chart.setOption(option);
  140. });
  141. </script>
  142. </body>
  143. </html>