fix:优化K线图的数据配置

main
liu.shiyi 9 months ago
parent 951183b47b
commit b4dc142e75

@ -36,7 +36,9 @@ export default {
charts: null,
hasData: false,
level: '',
option: {}
option: {},
xData: [],
yData: []
}
},
computed: {
@ -78,7 +80,7 @@ export default {
// changeStylekey,chart
this.changeData(config).then((res) => {
//
this.newChart(res)
this.newChart(config)
})
}
},
@ -88,43 +90,26 @@ export default {
* @param {*} config
* @param {Array} data
*/
dataFormatting (config, data) {
const dataList = []
data?.data?.forEach(item => {
dataList.push({
name: item[config.customize.name],
value: [item[config.customize.xaxis], item[config.customize.yaxis], item[config.customize.value]],
//
originData: item
})
})
config.option = {
...config.option,
data: dataList
dataFormatting (config, _data) {
console.log('dataFormatting', _data)
const data = _data?.data
if (data && data.length) {
this.xData = data.map(item => item[config.dataSource.x])
this.yData = data.map(item => [item[config.dataSource.openField], item[config.dataSource.closeField], item[config.dataSource.lowField], item[config.dataSource.highField]])
} else {
this.xData = ['2017-10-24', '2017-10-25', '2017-10-26', '2017-10-27']
this.yData = [
[20, 34, 10, 38],
[40, 35, 30, 50],
[31, 38, 33, 44],
[38, 15, 5, 42]
]
}
return config
},
/**
* 返回上一级
* @param {*} config
*/
async backToPreviousLevel (config) {
this.currentDeep--
const map = this.mapList[this.currentDeep]
// mapList
this.mapList.pop()
const mapData = JSON.parse(map.geoJson)
this.option.geo.map = map.name
// this.changeData({...config, customize: {...config.customize, level: map.level, scope: map.name}})
echarts.registerMap(map.name, mapData)
this.charts.setOption(this.option, true)
},
/**
* 修改地图数据
* @param {Array} data
*/
changeMapData (data) {
this.option.series[0].data = data
//
updateChartData (config) {
this.handleOption(config)
this.charts.setOption(this.option)
},
/**
@ -139,8 +124,6 @@ export default {
// optionechartsoption
this.handleOption(config)
this.charts.setOption(this.option)
//
this.registerClickEvent(config)
},
/**
* 处理配置项option
@ -149,68 +132,16 @@ export default {
handleOption (config) {
this.option = {
xAxis: {
data: ['2017-10-24', '2017-10-25', '2017-10-26', '2017-10-27']
data: this.xData
},
yAxis: {},
series: [
{
type: 'candlestick',
data: [
[20, 34, 10, 38],
[40, 35, 30, 50],
[31, 38, 33, 44],
[38, 15, 5, 42]
]
data: this.yData
}
]
}
},
/**
* 注册点击事件
* @param config 地图组件配置项
*/
registerClickEvent (config) {
this.charts.on('click', async (params) => {
const data = params?.data?.originData
if (data) {
this.linkage({ ...data, clickAreaName: params.name })
} else {
this.linkage({ clickAreaName: params.name })
}
if (params.name == '') return
if (!config.customize.down) {
return
}
//
if (this.currentDeep >= config.customize.downLevel) return
const downMapUrl = `${window.BS_CONFIG?.httpConfigs?.baseURL}/bigScreen/map/data/${this.mapList[this.currentDeep].id}/${params.name}`
const downMap = await this.$dataRoomAxios.get(decodeURI(downMapUrl), {}, false)
//
if (downMap.available !== 1) {
this.$message({
message: '未找到该地图配置',
type: 'warning'
})
return
}
let geoJsonObj
try {
geoJsonObj = JSON.parse(downMap.geoJson)
} catch (error) {
this.$message({
message: params.name + '地图数据格式错误',
type: 'warning'
})
return
}
this.currentDeep++
this.mapList.push(downMap)
// this.changeData({...config, customize: {...config.customize, scope: params.name}})
this.option.geo.map = params.name
echarts.registerMap(params.name, geoJsonObj)
this.charts.setOption(this.option, true)
})
}
}

@ -3,7 +3,7 @@ import Icon from 'data-room-ui/assets/images/bigScreenIcon/export'
import cloneDeep from 'lodash/cloneDeep'
export const settingConfig = {
padding: [30, 30, 50, 80],
padding: [0, 30, 50, 80],
legend: false,
isGroup: true,
data: [],
@ -16,21 +16,6 @@ export const settingConfig = {
},
headerField: {
enable: false
},
mapField: {
enable: true
},
metricField: {
// 指标
label: '维度',
enable: false,
multiple: false // 是否多选
},
dimensionField: {
// 表格列
label: '展示字段', // 维度/查询字段
enable: false,
multiple: false // 是否多选
}
}
}
@ -131,8 +116,8 @@ export const candlestickData = {
border: { type: '', titleHeight: 60, fontSize: 16, isTitle: true, padding: [0, 0, 0, 0] },
className:
'com.gccloud.dataroom.core.module.chart.components.ScreenMapChart',
w: 800,
h: 700,
w: 450,
h: 320,
x: 0,
y: 0,
type: 'candlestick',
@ -141,5 +126,13 @@ export const candlestickData = {
},
setting: undefined, // 右侧面板自定义配置
dataHandler: {}, // 数据自定义处理js脚本
...cloneDeep(dataConfig)
...cloneDeep(dataConfig),
dataSource: {
...cloneDeep(dataConfig.dataSource),
xField: '',
openField: '',
closeField: '',
lowField: '',
highField: ''
}
}

@ -120,7 +120,7 @@
</div>
</div>
<!-- 基础组件数据配置 -->
<template v-if="!['customComponent', 'remoteComponent','echartsComponent'].includes(config.type)">
<template v-if="!['customComponent', 'remoteComponent','echartsComponent','candlestick'].includes(config.type)">
<!--维度多选-->
<el-form-item
v-if="config.option.displayOption.dimensionField.enable"
@ -213,6 +213,41 @@
</el-select>
</el-form-item>
</template>
<!-- K线图数据配置 -->
<template v-if="config.type === 'candlestick'">
<el-form-item
v-for="(fieldItem, i) in fieldNameMapping"
:key="i"
prop="dataSource.xField"
class="data-form-item"
:label="fieldItem.desc"
>
<el-select
v-model="config.dataSource[fieldItem.name]"
:multiple="fieldItem.multiple"
class="bs-el-select"
popper-class="bs-el-select"
filterable
clearable
>
<el-option
v-for="(field, index) in dataSourceDataList"
:key="index"
:label="field.comment"
:value="field.name"
>
<div class="source-key-option">
<div>
{{ field.comment !== "" ? field.comment : field.name }}
</div>
<div class="option-txt">
{{ field.name }}
</div>
</div>
</el-option>
</el-select>
</el-form-item>
</template>
<!-- g2plot和远程组件数据配置 -->
<template v-else>
<template
@ -890,6 +925,33 @@ export default {
},
data () {
return {
fieldNameMapping: [ // k线
{
name: 'xField',
desc: 'X轴',
multiple: false
},
{
name: 'openField',
desc: '开盘价',
multiple: false
},
{
name: 'closeField',
desc: '收盘价',
multiple: false
},
{
name: 'lowField',
desc: '最低价',
multiple: false
},
{
name: 'highField',
desc: '最高价',
multiple: false
}
],
fieldsList: [],
params: [], //
datasetName: '',

@ -264,8 +264,9 @@ export default {
} else {
this.chart.changeData(config.option.data)
}
}
if (this.charts) {
} if (this.config.type === 'candlestick' && this.charts) {
this.updateChartData(config, _res)
} else if (this.charts) {
// 地图组件的被联动更新
this.changeMapData(config.option.data)
}
@ -278,6 +279,10 @@ export default {
resolve(config)
})
})
},
// 更新图表数据
updateChartData () {
},
// http前台代理需要对返回的数据进行重新组装
httpDataFormatting (chartRes, httpRes) {

Loading…
Cancel
Save