props.ts 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. import type { PropType, ExtractPropTypes } 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. /* 系列相关 */
  53. const series: EChartsOption['series'] = [];
  54. series['bar' as unknown as number] = {
  55. // @ts-ignore
  56. fixedBarWidth: false,
  57. barWidth: 'auto',
  58. barGap: '10%',
  59. barCategoryGap: '20%',
  60. itemStyle: {
  61. borderColor: '#ccc',
  62. borderRadius: 0,
  63. borderWidth: 0,
  64. }
  65. };
  66. const chartOptions = getNormalizedChart({
  67. title: {
  68. text: "柱状图标题",
  69. },
  70. xAxis: {
  71. data: ['轴标签A', '轴标签B', '轴标签C', '轴标签D']
  72. },
  73. series
  74. })
  75. export const defaultPropsValue: EChartsOption = {
  76. // 组件容器默认属性
  77. container: {
  78. props: {
  79. width: 400,
  80. height: 260,
  81. },
  82. },
  83. // 图表默认属性
  84. props: {
  85. // 数据源
  86. dataSource: {
  87. sourceType: DataSourceType.STATIC,
  88. data: {
  89. series: [
  90. {
  91. type: 'bar',
  92. name: '系列1',
  93. data: [10, 30, 20, 40]
  94. },
  95. {
  96. type: 'bar',
  97. name: '系列2',
  98. data: [15, 35, 25, 45]
  99. },
  100. ]
  101. },
  102. url: location.origin + "/mock/api/get/example/bar",
  103. method: "POST",
  104. params: {},
  105. headers: {},
  106. refreshTime: 0,
  107. dataProcess: `
  108. (res) => {
  109. // 取出列表
  110. const data = res.data;
  111. // x轴数据
  112. const xData = data.map((item) => item.name);
  113. // 系列数据
  114. const series = [
  115. { type: 'bar', name: '价格', data: data.map(item => item.price) },
  116. { type: 'bar', name: '总量', data: data.map(item => item.count) },
  117. ];
  118. // 返回图表数据
  119. return { xData, series };
  120. }
  121. `
  122. },
  123. ...chartOptions
  124. },
  125. };
  126. export type BasicBarProps = ExtractPropTypes<typeof basicBarProps>;