d70633b02b1d9bc9d4a8123e3fa3700fa6402db0.svn-base 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. <!-- -->
  2. <template>
  3. <div>
  4. <el-row>
  5. <div style="width:58vw;height:49vh;" ref="barChart"></div>
  6. </el-row>
  7. </div>
  8. </template>
  9. <script>
  10. //这里可以导入其他文件(比如:组件,工具js,第三方插件js,json文件,图片文件等等)
  11. //例如:import 《组件名称》 from '《组件路径》';
  12. import echarts from 'echarts'
  13. export default {
  14. //import引入的组件需要注入到对象中才能使用
  15. components: {},
  16. props:[],
  17. data() {
  18. //这里存放数据
  19. return {
  20. showTable:false,
  21. tableOrChart:'表格',
  22. radio:'1',
  23. title:'评论点赞TOP 5',
  24. color:['#009688', '#4caf50', '#8bc34a', '#cddc39', '#ffeb3b'],
  25. };
  26. },
  27. //监听属性 类似于data概念
  28. computed: {},
  29. //监控data中的数据变化
  30. watch: {
  31. },
  32. //方法集合
  33. methods: {
  34. changeRadioEvent(item){
  35. if(item == '1'){
  36. this.title = '评论点赞TOP 5';
  37. this.color = ['#009688', '#4caf50', '#8bc34a', '#cddc39', '#ffeb3b'];
  38. this.initChart();
  39. }else{
  40. this.title = '评论吐槽TOP 5';
  41. this.color = ['#ff5722', '#ff9800', '#ffc107', '#ffeb3b', '#cddc39'];
  42. this.initChart();
  43. }
  44. },
  45. initChart:function(){
  46. let _self = this;
  47. let chart = echarts.init(this.$refs['barChart']);
  48. var myColor = this.color;
  49. var chartData = [40,28,18,15,6];
  50. var chartName = ['差旅费异常、专家费、劳务费、招待费、发票异常、先付款、.pdf', '交通费报销2018-11-12月.xlsx', '水利部主机业务申请表-新版.docx', 'ZSFW-01-金水字[2017]01号-关于印发《财务支出审批管理办法》的通知-附件1:财务支出审批管理办法_看图王.pdf-新版.docx','border1.png'];
  51. let option = {
  52. title: {
  53. text: '资料下载量排行',
  54. x: 'center',
  55. top: "20",
  56. textStyle: {
  57. color: '#000',
  58. fontSize: 16
  59. }
  60. },
  61. backgroundColor: '#fff',
  62. grid: {
  63. left: '5%',
  64. right: '5%',
  65. bottom: '5%',
  66. top: '5%',
  67. containLabel: true
  68. },
  69. xAxis: [{
  70. show: false,
  71. },
  72. {
  73. show: false,
  74. }
  75. ],
  76. yAxis: {
  77. type: 'category',
  78. inverse: true,
  79. show: false
  80. },
  81. series: [
  82. //亮色条 百分比
  83. {
  84. show: true,
  85. type: 'bar',
  86. barGap: '-100%',
  87. barWidth: '20%',
  88. z: 2,
  89. itemStyle: {
  90. normal: {
  91. color: function(params) {
  92. var num = myColor.length;
  93. return myColor[params.dataIndex % num]
  94. }
  95. }
  96. },
  97. label: {
  98. normal: {
  99. show: true,
  100. textStyle: {
  101. color: '#000',
  102. fontSize: 12,
  103. fontWeight: 'bold'
  104. },
  105. position: 'right',
  106. formatter: function(data) {
  107. return (chartData[data.dataIndex]);
  108. }
  109. }
  110. },
  111. data: chartData,
  112. },
  113. //年份
  114. {
  115. show: true,
  116. type: 'bar',
  117. xAxisIndex: 1, //代表使用第二个X轴刻度
  118. barGap: '-100%',
  119. barWidth: '10%',
  120. itemStyle: {
  121. normal: {
  122. barBorderRadius: 200,
  123. color: 'transparent'
  124. }
  125. },
  126. label: {
  127. normal: {
  128. show: true,
  129. position: [0, '-20'],
  130. textStyle: {
  131. fontSize:14,
  132. color: '#333',
  133. },
  134. formatter: function(data) {
  135. return chartName[data.dataIndex];
  136. }
  137. }
  138. },
  139. data: chartData
  140. }
  141. ]
  142. };
  143. chart.setOption(option,true);
  144. },
  145. },
  146. //生命周期 - 创建完成(可以访问当前this实例)
  147. created() {
  148. },
  149. //生命周期 - 挂载完成(可以访问DOM元素)
  150. mounted() {
  151. this.initChart();
  152. },
  153. beforeCreate() {}, //生命周期 - 创建之前
  154. beforeMount() {}, //生命周期 - 挂载之前
  155. beforeUpdate() {}, //生命周期 - 更新之前
  156. updated() {}, //生命周期 - 更新之后
  157. beforeDestroy() {}, //生命周期 - 销毁之前
  158. destroyed() {}, //生命周期 - 销毁完成
  159. activated() {}, //如果页面有keep-alive缓存功能,这个函数会触发
  160. }
  161. </script>
  162. <style scoped>
  163. </style>