chart.vue 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <template>
  2. <view class="charts-box">
  3. <qiun-data-charts type="funnel" :opts="opts" :chartData="chartData" />
  4. </view>
  5. </template>
  6. <script>
  7. import {
  8. getcourseRate
  9. } from "@/api/courseManage.js"
  10. export default {
  11. props: {
  12. getratelist: {
  13. type: Object,
  14. default: () => ([{
  15. name: '掌声',
  16. value: 10
  17. }])
  18. }
  19. },
  20. data() {
  21. return {
  22. chartData: {},
  23. //您可以通过修改 config-ucharts.js 文件中下标为 ['funnel'] 的节点来配置全局默认参数,如都是默认参数,此处可以不传 opts 。实际应用过程中 opts 只需传入与全局默认参数中不一致的【某一个属性】即可实现同类型的图表显示不同的样式,达到页面简洁的需求。
  24. opts: {
  25. color: ["#1890FF", "#91CB74", "#FAC858", "#EE6666", "#73C0DE", "#3CA272", "#FC8452", "#9A60B4",
  26. "#ea7ccc"
  27. ],
  28. padding: [15, 15, 0, 15],
  29. enableScroll: false,
  30. extra: {
  31. funnel: {
  32. activeOpacity: 0.3,
  33. activeWidth: 10,
  34. border: true,
  35. borderWidth: 2,
  36. borderColor: "#FFFFFF",
  37. fillOpacity: 1,
  38. labelAlign: "right"
  39. }
  40. },
  41. }
  42. };
  43. },
  44. mounted() {
  45. this.getServerData();
  46. },
  47. methods: {
  48. getServerData() {
  49. //模拟从服务器获取数据时的延时
  50. setTimeout(() => {
  51. // 模拟服务器返回数据,如果数据格式和标准格式不同,需自行按下面的格式拼接
  52. this.chartData = {
  53. series: [{
  54. name: '流量',
  55. data: this.getratelist.data.map(item => {
  56. return {
  57. name: item.name,
  58. value: item.value,
  59. centerText: item.value,
  60. };
  61. })
  62. // data: [{
  63. // "name": "一班",
  64. // "centerText": "50",
  65. // "value": 50
  66. // }, {
  67. // "name": "二班",
  68. // "centerText": "30",
  69. // "value": 30
  70. // }, {
  71. // "name": "三班",
  72. // "centerText": "20",
  73. // "value": 20
  74. // }, {
  75. // "name": "四班",
  76. // "centerText": "18",
  77. // "value": 0
  78. // }, {
  79. // "name": "五班",
  80. // "centerText": "8",
  81. // "value": 0
  82. // }]
  83. }]
  84. };
  85. console.log(this.chartData)
  86. // this.chartData = JSON.parse(JSON.stringify(this.getratelist));
  87. }, 500);
  88. },
  89. }
  90. };
  91. </script>
  92. <style scoped>
  93. /* 请根据实际需求修改父元素尺寸,组件自动识别宽高 */
  94. .charts-box {
  95. width: 100%;
  96. height: 300px;
  97. }
  98. </style>