index.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <template>
  2. <div :id="id" :style="{ width: width, height: height }"></div>
  3. </template>
  4. <script>
  5. import { chartOptionMixins } from "@/views/analyse/custom/mixins";
  6. import { random } from "@/utils";
  7. export default {
  8. mixins: [chartOptionMixins],
  9. name: "CScatter",
  10. data() {
  11. return {
  12. id: 'scatter',
  13. size: 0,
  14. }
  15. },
  16. mounted() {
  17. },
  18. methods: {
  19. getOption() {
  20. if (this.form.schema.x.ptype === 2) {
  21. this.dateTimeSort()
  22. }
  23. let data = [], x = ['', ...this.selected.x, ''], y = ['', ...this.selected.y, '']
  24. for (let i = 0; i < x.length; i++) {
  25. for (let j = 0; j < y.length; j++) {
  26. if (x[i] && y[j]) {
  27. data.push([i, j, this.getDataCount(x[i], y[j])])
  28. }
  29. }
  30. }
  31. const symbolSize = this.getSymbolSize(data)
  32. return {
  33. grid: {
  34. top: this.form.setting.gridTop + '%',
  35. left: this.form.setting.gridLeft + '%',
  36. right: this.form.setting.gridRight + '%',
  37. bottom: this.form.setting.gridBottom + '%',
  38. containLabel: true
  39. },
  40. xAxis: [
  41. {
  42. type: 'category',
  43. boundaryGap: false,
  44. name: this.form.setting.title1,
  45. nameTextStyle: this.getNameTextStyle('x'),
  46. nameLocation: this.form.setting.nameLocation,
  47. scale: true,
  48. data: x,
  49. axisLabel: this.getAxisLabel('category', 'x'),
  50. splitLine: {
  51. show: this.form.setting.splitLine
  52. }
  53. }
  54. ],
  55. yAxis: [
  56. {
  57. type: 'category',
  58. boundaryGap: false,
  59. name: this.form.setting.title2,
  60. nameTextStyle: this.getNameTextStyle('y'),
  61. nameLocation: this.form.setting.nameLocation2,
  62. scale: true,
  63. data: y,
  64. axisLabel: this.getAxisLabel('category', 'y'),
  65. splitLine: {
  66. show: this.form.setting.splitLine2
  67. }
  68. }
  69. ],
  70. series: [
  71. {
  72. name: '',
  73. type: 'scatter',
  74. emphasis: {
  75. focus: 'series'
  76. },
  77. symbolSize: (val) => {
  78. return symbolSize[val[2]]
  79. },
  80. itemStyle: {
  81. color: (val) => {
  82. const data = val.value[2]
  83. const color = this.form.setting.config.table.find(item => data >= item.min && data <= item.max)
  84. if (color) {
  85. return color.color
  86. }
  87. return '#5470c6'
  88. }
  89. },
  90. label: this.getDataLabel(),
  91. data: data,
  92. },
  93. ]
  94. }
  95. },
  96. getSymbolSize(dataList) {
  97. const data = dataList.map(item => item[2]).sort((a, b) => {
  98. return b - a
  99. })
  100. const maxVal = data[0]
  101. let symbolSize = {}
  102. data.map(item => {
  103. symbolSize[item] = Math.round(item / maxVal * 100)
  104. })
  105. return symbolSize
  106. }
  107. }
  108. }
  109. </script>