ring.vue 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <template>
  2. <div :class="this.id" ref="ringChart">
  3. <canvas :id="this.id"></canvas>
  4. </div>
  5. </template>
  6. <script>
  7. import F2 from "@antv/f2/lib/index-all";
  8. export default {
  9. name: "ring",
  10. props: {
  11. list: {
  12. type: Array,
  13. default: () => []
  14. },
  15. id: {
  16. type: String,
  17. default: ""
  18. }
  19. },
  20. data: function() {
  21. return {};
  22. },
  23. methods: {},
  24. computed: {},
  25. mounted() {
  26. const data = this.list;
  27. let total = 0;
  28. data.forEach(v => {
  29. total += v.amount;
  30. });
  31. const chart = new F2.Chart({
  32. id: this.id,
  33. width: this.$refs.ringChart.offsetWidth,
  34. height: this.$refs.ringChart.offsetWidth * 0.5625,
  35. pixelRatio: window.devicePixelRatio,
  36. padding: [20, 0, 5, 0]
  37. });
  38. chart.source(data);
  39. chart.coord("polar", {
  40. transposed: true,
  41. innerRadius: 0.6,
  42. radius: 0.75
  43. });
  44. chart.axis(false);
  45. chart.legend(false);
  46. chart.tooltip(false);
  47. // 配置文本饼图
  48. chart.pieLabel({
  49. sidePadding: 5,
  50. label1: function label1(data) {
  51. return {
  52. text: data.memo,
  53. fill: "#808080"
  54. };
  55. },
  56. label2: function label2(data) {
  57. return {
  58. fill: "#808080",
  59. text: ((data.amount / total) * 100).toFixed(2) + "%",
  60. fontWeight: 500,
  61. fontSize: 10
  62. };
  63. }
  64. });
  65. chart
  66. .interval()
  67. .position("const*amount")
  68. .color("memo", [
  69. "#1890FF",
  70. "#13C2C2",
  71. "#2FC25B",
  72. "#FACC14",
  73. "#F04864",
  74. "#8543E0",
  75. "#3436C7",
  76. "#223273"
  77. ])
  78. .adjust("stack");
  79. chart.render();
  80. },
  81. beforeDestroy: function() {},
  82. components: {}
  83. };
  84. </script>
  85. <style lang="scss" scoped></style>