[issues/613] LineMulti 在数据不对齐时,横坐标计算错误

This commit is contained in:
zhangdaiscott 2023-07-13 18:36:52 +08:00
parent 823ca5e328
commit f563214269
2 changed files with 29 additions and 8 deletions

View File

@ -6,7 +6,7 @@
import { useECharts } from '/@/hooks/web/useECharts'; import { useECharts } from '/@/hooks/web/useECharts';
import { cloneDeep } from 'lodash-es'; import { cloneDeep } from 'lodash-es';
export default defineComponent({ export default defineComponent({
name: 'barMulti', name: 'BarMulti',
props: { props: {
chartData: { chartData: {
type: Array, type: Array,
@ -75,10 +75,20 @@
let xAxisData = Array.from(new Set(props.chartData.map((item) => item.name))); let xAxisData = Array.from(new Set(props.chartData.map((item) => item.name)));
let seriesData = []; let seriesData = [];
typeArr.forEach((type) => { typeArr.forEach((type) => {
let obj = { name: type, type: props.type }; let obj: any = { name: type, type: props.type };
let chartArr = props.chartData.filter((item) => type === item.type); // update-begin-author:liusq date:2023-7-12 for: [issues/613] LineMulti
let data = [];
xAxisData.forEach((x) => {
let dataArr = props.chartData.filter((item) => type === item.type && item.name == x);
if (dataArr && dataArr.length > 0) {
data.push(dataArr[0].value);
} else {
data.push(null);
}
});
// update-end-author:liusq date:2023-7-12 for: [issues/613] LineMulti
//data //data
obj['data'] = chartArr.map((item) => item.value); obj['data'] = data;
seriesData.push(obj); seriesData.push(obj);
}); });
option.series = seriesData; option.series = seriesData;

View File

@ -7,7 +7,7 @@
import { cloneDeep } from 'lodash-es'; import { cloneDeep } from 'lodash-es';
export default defineComponent({ export default defineComponent({
name: 'lineMulti', name: 'LineMulti',
props: { props: {
chartData: { chartData: {
type: Array, type: Array,
@ -76,14 +76,25 @@
let xAxisData = Array.from(new Set(props.chartData.map((item) => item.name))); let xAxisData = Array.from(new Set(props.chartData.map((item) => item.name)));
let seriesData = []; let seriesData = [];
typeArr.forEach((type) => { typeArr.forEach((type) => {
let obj = { name: type, type: props.type }; let obj: any = { name: type, type: props.type };
let chartArr = props.chartData.filter((item) => type === item.type); // update-begin-author:liusq date:2023-7-12 for: [issues/613] LineMulti
let data = [];
xAxisData.forEach((x) => {
let dataArr = props.chartData.filter((item) => type === item.type && item.name == x);
if (dataArr && dataArr.length > 0) {
data.push(dataArr[0].value);
} else {
data.push(null);
}
});
// update-end-author:liusq date:2023-7-12 for: [issues/613] LineMulti
//data //data
obj['data'] = chartArr.map((item) => item.value); obj['data'] = data;
seriesData.push(obj); seriesData.push(obj);
}); });
option.series = seriesData; option.series = seriesData;
option.xAxis.data = xAxisData; option.xAxis.data = xAxisData;
console.log('option', option);
setOptions(option); setOptions(option);
getInstance()?.off('click', onClick); getInstance()?.off('click', onClick);
getInstance()?.on('click', onClick); getInstance()?.on('click', onClick);