index.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. axisLine:{
  69. show:this.form.setting.show2
  70. },
  71. }
  72. ],
  73. series: [
  74. {
  75. name: '',
  76. type: 'scatter',
  77. emphasis: {
  78. focus: 'series'
  79. },
  80. symbolSize: (val) => {
  81. return symbolSize[val[2]]
  82. },
  83. itemStyle: {
  84. color: (val) => {
  85. const data = val.value[2]
  86. const color = this.form.setting.config.table.find(item => data >= item.min && data <= item.max)
  87. if (color) {
  88. return color.color
  89. }
  90. return '#5470c6'
  91. }
  92. },
  93. label: this.getDataLabel(),
  94. data: data,
  95. },
  96. ]
  97. }
  98. },
  99. getSymbolSize(dataList) {
  100. const data = dataList.map(item => item[2]).sort((a, b) => {
  101. return b - a
  102. })
  103. const maxVal = data[0]
  104. let symbolSize = {}
  105. data.map(item => {
  106. symbolSize[item] = Math.round(item / maxVal * 100)
  107. })
  108. return symbolSize
  109. }
  110. }
  111. }
  112. </script>