com-chart-1.vue 2.2 KB

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