riskLevelChart.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <template>
  2. <div>
  3. <div id="riskLevelChart" :style="{width:width,height:height}"></div>
  4. </div>
  5. </template>
  6. <script>
  7. import { riskLevelData } from "@/api/process/moc";
  8. export default {
  9. props: {
  10. timeliness: null,
  11. width: {
  12. type: String,
  13. default: '100%'
  14. },
  15. height: {
  16. type: String,
  17. default: '200px'
  18. },
  19. },
  20. data() {
  21. return {
  22. option: {
  23. title: {
  24. left: 'center'
  25. },
  26. tooltip: {
  27. trigger: 'item',
  28. formatter: '{a} <br/>{b} : {c} ({d}%)'
  29. },
  30. legend: {
  31. orient: 'vertical',
  32. left: 'left',
  33. data: []
  34. },
  35. toolbox: {
  36. show: true,
  37. feature: {
  38. mark: {show: true},
  39. magicType: {
  40. show: true,
  41. type: ['pie', 'funnel']
  42. },
  43. restore: {show: true},
  44. saveAsImage: {show: true}
  45. }
  46. },
  47. series: [
  48. {
  49. label: {
  50. formatter: '{b}: ({d}%)'
  51. },
  52. name: this.$t('区域'),
  53. type: 'pie',
  54. radius: ['50%', '70%'],
  55. selectedMode: 'single',
  56. data: [
  57. {value: 335, name: this.$t('直接访问')},
  58. ],
  59. emphasis: {
  60. label: {
  61. show: true,
  62. // fontSize: '21',
  63. fontWeight: 'bold'
  64. }
  65. },
  66. }
  67. ]
  68. },
  69. // 查询参数
  70. queryParams: {
  71. timeliness: null,
  72. },
  73. chart: null,
  74. chartData : []
  75. }
  76. },
  77. mounted() {
  78. this.$nextTick(() => {
  79. this.queryParams.timeliness = this.timeliness;
  80. riskLevelData(this.queryParams).then(response => {
  81. this.chartData = response
  82. for(let i = 0 ; i <this.chartData.length ; i++){
  83. this.option.legend.data[i] = this.chartData[i].dataName
  84. this.option.series[0].data[i] = {value:this.chartData[i].dataNum , name: this.chartData[i].dataName }
  85. }
  86. this.initChart()
  87. });
  88. })
  89. },
  90. methods: {
  91. /** 获取当前年份 */
  92. getNowTime() {
  93. var now = new Date();
  94. },
  95. initChart() {
  96. // 基于准备好的dom,初始化echarts实例
  97. this.chart = this.echarts.init(document.getElementById('riskLevelChart'))
  98. this.chart.setOption(this.option)
  99. }
  100. }
  101. }
  102. </script>