com-chart-2.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <!-- 统计图2 -->
  2. <template>
  3. <div class="echarts-div" id='pic-chart' ref='pic-chart'></div>
  4. </template>
  5. <script>
  6. module.exports = {
  7. data() {
  8. return {
  9. }
  10. },
  11. methods: {
  12. // 刷新饼图
  13. f5PieChart: function() {
  14. // =========================================== 定义数据
  15. var dataArray = [
  16. {name: '昵称注册', value: sa.randomNum(100, 1000)},
  17. {name: '手机号注册', value: sa.randomNum(100, 1000)},
  18. {name: '微信登陆', value: sa.randomNum(100, 1000)},
  19. {name: 'QQ登陆', value: sa.randomNum(100, 1000)},
  20. {name: '邮箱登录', value: sa.randomNum(100, 1000)},
  21. {name: '小程序登录', value: sa.randomNum(100, 1000)},
  22. {name: '管理员添加', value: sa.randomNum(100, 1000)},
  23. ]; // 坐标X轴数据
  24. // =========================================== 开始渲染
  25. var myChart = echarts.init(document.getElementById('pic-chart'));
  26. option = {
  27. title: {
  28. text: '账号来源',
  29. left: 'left',
  30. top: 0,
  31. textStyle: {
  32. color: '#666',
  33. fontSize: '14'
  34. }
  35. },
  36. toolbox: {
  37. show: true,
  38. top: 0,
  39. feature: {
  40. saveAsImage: {
  41. show: true
  42. }
  43. }
  44. },
  45. tooltip: {
  46. trigger: 'item',
  47. formatter: "{a} <br/>{b} : {c} ({d}%)"
  48. },
  49. series: [{
  50. name: '账号来源',
  51. type: 'pie',
  52. radius: '70%', // 半径大小
  53. center: ['50%', '60%'],
  54. selectedMode: 'single',
  55. roseType: 'radius',
  56. data: dataArray.sort(function(a, b) {
  57. return a.value - b.value;
  58. }),
  59. //roseType: 'radius', // 半径模式还是面积模式
  60. itemStyle: {
  61. normal: {
  62. color: function(params) {
  63. // build a color map as your need.
  64. var colorList = [
  65. '#ff7f50','#87cefa','#da70d6','#32cd32','#6495ed',
  66. '#ff69b4','#ba55d3','#cd5c5c','#ffa500','#40e0d0',
  67. '#1e90ff','#ff6347','#7b68ee','#00fa9a',
  68. '#6699FF','#ff6666','#3cb371','#b8860b','#30e0e0'
  69. ];
  70. // '#ffd700',
  71. function GetRandomNum(Min, Max) {
  72. var Range = Max - Min;
  73. var Rand = Math.random();
  74. return (Min + Math.round(Rand * Range));
  75. }
  76. var index = GetRandomNum(0, colorList.length - 1);
  77. return colorList[index];
  78. //return colorList[params.dataIndex]
  79. }
  80. }
  81. },
  82. label: {
  83. normal: {
  84. formatter: '{b|{b}:}{c} {per|{d}%} ',
  85. rich: {}
  86. }
  87. },
  88. // 弹出动画
  89. animationType: 'scale',
  90. animationEasing: 'elasticOut',
  91. animationDelay: function (idx) {
  92. return Math.random() * 200;
  93. }
  94. }]
  95. };
  96. myChart.setOption(option);
  97. window.myChartList.push(myChart);
  98. },
  99. },
  100. created() {
  101. // 刷新所有图标数据
  102. this.$nextTick(function() {
  103. this.f5PieChart();
  104. });
  105. }
  106. }
  107. </script>
  108. <style scoped>
  109. </style>