getOption.html 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. <html>
  2. <head>
  3. <meta charset="utf-8">
  4. <script src="esl.js"></script>
  5. <script src="config.js"></script>
  6. <meta name="viewport" content="width=device-width, initial-scale=1" />
  7. <link rel="stylesheet" href="reset.css">
  8. </head>
  9. <body>
  10. <style>
  11. </style>
  12. <div>
  13. <input type="button" value="exchangeXY" onclick="go.exchangeXY();">
  14. <input type="button" value="illegal use getModel.option" onclick="go.illegal();">
  15. <input type="button" value="dataZoom restore (error if view changed)" onclick="go.dataZoomRestore();">
  16. </div>
  17. <div id="main"></div>
  18. <script>
  19. var chart;
  20. var myChart;
  21. var go;
  22. require([
  23. 'echarts',
  24. 'echarts/chart/bar',
  25. 'echarts/chart/line',
  26. 'echarts/component/legend',
  27. 'echarts/component/grid',
  28. 'echarts/component/tooltip',
  29. 'echarts/component/markLine',
  30. // dataZoom and toolbox is required for reproduct bug.
  31. 'echarts/component/dataZoom',
  32. 'echarts/component/toolbox'
  33. ], function (echarts) {
  34. chart = myChart = echarts.init(document.getElementById('main'), null, {
  35. renderer: 'canvas'
  36. });
  37. option = {
  38. toolbox: {
  39. feature: {
  40. dataZoom: {}
  41. }
  42. },
  43. dataZoom: [{
  44. show: true,
  45. end: 80
  46. }, {
  47. type: 'inside',
  48. end: 80
  49. }],
  50. legend: {
  51. data:['邮件营销','联盟广告','视频广告','直接访问','搜索引擎']
  52. },
  53. xAxis : [
  54. {
  55. type : 'category',
  56. boundaryGap : false,
  57. data : ['周一','周二','周三','周四','周五','周六','周日']
  58. }
  59. ],
  60. yAxis : [
  61. {
  62. type : 'value'
  63. }
  64. ],
  65. series : [
  66. {
  67. name:'邮件营销',
  68. type:'line',
  69. stack: '总量',
  70. data:[120, 132, 101, 134, 90, 230, 210]
  71. },
  72. {
  73. name:'联盟广告',
  74. type:'line',
  75. stack: '总量',
  76. data:[220, 182, 191, 234, 290, 330, 310]
  77. },
  78. {
  79. name:'视频广告',
  80. type:'line',
  81. stack: '总量',
  82. data:[150, 232, 201, 154, 190, 330, 410]
  83. },
  84. {
  85. name:'直接访问',
  86. type:'line',
  87. stack: '总量',
  88. data:[320, 332, 301, 334, 390, 330, 320]
  89. },
  90. {
  91. name:'搜索引擎',
  92. type:'line',
  93. stack: '总量',
  94. data:[820, 932, 901, 934, 1290, 1330, 1320]
  95. }
  96. ]
  97. };
  98. go = {
  99. exchangeXY: function () {
  100. var option = myChart.getOption();
  101. var temp;
  102. temp = option.xAxis;
  103. option.xAxis = option.yAxis;
  104. option.yAxis = temp;
  105. myChart.setOption(option);
  106. },
  107. illegal: function () {
  108. try {
  109. var option = myChart.getModel.option;
  110. var temp;
  111. temp = option.xAxis;
  112. option.xAxis = option.yAxis;
  113. option.yAxis = temp;
  114. myChart.setOption(option);
  115. alert('error');
  116. }
  117. catch (e) {
  118. alert('ok');
  119. }
  120. },
  121. dataZoomRestore: function () {
  122. var option = myChart.getOption();
  123. myChart.setOption(option);
  124. }
  125. };
  126. chart.setOption(option);
  127. });
  128. </script>
  129. </body>
  130. </html>