props.ts 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. import { type PropType } from "vue";
  2. import { EChartsOption } from "echarts";
  3. import { getNormalizedChart, dataSource } from "../../../utils";
  4. import { DataSourceType } from "../../../chartEnum";
  5. export const basicBarProps = {
  6. width: {
  7. type: Number as PropType<number>,
  8. default: 400,
  9. },
  10. height: {
  11. type: Number as PropType<number>,
  12. default: 260,
  13. },
  14. dataSource,
  15. // 标题
  16. title: {
  17. type: Object as PropType<EChartsOption["title"]>,
  18. },
  19. // 图例
  20. legend: {
  21. type: Object as PropType<EChartsOption["legend"]>,
  22. },
  23. // 背景
  24. backgroundColor: {
  25. type: String as PropType<string>,
  26. },
  27. // 边框
  28. grid: {
  29. type: Object as PropType<EChartsOption["grid"]>,
  30. },
  31. // 提示框
  32. tooltip: {
  33. type: Object as PropType<EChartsOption["tooltip"]>,
  34. },
  35. // x轴数据
  36. xAxis: {
  37. type: Object as PropType<EChartsOption["xAxis"]>,
  38. },
  39. // y轴数据
  40. yAxis: {
  41. type: Object as PropType<EChartsOption["yAxis"]>,
  42. },
  43. // 折线
  44. series: {
  45. type: Array as PropType<EChartsOption["series"]>,
  46. },
  47. // color
  48. color: {
  49. type: Object as PropType<EChartsOption["color"]>
  50. }
  51. };
  52. const chartOptions = getNormalizedChart({
  53. title: {
  54. text: "柱状图标题",
  55. },
  56. xAxis: {
  57. data: ['轴标签A', '轴标签B', '轴标签C', '轴标签D']
  58. },
  59. })
  60. export const defaultPropsValue: EChartsOption = {
  61. // 组件容器默认属性
  62. container: {
  63. props: {
  64. width: 400,
  65. height: 260,
  66. },
  67. },
  68. // 图表默认属性
  69. props: {
  70. // 数据源
  71. dataSource: {
  72. sourceType: DataSourceType.STATIC,
  73. data: {
  74. xData: ['轴标签A', '轴标签B', '轴标签C', '轴标签D'],
  75. series: [
  76. {
  77. type: 'bar',
  78. name: '系列1',
  79. data: [89.3, 92.1, 94.4, 85.4]
  80. },
  81. {
  82. type: 'bar',
  83. name: '系列2',
  84. data: [95.8, 89.4, 91.2, 76.9]
  85. },
  86. ]
  87. },
  88. url: location.origin + "/mock/api/get/example/bar",
  89. method: "POST",
  90. params: {},
  91. headers: {},
  92. refreshTime: 0,
  93. dataProcess: `
  94. (res) => {
  95. // 取出列表
  96. const data = res.data;
  97. // x轴数据
  98. const xData = data.map((item) => item.name);
  99. // 系列数据
  100. const series = [
  101. { type: 'bar', name: '价格', data: data.map(item => item.price) },
  102. { type: 'bar', name: '总量', data: data.map(item => item.count) },
  103. ];
  104. // 返回图表数据
  105. return { xData, series };
  106. }
  107. `
  108. },
  109. ...chartOptions
  110. },
  111. };