com-chart-1.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <!-- 统计图1 -->
  2. <template>
  3. <div class="echarts-div" id='bar-chart' ref="bar-chart"></div>
  4. </template>
  5. <script>
  6. module.exports = {
  7. data() {
  8. return {}
  9. },
  10. methods: {
  11. // 刷新柱状图
  12. f5BarChart: function () {
  13. // =========================================== 定义数据
  14. var x_name = ''; // new Date().getFullYear() + "年"; // x轴名称
  15. var y_name = "注册数量"; // y轴名称
  16. var dataArray = []; // 坐标X轴数据
  17. var valueArray = []; // 坐标Y轴数据
  18. var arr = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11];
  19. for (var i in arr) {
  20. i = parseInt(i) + 1;
  21. dataArray.push(i + '月');
  22. if (i < 10) {
  23. i = "0" + i;
  24. }
  25. i = i + "";
  26. valueArray.push(sa.randomNum(100, 1000) || 0);
  27. }
  28. // =========================================== 开始渲染
  29. var ele = this.$refs['bar-chart'];
  30. var myChart = echarts.init(ele);
  31. var option = {
  32. tooltip: {
  33. trigger: 'axis',
  34. formatter: '{b}<br/> ' + y_name + ':{c}',
  35. axisPointer: {
  36. type: 'shadow'
  37. }
  38. },
  39. grid: {x: 50, y: 30, x2: 25, y2: 25}, //设置canvas内部表格的内距
  40. toolbox: {
  41. show: true,
  42. top: 0,
  43. feature: {
  44. saveAsImage: {
  45. show: true
  46. }
  47. }
  48. },
  49. xAxis: {
  50. name: x_name,
  51. type: 'category',
  52. // axisLabel: {
  53. // 'interval': 0
  54. // }, //强制不缩略x轴刻度,
  55. data: dataArray
  56. },
  57. yAxis: {
  58. name: y_name,
  59. type: 'value'
  60. },
  61. series: [{
  62. name: y_name,
  63. data: valueArray,
  64. type: 'bar',
  65. label: {
  66. normal: {
  67. show: true,
  68. position: 'top',
  69. formatter: '{c}'
  70. }
  71. },
  72. itemStyle: {
  73. normal: {
  74. color: '#5DB1FF',
  75. label: {
  76. show: true,
  77. textStyle: {
  78. color: 'black'
  79. }
  80. }
  81. }
  82. }
  83. }]
  84. };
  85. myChart.setOption(option);
  86. window.myChartList.push(myChart);
  87. // window.myChartList[0] = myChart;
  88. // myChartList[1] = myChart;
  89. },
  90. },
  91. created() {
  92. // 刷新所有图标数据
  93. this.$nextTick(function () {
  94. this.f5BarChart();
  95. });
  96. }
  97. }
  98. </script>
  99. <style scoped>
  100. </style>