legend.html 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <meta name="description" content="ECharts">
  8. <meta name="author" content="kener.linfeng@gmail.com">
  9. <title>ECharts · Example</title>
  10. <link rel="shortcut icon" href="../asset/ico/favicon.png">
  11. <link href="../asset/css/font-awesome.min.css" rel="stylesheet">
  12. <link href="../asset/css/bootstrap.css" rel="stylesheet">
  13. <link href="../asset/css/carousel.css" rel="stylesheet">
  14. <link href="../asset/css/echartsHome.css" rel="stylesheet">
  15. <!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
  16. <!--[if lt IE 9]>
  17. <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
  18. <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
  19. <![endif]-->
  20. <script src="./www/js/echarts.js"></script>
  21. <script src="../asset/js/codemirror.js"></script>
  22. <script src="../asset/js/javascript.js"></script>
  23. <link href="../asset/css/codemirror.css" rel="stylesheet">
  24. <link href="../asset/css/monokai.css" rel="stylesheet">
  25. </head>
  26. <body>
  27. <!-- Fixed navbar -->
  28. <div class="navbar navbar-default navbar-fixed-top" role="navigation" id="head"></div>
  29. <div class="container-fluid">
  30. <div class="row-fluid example">
  31. <div id="sidebar-code" class="col-md-4">
  32. <div class="well sidebar-nav">
  33. <div class="nav-header"><a href="#" onclick="autoResize()" class="glyphicon glyphicon-resize-full" id ="icon-resize" ></a>option</div>
  34. <textarea id="code" name="code">
  35. option = {
  36. legend: {
  37. orient: 'horizontal', // 'vertical'
  38. x: 'right', // 'center' | 'left' | {number},
  39. y: 'top', // 'center' | 'bottom' | {number}
  40. backgroundColor: '#eee',
  41. borderColor: 'rgba(178,34,34,0.8)',
  42. borderWidth: 4,
  43. padding: 10, // [5, 10, 15, 20]
  44. itemGap: 20,
  45. textStyle: {color: 'red'},
  46. selected: {
  47. '降水量' : false
  48. },
  49. data: [
  50. {
  51. name:'蒸发量',
  52. icon : 'image://../asset/ico/favicon.png',
  53. textStyle:{fontWeight:'bold', color:'green'}
  54. },
  55. '降水量','最高气温', '最低气温'
  56. ]
  57. },
  58. xAxis :{
  59. data : ['周一','周二','周三','周四','周五','周六','周日']
  60. },
  61. yAxis : [
  62. {
  63. type : 'value',
  64. axisLabel : {
  65. formatter: '{value} ml'
  66. }
  67. },
  68. {
  69. type : 'value',
  70. axisLabel : {
  71. formatter: '{value} °C'
  72. },
  73. splitLine : {show : false}
  74. }
  75. ],
  76. series : [
  77. {
  78. name:'蒸发量',
  79. type:'bar',
  80. data:[2.0, 4.9, 7.0, 23.2, 25.6, 76.7, 135.6]
  81. },
  82. {
  83. name:'最高气温',
  84. type:'line',
  85. yAxisIndex: 1,
  86. data:[11, 11, 15, 13, 12, 13, 10]
  87. },
  88. {
  89. name:'降水量',
  90. type:'bar',
  91. data:[2.6, 5.9, 9.0, 26.4, 28.7, 70.7, 175.6]
  92. }
  93. ]
  94. };
  95. // 动态添加默认不显示的数据
  96. var ecConfig = require('echarts/config');
  97. myChart.on(ecConfig.EVENT.LEGEND_SELECTED, function (param){
  98. var selected = param.selected;
  99. var len;
  100. var added;
  101. if (selected['最低气温']) {
  102. len = option.series.length;
  103. added = false;
  104. while (len--) {
  105. if (option.series[len].name == '最低气温') {
  106. // 已经添加
  107. added = true;
  108. break;
  109. }
  110. }
  111. if (!added) {
  112. myChart.showLoading({
  113. text : '数据获取中',
  114. effect: 'whirling'
  115. });
  116. setTimeout(function (){
  117. option.series.push({
  118. name:'最低气温',
  119. type:'line',
  120. yAxisIndex: 1,
  121. data:[-2, 1, 2, 5, 3, 2, 0]
  122. });
  123. myChart.hideLoading();
  124. myChart.setOption(option);
  125. }, 2000)
  126. }
  127. }
  128. });
  129. </textarea>
  130. </div><!--/.well -->
  131. </div><!--/span-->
  132. <div id="graphic" class="col-md-8">
  133. <div id="main" class="main"></div>
  134. <div>
  135. <button type="button" class="btn btn-sm btn-success" onclick="refresh(true)">刷 新</button>
  136. <span class="text-primary">切换主题</span>
  137. <select id="theme-select"></select>
  138. <span id='wrong-message' style="color:red"></span>
  139. </div>
  140. </div><!--/span-->
  141. </div><!--/row-->
  142. </div><!--/.fluid-container-->
  143. <footer id="footer"></footer>
  144. <!-- Le javascript
  145. ================================================== -->
  146. <!-- Placed at the end of the document so the pages load faster -->
  147. <script src="../asset/js/jquery.min.js"></script>
  148. <script type="text/javascript" src="../asset/js/echartsHome.js"></script>
  149. <script src="../asset/js/bootstrap.min.js"></script>
  150. <script src="../asset/js/echartsExample.js"></script>
  151. </body>
  152. </html>