PieCharts.vue 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <template>
  2. <view class="charts-box">
  3. <qiun-data-charts type="ring" :opts="opts" :chartData="chartData" />
  4. </view>
  5. </template>
  6. <script>
  7. export default {
  8. data() {
  9. return {
  10. chartData: {},
  11. //您可以通过修改 config-ucharts.js 文件中下标为 ['ring'] 的节点来配置全局默认参数,如都是默认参数,此处可以不传 opts 。实际应用过程中 opts 只需传入与全局默认参数中不一致的【某一个属性】即可实现同类型的图表显示不同的样式,达到页面简洁的需求。
  12. opts: {
  13. rotate: false,
  14. rotateLock: false,
  15. color: ['#1372FF', '#F89F2A', '#02C493'],
  16. padding: [10, 15, 15, 10],
  17. dataLabel: true,
  18. enableScroll: false,
  19. legend: {
  20. show: true,
  21. position: "bottom",
  22. lineHeight: 25
  23. },
  24. title: {
  25. name: "",
  26. fontSize: 15,
  27. color: "#666666"
  28. },
  29. subtitle: {
  30. name: "",
  31. fontSize: 25,
  32. color: "#7cb5ec"
  33. },
  34. extra: {
  35. ring: {
  36. ringWidth: 35,
  37. activeOpacity: 0.5,
  38. activeRadius: 10,
  39. offsetAngle: 0,
  40. labelWidth: 10,
  41. border: false,
  42. borderWidth: 3,
  43. borderColor: "#FFFFFF"
  44. }
  45. },
  46. }
  47. };
  48. },
  49. onReady() {
  50. this.getServerData();
  51. },
  52. methods: {
  53. getServerData() {
  54. //模拟从服务器获取数据时的延时
  55. setTimeout(() => {
  56. //模拟服务器返回数据,如果数据格式和标准格式不同,需自行按下面的格式拼接
  57. let res = {
  58. series: [{
  59. data: [{
  60. "name": "房费",
  61. "value": 21964.00,
  62. "labelText": "房费 72%"
  63. },
  64. {
  65. "name": "商品",
  66. "value": 6514.00,
  67. "labelText": "商品 21%"
  68. },
  69. {
  70. "name": "其他",
  71. "value": 2514.00,
  72. "labelText": "其他 7%",
  73. },
  74. ],
  75. }]
  76. };
  77. this.chartData = JSON.parse(JSON.stringify(res));
  78. }, 500);
  79. },
  80. }
  81. };
  82. </script>
  83. <style scoped>
  84. /* 请根据实际需求修改父元素尺寸,组件自动识别宽高 */
  85. .charts-box {
  86. width: 95%;
  87. height: 300px;
  88. }
  89. </style>