com-chart-2.vue 3.2 KB

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