bubble.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. <template>
  2. <div :id="id" style="height: 100%;width:100%;"></div>
  3. </template>
  4. <script>
  5. export default {
  6. data () {
  7. return {
  8. mychat: '',
  9. total: 0,
  10. heightlightIndex: 0,
  11. }
  12. },
  13. props:{
  14. id:{
  15. type: String
  16. },
  17. // pieData:{
  18. // type: Array,
  19. // default: function(){
  20. // return [
  21. // {value:335, name:'新增檔案'},
  22. // {value:310, name:'書面問答'},
  23. // {value:234, name:'匯入.pptx'},
  24. // {value:135, name:'PowerClick'},
  25. // {value:1548, name:'開啟.hte'},
  26. // {value:123, name:'其他'},
  27. // ]
  28. // },
  29. // },
  30. title:{
  31. type: String
  32. },
  33. ylabel:{
  34. type: Array,
  35. default: function(){
  36. return ['一年級', '二年級', '三年級','四年級','五年級'];
  37. }
  38. },
  39. bubleData:{
  40. type: Array,
  41. default: function(){
  42. // [x, y, total]
  43. return [
  44. [0,0,10], [1,0, 30], [4,0, 20], [5,0, 10],
  45. [1,1,30], [2,1, 30],
  46. [3,2,30], [4,2, 10],
  47. [2,3,30]];
  48. }
  49. }
  50. },
  51. mounted(){
  52. this.drawLine();
  53. },
  54. created(){
  55. },
  56. methods:{
  57. drawLine(){
  58. let _this = this
  59. var bubblecolor = ['#FF6B6A', '#FF9FF4', '#48DBFC', '#1CD0A1', '#FDC958', '#FFAD76'];
  60. var hours = ['0-50', '51-60', '61-70', '71-80', '81-80', '90~'];
  61. // data = data.map(function (item) {
  62. // return [item[1], item[0], item[2]];
  63. // });
  64. // console.log(data)
  65. // 基于准备好的dom,初始化echarts实例
  66. this.myChart = this.$echarts.init(document.getElementById(this.id));
  67. this.myChart.setOption({
  68. title:{
  69. show: _this.title ? true : false,
  70. text: _this.title ? _this.title : '',
  71. left: 'center',
  72. textStyle:{
  73. color: '#fafafa',
  74. fontWeight: 100,
  75. }
  76. },
  77. tooltip: {
  78. position: 'top',
  79. formatter: function (params) {
  80. return _this.ylabel[params.value[1]] + '裡,'+ hours[params.value[0]] + '區間的一共有'+params.value[2] + '人';
  81. }
  82. },
  83. grid: {
  84. left: '2%',
  85. bottom: 0,
  86. right: '16px',
  87. containLabel: true,
  88. },
  89. xAxis: {
  90. type: 'category',
  91. data: hours,
  92. boundaryGap: false,
  93. splitLine: {
  94. lineStyle: {
  95. color: 'rgba(185, 193, 173, 0.63)',
  96. },
  97. show: true
  98. },
  99. axisLine: {
  100. lineStyle: {
  101. color: 'rgba(185, 193, 173, 0.63)',
  102. width: 1,
  103. }
  104. },
  105. },
  106. yAxis: {
  107. type: 'category',
  108. data: _this.ylabel,
  109. boundaryGap: true,
  110. splitLine: {
  111. lineStyle: {
  112. color: 'rgba(185, 193, 173, 0.63)',
  113. },
  114. show: true
  115. },
  116. axisLine: {
  117. lineStyle: {
  118. color: 'rgba(185, 193, 173, 0.63)',
  119. width: 1,
  120. }
  121. },
  122. },
  123. series: [{
  124. // name: '论文数量',
  125. type: 'scatter',
  126. symbolSize: function (val) {
  127. let tmp = val[2]*0.03;
  128. if(tmp == 0){
  129. return 0
  130. } else if(tmp<1){
  131. return 10
  132. } else {
  133. return tmp;
  134. }
  135. },
  136. data: _this.bubleData,
  137. animationDelay: function (idx) {
  138. return idx * 5;
  139. },
  140. itemStyle:{
  141. normal:{
  142. color: function(params) {
  143. var num=bubblecolor.length;
  144. return bubblecolor[params.dataIndex%num]
  145. },
  146. }
  147. }
  148. }]
  149. });
  150. },
  151. }
  152. }
  153. </script>
  154. <style>
  155. </style>