酷炫直播运营系统小程序版本

self-echarts.vue 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <template>
  2. <div class="echarts-wrap">
  3. <mpvue-echarts2 :onInit="onInit" canvasId="demo-canvas" />
  4. </div>
  5. </template>
  6. <script>
  7. import mpvueEcharts2 from './echarts.vue';
  8. import * as echarts from './echarts.min'; /*chart.min.js为在线定制*/
  9. let chart = null;
  10. function initChart(canvas, width, height, canvasDpr) {
  11. chart = echarts.init(canvas, null, {
  12. width: width,
  13. height: height,
  14. canvasDpr: canvasDpr ,// 增加了dpr
  15. devicePixelRatio: canvasDpr // 加上这一行即可解决模糊问题
  16. });
  17. canvas.setChart(chart);
  18. var xArr = ['a','b','c','d'];
  19. var yArr = [12,233,434,545]
  20. var option = {
  21. tooltip: {
  22. trigger: 'axis',
  23. show: true,
  24. formatter: function(params) {
  25. var params = params[0]
  26. var result = "";
  27. result = params.name + ':' + (params.value ? (params.value) : '-') + '\n'
  28. return result;
  29. }
  30. },
  31. grid: {
  32. left: "1%",
  33. right: "2%",
  34. bottom: "1%",
  35. containLabel: true
  36. },
  37. legend: {
  38. show: true,
  39. textStyle: {
  40. color: '#000'
  41. }
  42. },
  43. xAxis: [{
  44. type: "category",
  45. data: xArr,
  46. axisLine: {
  47. lineStyle: {
  48. color: '#89899C'
  49. }
  50. },
  51. axisTick: {
  52. show: false
  53. },
  54. splitLine: {
  55. show: false
  56. },
  57. axisLabel: {
  58. color: '#89899C',
  59. fontSize: 10,
  60. rotate: 30,
  61. },
  62. }],
  63. yAxis: [{
  64. type: "value",
  65. name: "个数",
  66. axisLine: {
  67. lineStyle: {
  68. color: '#89899C'
  69. }
  70. },
  71. max: yArr.length == 0 ? 100000 : 'dataMax',
  72. min: function(value) {
  73. return value.min <= 0 ? value.min : 0;
  74. },
  75. axisTick: {
  76. show: false
  77. },
  78. splitLine: {
  79. lineStyle: {
  80. color: "#89899C",
  81. type: "dashed"
  82. }
  83. },
  84. nameTextStyle: {
  85. color: "#89899C",
  86. fontSize: 14,
  87. padding: [0, 1, 0, 0]
  88. },
  89. axisLabel: {
  90. color: '#89899C',
  91. fontSize: 13,
  92. // formatter: function(params) {
  93. // var result = params;
  94. // return app.func.NumberHandle(result);
  95. // }
  96. }
  97. }],
  98. series: [{
  99. type: "bar",
  100. name: '作品获赞分布',
  101. barWidth: (100 / xArr.length) > 10 ? 10 : (100 / xArr.length),
  102. yAxisIndex: 0,
  103. barGap: 0,
  104. data: yArr,
  105. itemStyle: {
  106. color: "#2562FF",
  107. barBorderRadius: [4, 4, 4, 4],
  108. borderType: "dotted"
  109. }
  110. }]
  111. };
  112. chart.setOption(option,true);
  113. return chart; // 返回 chart 后可以自动绑定触摸操作
  114. }
  115. export default {
  116. components: {
  117. mpvueEcharts2
  118. },
  119. data() {
  120. return {
  121. onInit: initChart
  122. }
  123. }
  124. }
  125. </script>
  126. <style scoped>
  127. .echarts-wrap {
  128. width: 100%;
  129. height: 400rpx;
  130. }
  131. </style>