|
@@ -2,13 +2,13 @@
|
|
<div class="heightFull widthFull d-flex">
|
|
<div class="heightFull widthFull d-flex">
|
|
<HomeSide @update="onUpdate"></HomeSide>
|
|
<HomeSide @update="onUpdate"></HomeSide>
|
|
<div class="d-flex chart heightFull widthFull pa-3">
|
|
<div class="d-flex chart heightFull widthFull pa-3">
|
|
- <div v-if="showChart" class="chart-list heightFull overflow-y-auto mr-3">
|
|
|
|
- <div v-for="(chart, key) in Charts" :key="key" class="chart-type mb-3" @click="onChange(key)">
|
|
|
|
|
|
+ <div class="chart-list heightFull overflow-y-auto mr-3">
|
|
|
|
+ <div v-for="item in items" :key="item.key" class="chart-type mb-3" @click="onChange(item.key)">
|
|
<div>
|
|
<div>
|
|
- <span class="mdi" :class="chart.icon"></span>
|
|
|
|
|
|
+ <span class="mdi" :class="item.icon"></span>
|
|
</div>
|
|
</div>
|
|
<div>
|
|
<div>
|
|
- {{ chart.title }}
|
|
|
|
|
|
+ {{ item.title }}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
@@ -72,6 +72,16 @@ export default {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
},
|
|
},
|
|
|
|
+ computed: {
|
|
|
|
+ items () {
|
|
|
|
+ return Object.keys(Charts).map(key => {
|
|
|
|
+ return {
|
|
|
|
+ key,
|
|
|
|
+ ...Charts[key]
|
|
|
|
+ }
|
|
|
|
+ }).sort((a, b) => a.sort - b.sort)
|
|
|
|
+ }
|
|
|
|
+ },
|
|
methods: {
|
|
methods: {
|
|
onClose () {
|
|
onClose () {
|
|
this.showChart = false
|
|
this.showChart = false
|
|
@@ -93,25 +103,49 @@ export default {
|
|
this.setData()
|
|
this.setData()
|
|
})
|
|
})
|
|
},
|
|
},
|
|
|
|
+ dataAlready (key, data = [[]], config) {
|
|
|
|
+ switch (key) {
|
|
|
|
+ case 'pie':
|
|
|
|
+ return {
|
|
|
|
+ data: data.map(e => e.map((_e, i) => {
|
|
|
|
+ return {
|
|
|
|
+ value: _e,
|
|
|
|
+ name: config.xAxisData[i] ?? _e
|
|
|
|
+ }
|
|
|
|
+ }))
|
|
|
|
+ }
|
|
|
|
+ case 'radar': {
|
|
|
|
+ const _data = data.map(arr => {
|
|
|
|
+ // 按类型轴分组
|
|
|
|
+ const _map = new Map()
|
|
|
|
+ arr.forEach((e, i) => {
|
|
|
|
+ if (_map.has(config.xAxisData[i])) {
|
|
|
|
+ _map.get(config.xAxisData[i]).push(e)
|
|
|
|
+ } else {
|
|
|
|
+ _map.set(config.xAxisData[i], [e])
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ return Array.from(_map, ([name, value]) => ({ name, value }))
|
|
|
|
+ })
|
|
|
|
+ return {
|
|
|
|
+ data: _data,
|
|
|
|
+ radar: {
|
|
|
|
+ indicator: config.xAxisData.map((e, i) => ({ name: e, max: Math.max(...data.map(_d => _d[i])) }))
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ default:
|
|
|
|
+ return { data }
|
|
|
|
+ }
|
|
|
|
+ },
|
|
setData () {
|
|
setData () {
|
|
const { data, key, config } = this.chartsOpt
|
|
const { data, key, config } = this.chartsOpt
|
|
this.chart.showLoading()
|
|
this.chart.showLoading()
|
|
// 根据key值处理data
|
|
// 根据key值处理data
|
|
const _option = cloneDeep(Charts[key].option)
|
|
const _option = cloneDeep(Charts[key].option)
|
|
const series = _option.series
|
|
const series = _option.series
|
|
- const _data = []
|
|
|
|
- if (key === 'pie') {
|
|
|
|
- (data || [[]]).forEach(e => {
|
|
|
|
- _data.push(e.map((_e, i) => {
|
|
|
|
- return {
|
|
|
|
- value: _e,
|
|
|
|
- name: config.xAxisData[i] ?? _e
|
|
|
|
- }
|
|
|
|
- }))
|
|
|
|
- })
|
|
|
|
- } else {
|
|
|
|
- _data.push(...data)
|
|
|
|
- }
|
|
|
|
|
|
+ const { data: _data, radar } = this.dataAlready(key, data, config)
|
|
|
|
+ console.log(_data)
|
|
const _tem = series[0]
|
|
const _tem = series[0]
|
|
const { data: dataSource, ...opt } = _tem
|
|
const { data: dataSource, ...opt } = _tem
|
|
data.forEach((d, i) => {
|
|
data.forEach((d, i) => {
|
|
@@ -123,6 +157,9 @@ export default {
|
|
if (_option.xAxis?.data) {
|
|
if (_option.xAxis?.data) {
|
|
_option.xAxis.data = config?.xAxisData ?? data[0].map((e, i) => i)
|
|
_option.xAxis.data = config?.xAxisData ?? data[0].map((e, i) => i)
|
|
}
|
|
}
|
|
|
|
+ if (_option.radar) {
|
|
|
|
+ _option.radar = radar
|
|
|
|
+ }
|
|
this.chart.setOption(_option, true)
|
|
this.chart.setOption(_option, true)
|
|
this.chart.hideLoading()
|
|
this.chart.hideLoading()
|
|
},
|
|
},
|