pieCharts.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <template>
  2. <div class="countryLineChart" ref="countryLineChart"></div>
  3. </template>
  4. <script>
  5. // import * as echarts from "echarts";
  6. // import config from "@/config/index";
  7. import * as echarts from "echarts/core";
  8. import { GaugeChart } from "echarts/charts";
  9. import { TooltipComponent } from "echarts/components";
  10. import { CanvasRenderer } from "echarts/renderers";
  11. echarts.use([CanvasRenderer, TooltipComponent, GaugeChart]);
  12. export default {
  13. name: "countryLineChart",
  14. props: ["list"],
  15. data: function() {
  16. return {
  17. leftList: [],
  18. rightList: [],
  19. chart: undefined,
  20. };
  21. },
  22. filters: {},
  23. watch: {
  24. list() {
  25. this.createChart();
  26. },
  27. },
  28. methods: {
  29. createChart() {
  30. if (!this.$refs.countryLineChart) return;
  31. if (!this.chart) {
  32. this.chart = echarts.init(this.$refs.countryLineChart);
  33. this.chart.resize({
  34. height: (this.$refs.countryLineChart.offsetWidth * 6) / 16,
  35. });
  36. }
  37. var option = {
  38. series: this.list.map((v, i) => {
  39. let y = i < 5 ? 25 : 75;
  40. return {
  41. type: "gauge",
  42. startAngle: 90,
  43. endAngle: -270,
  44. center: [((10 + i * 20) % 100) + "%", y + "%"],
  45. pointer: {
  46. show: false,
  47. },
  48. progress: {
  49. show: true,
  50. overlap: false,
  51. roundCap: true,
  52. clip: false,
  53. itemStyle: {
  54. borderWidth: 0,
  55. },
  56. },
  57. axisLine: {
  58. lineStyle: {
  59. width: 10,
  60. },
  61. },
  62. splitLine: {
  63. show: false,
  64. distance: 0,
  65. length: 5,
  66. },
  67. axisTick: {
  68. show: false,
  69. },
  70. axisLabel: {
  71. show: false,
  72. distance: 50,
  73. },
  74. radius: "40%",
  75. data: [
  76. {
  77. value: (v.score * 100).toFixed(2) - 0,
  78. name: v.name,
  79. title: {
  80. offsetCenter: ["0%", "-15%"],
  81. width: 100,
  82. overflow: 'truncate'
  83. },
  84. detail: {
  85. valueAnimation: true,
  86. offsetCenter: ["0%", "15%"],
  87. },
  88. },
  89. ],
  90. title: {
  91. fontSize: 14,
  92. },
  93. detail: {
  94. width: 20,
  95. height: 14,
  96. fontSize: 14,
  97. color: "inherit",
  98. borderWidth: 0,
  99. formatter: "{value}%",
  100. },
  101. };
  102. }),
  103. };
  104. option && this.chart.setOption(option);
  105. },
  106. },
  107. mounted() {
  108. this.createChart();
  109. },
  110. beforeUnmount: function() {
  111. this.chart.dispose();
  112. },
  113. components: {},
  114. };
  115. </script>
  116. <style></style>