博客列表 >echarts 下鉆功能

echarts 下鉆功能

手机用户843026802
手机用户843026802原创
2019年12月19日 16:31:08501浏览

echarts 下鉆功能

  1. <!DOCTYPE html>
  2. <html style="height: 100%">
  3. <head>
  4. <meta charset="utf-8">
  5. </head>
  6. <body style="height: 100%; margin: 0">
  7. <div style="margin-left:40%;margin-top:2%">
  8. <button id='return-button' value=''>返回</button>
  9. </div>
  10. <div id="container" style="height: 50%;width: 50%"></div>
  11. <script type="text/javascript" src="echarts.min.js"></script>
  12. <script type="text/javascript" src="jquery-1.10.2.min.js"></script>
  13. <script type="text/javascript" src="drillDown.js"></script>
  14. <script type="text/javascript">
  15. var drillDown = {
  16. getOption : function () {
  17. var option = null;
  18. option = {
  19. title: {
  20. text: '折线图下钻示例原圖',
  21. left: 'center'
  22. },
  23. tooltip: {
  24. trigger: 'item',
  25. formatter: '{a} <br/>{b} : {c}'
  26. },
  27. legend: {
  28. left: 'left',
  29. data: ['月数据']
  30. },
  31. xAxis: {
  32. type: 'category',
  33. name: 'x',
  34. splitLine: {show: false},
  35. data: ['201601', '201602', '201603', '201604', '201605', '201606', '201607', '201608', '201609']
  36. },
  37. grid: {
  38. left: '3%',
  39. right: '4%',
  40. bottom: '3%',
  41. containLabel: true
  42. },
  43. yAxis: {
  44. type: 'log',
  45. name: 'y'
  46. },
  47. series: [{
  48. name: '月数据',
  49. type: 'line',
  50. data: [1, 2, 4, 8, 16, 32, 64, 128, 256]
  51. }]
  52. };
  53. return option;
  54. },
  55. initChart : function (myChart,option) {
  56. myChart.setOption(option);
  57. myChart.on('click',function(object){
  58. // 销毁之前的echarts实例
  59. echarts.dispose(dom);
  60. // 初始化一个新的实例
  61. var myChart = echarts.init(dom);
  62. // object为当前的这个echart对象,大家可以自己打印出来看看
  63. // console.dir(object);
  64. // 我们可以看到name属性即为当前点击点的对应月份值,那么我们可以通过这个值去接口查询对应201609月份下的每一天的值.
  65. // 此处的201609月份数据可以通过接口读取
  66. // $.ajax(
  67. // type : 'get',
  68. // url : interfaceUrl + '&month=' + object.name, // 此处可以替换为你的接口地址
  69. // dataType : 'json',
  70. // success : function (msg){
  71. // option.xAxis.data = msg.xAxis;
  72. // option.series[0].data = msg.yAxis[0];
  73. // myChart.setOption(option, true);
  74. // }
  75. // );
  76. // 我这里就模拟一个测试数据,做为demo演示
  77. option.title.text = '折线图下钻示例鉆圖';
  78. option.xAxis.data = [
  79. '2016-09-01','2016-09-02','2016-09-03','2016-09-04','2016-09-05','2016-09-06','2016-09-07','2016-09-08',
  80. '2016-09-09','2016-09-10','2016-09-11','2016-09-12','2016-09-13','2016-09-14','2016-09-15','2016-09-16',
  81. '2016-09-17','2016-09-18','2016-09-19','2016-09-20','2016-09-21','2016-09-22','2016-09-23','2016-09-24',
  82. '2016-09-25','2016-09-26','2016-09-27','2016-09-28','2016-09-29','2016-09-30'
  83. ];
  84. option.series[0].data = [
  85. 3,4,5,6,5,6,7,8,8,9,
  86. 12,13,15,16,20,12,30,21,22,29,
  87. 30,31,33,34,35,36,20,29,33,40
  88. ];
  89. myChart.setOption(option, true);
  90. });
  91. },
  92. };
  93. var dom = document.getElementById("container");
  94. var myChart = echarts.init(dom);
  95. var option = drillDown.getOption();
  96. drillDown.initChart(myChart,option);
  97. $('#return-button').on('click',function(){
  98. var myChart = echarts.init(dom);
  99. var option = drillDown.getOption();
  100. drillDown.initChart(myChart,option);
  101. });
  102. /*轉自:
  103. https://www.cnblogs.com/luoguixin/p/10191939.html
  104. https://segmentfault.com/a/1190000006978935
  105. */
  106. </script>
  107. </body>
  108. </html>
声明:本文内容转载自脚本之家,由网友自发贡献,版权归原作者所有,如您发现涉嫌抄袭侵权,请联系admin@php.cn 核实处理。
全部评论
文明上网理性发言,请遵守新闻评论服务协议