console.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. const $ = require('jquery');
  2. require("../css/reset.less")
  3. require("../css/console.less")
  4. require("../images/logo.png")
  5. // import 'zrender/lib/svg/svg';
  6. const echarts = require('echarts');
  7. console.log(echarts)
  8. $(function(){
  9. // var myChart = echarts.init(document.getElementById('echarts'));
  10. var myChart = echarts.init(document.getElementById('main'));
  11. // 绘制图表
  12. let app = {}
  13. let option = {
  14. title: {
  15. text: '饼图程序调用高亮示例',
  16. left: 'center'
  17. },
  18. tooltip: {
  19. trigger: 'item',
  20. formatter: '{a} <br/>{b} : {c} ({d}%)'
  21. },
  22. legend: {
  23. orient: 'vertical',
  24. left: 'left',
  25. data: ['直接访问', '邮件营销', '联盟广告', '视频广告', '搜索引擎']
  26. },
  27. series: [
  28. {
  29. name: '访问来源',
  30. type: 'pie',
  31. radius: '55%',
  32. center: ['50%', '60%'],
  33. data: [
  34. {value: 335, name: '直接访问'},
  35. {value: 310, name: '邮件营销'},
  36. {value: 234, name: '联盟广告'},
  37. {value: 135, name: '视频广告'},
  38. {value: 1548, name: '搜索引擎'}
  39. ],
  40. emphasis: {
  41. itemStyle: {
  42. shadowBlur: 10,
  43. shadowOffsetX: 0,
  44. shadowColor: 'rgba(0, 0, 0, 0.5)'
  45. }
  46. }
  47. }
  48. ]
  49. };
  50. app.currentIndex = -1;
  51. setInterval(function () {
  52. var dataLen = option.series[0].data.length;
  53. // 取消之前高亮的图形
  54. myChart.dispatchAction({
  55. type: 'downplay',
  56. seriesIndex: 0,
  57. dataIndex: app.currentIndex
  58. });
  59. app.currentIndex = (app.currentIndex + 1) % dataLen;
  60. // 高亮当前图形
  61. myChart.dispatchAction({
  62. type: 'highlight',
  63. seriesIndex: 0,
  64. dataIndex: app.currentIndex
  65. });
  66. // 显示 tooltip
  67. myChart.dispatchAction({
  68. type: 'showTip',
  69. seriesIndex: 0,
  70. dataIndex: app.currentIndex
  71. });
  72. }, 1000);
  73. myChart.setOption(option);
  74. })