healthpieChart.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <template>
  2. <div class="chart" :id="id"></div>
  3. </template>
  4. <script>
  5. import * as echarts from "echarts";
  6. import util from "@/helper/util.js";
  7. export default {
  8. props: {
  9. width: {
  10. type: String,
  11. default: "28.519vh",
  12. },
  13. height: {
  14. type: String,
  15. default: "28.519vh",
  16. },
  17. },
  18. data() {
  19. return {
  20. id: "",
  21. chart: null,
  22. };
  23. },
  24. created() {
  25. this.id = "pie-chart-" + util.newGUID();
  26. },
  27. mounted() {
  28. this.$el.style.width = this.width;
  29. this.$el.style.height = this.height;
  30. this.chart = echarts.init(this.$el);
  31. this.initEcharts();
  32. },
  33. methods: {
  34. initEcharts() {
  35. const option = {
  36. angleAxis: {
  37. type: "category",
  38. data: ["北", "东北", "东", "东南", "南", "西南", "西", "西北"],
  39. },
  40. color: [
  41. {
  42. type: "linear",
  43. x: 0,
  44. y: 0,
  45. x2: 1,
  46. y2: 2,
  47. colorStops: [
  48. {
  49. offset: 0,
  50. color: "red", // 0% 处的颜色
  51. },
  52. {
  53. offset: 1,
  54. color: "blue", // 100% 处的颜色
  55. },
  56. ],
  57. global: false, // 缺省为 false
  58. },
  59. ],
  60. radiusAxis: {},
  61. polar: {},
  62. tooltip: {
  63. trigger: "item",
  64. // formatter: '555'
  65. },
  66. series: [
  67. {
  68. type: "bar",
  69. data: [2, 0.5, 1, 1.2, 1.6, 2, 1, 0.5],
  70. coordinateSystem: "polar",
  71. // name: "[0.0:2.5]",
  72. stack: "a",
  73. emphasis: {
  74. focus: "series",
  75. },
  76. },
  77. ],
  78. textStyle: {
  79. color: "#9a60b4",
  80. fontSize: "19",
  81. fontWeight: 800,
  82. },
  83. // legend: {
  84. // show: false,
  85. // data: [
  86. // "[0.0:2.5]",
  87. // "[2.5:5.0]",
  88. // "[5.0:7.5]",
  89. // "[7.5:10.0]",
  90. // "[10.0:12.5]",
  91. // "[12.5:15.0]",
  92. // "[15.0:17.5]",
  93. // "[17.5:20.0]",
  94. // ],
  95. // // orient: "vertical", //设置显示顺序,默认水平(水平,竖直)
  96. // // x:0, //水平位置
  97. // // y: 70, //竖直位置
  98. // itemGap: 5, // 设置间距
  99. // textStyle: {
  100. // color: "#fff",
  101. // }, //文本样式
  102. // },
  103. };
  104. this.chart.setOption(option); // 渲染页面
  105. },
  106. },
  107. };
  108. </script>
  109. <style lang="less" scoped>
  110. .chart {
  111. width: 100%;
  112. height: 100%;
  113. display: inline-block;
  114. }
  115. </style>