index.vue 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <template>
  2. <div class="component">
  3. <h6 class="title">{{data.title}}</h6>
  4. <div :id="'pieDiagram' + index" ref="box"></div>
  5. </div>
  6. </template>
  7. <script>
  8. import G2 from '@antv/g2'
  9. export default {
  10. name: '',
  11. props: ['data', 'index'],
  12. data () {
  13. return {
  14. }
  15. },
  16. components: {
  17. G2,
  18. },
  19. mounted () {
  20. this.$nextTick(function () {
  21. this.init()
  22. })
  23. },
  24. methods: {
  25. init () {
  26. var _that = this
  27. var chart = new G2.Chart({
  28. container: 'pieDiagram' + _that.index,
  29. forceFit: true,
  30. width: _that.$refs.box.clientWidth,
  31. height: 400
  32. })
  33. chart.source(_that.data.list, {
  34. percent: {
  35. formatter: function formatter (val) {
  36. val = val * 100 + '%'
  37. return val
  38. }
  39. }
  40. })
  41. chart.coord('theta', {
  42. radius: 0.75
  43. })
  44. chart.tooltip({
  45. showTitle: false,
  46. itemTpl: '<li><span style="background-color:{color}" class="g2-tooltip-marker"></span>{name}: {value}</li>'
  47. })
  48. chart.intervalStack().position('percent').color('item').label('percent', {
  49. formatter: (val, item) => {
  50. return item.point.item + ': ' + val
  51. }
  52. }).tooltip('item*percent', function (item, percent) {
  53. percent = percent * 100 + '%'
  54. return {
  55. name: item,
  56. value: percent
  57. }
  58. }).style({
  59. lineWidth: 1,
  60. stroke: '#fff'
  61. })
  62. chart.render()
  63. },
  64. }
  65. }
  66. </script>
  67. <!-- Add "scoped" attribute to limit CSS to this component only -->
  68. <style lang="scss" scoped>
  69. @import "page.scss";
  70. </style>