PieData.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <template>
  2. <div ref="main" style="width:calc(100% - 0px) ;height:300px;"></div>
  3. </template>
  4. <script>
  5. import * as echarts from "echarts";
  6. export default {
  7. name: 'index',
  8. data() {
  9. return {
  10. }
  11. },
  12. props:{
  13. resultData: {
  14. type: Array,
  15. default:()=> [
  16. { name: '出让', value: 332312.43 },
  17. { name: '划拨', value: 573988.58},
  18. { name: '作价出资', value: 279083.13},
  19. { name: '转让', value: 2119.85 },
  20. ]
  21. },
  22. titleText:{
  23. type:String,
  24. }
  25. },
  26. watch:{
  27. resultData(){
  28. this.$nextTick(function() {
  29. this.getPie()
  30. })
  31. }
  32. },
  33. methods: {
  34. getPie() {
  35. var _this = this
  36. // 绘制图表
  37. var myChart = echarts.init(this.$refs.main)
  38. myChart.on('click',(params)=>{
  39. _this.$emit('visible',{syqsyfs:params.data.name,sfsb:"3"});
  40. console.log(4567,params)
  41. })
  42. // 指定图表的配置项和数据
  43. var option = {
  44. //标题
  45. title: {
  46. text: this.titleText,
  47. x: 'left' , //标题位置
  48. textStyle: { //标题内容的样式
  49. color: '#000',
  50. fontSize: 18 //主题文字字体大小,默认为18px
  51. },
  52. },
  53. // stillShowZeroSum: true,
  54. //鼠标划过时饼状图上显示的数据
  55. tooltip: {
  56. trigger: 'item',
  57. formatter: '{b}:{c} ({d}%)'
  58. },
  59. //图例
  60. legend: {//图例 标注各种颜色代表的模块
  61. // orient: 'vertical',//图例的显示方式 默认横向显示
  62. type:'scroll', //图例滚动效果
  63. bottom: 10,//控制图例出现的距离 默认左上角
  64. // itemWidth: 16,//图例颜色块的宽度和高度
  65. // itemHeight: 12,
  66. textStyle: {//图例中文字的样式
  67. color: '#000',
  68. fontSize: 13
  69. },
  70. // data: ['出让', '划拨', '作价出资','授权经营','转让','其他']//图例上显示的饼图各模块上的名字
  71. },
  72. //饼图中各模块的颜色
  73. color: ['#37a2da','#32c5e9','#9fe6b8','#ffdb5c','#ff9f7f','#fb7293','#e7bcf3','#8378ea'],
  74. // 饼图数据
  75. series: {
  76. // name: 'bug分布',
  77. type: 'pie', //echarts图的类型 pie代表饼图
  78. radius: '50%', //饼图中饼状部分的大小所占整个父元素的百分比
  79. center: ['50%', '50%'], //整个饼图在整个父元素中的位置
  80. // data:'' //饼图数据
  81. data: this.resultData,
  82. label:{
  83. normal : {
  84. formatter: '{b}:\n({d}%)',
  85. textStyle : {
  86. fontWeight : 'normal',
  87. fontSize : 13
  88. }
  89. }
  90. },
  91. itemStyle: {
  92. normal: {
  93. label: {
  94. show: true,//饼图上是否出现标注文字 标注各模块代表什么 默认是true
  95. // position: 'inner',//控制饼图上标注文字相对于饼图的位置 默认位置在饼图外
  96. },
  97. labelLine: {
  98. show: true//官网demo里外部标注上的小细线的显示隐藏 默认显示
  99. }
  100. }
  101. },
  102. }
  103. }
  104. // 使用刚指定的配置项和数据显示图表。
  105. myChart.setOption(option);
  106. myChart.resize();
  107. }
  108. }
  109. }
  110. </script>
  111. <style scoped>
  112. </style>