linkmore-design
Version:
🌈 🚀lm组件库。🚀
155 lines (154 loc) • 3.01 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
exports.getBarOption = getBarOption;
exports.getLineOption = getLineOption;
exports.getPieOption = getPieOption;
function getBarOption(cols, source) {
let xAxis = [];
const series = [];
cols.forEach(col => {
const arr = source.map(item => {
return item[col.dataIndex];
});
// 第一个非number类型作为x轴
if (col.etype !== 'number' && !xAxis?.length) {
xAxis = arr;
return;
}
if (col.xAxis) {
xAxis = arr;
return;
}
if (col.etype === 'number') {
series.push({
data: arr,
type: 'bar',
name: col.title,
legend: {},
grid: {
left: '3%',
right: '4%',
bottom: '3%',
containLabel: true
},
tooltip: {
trigger: 'axis',
axisPointer: {
type: 'shadow'
}
},
label: {
show: false,
position: 'center'
}
});
}
});
const option = {
xAxis: {
type: 'category',
data: xAxis
},
yAxis: {
type: 'value'
},
series
};
return option;
}
function getLineOption(cols, source) {
let xAxis = [];
const series = [];
cols.forEach(col => {
const arr = source.map(item => {
return item[col.dataIndex];
});
// 第一个非number类型作为x轴
if (col.etype !== 'number' && !xAxis?.length) {
xAxis = arr;
return;
}
if (col.xAxis) {
xAxis = arr;
return;
}
if (col.etype === 'number') {
series.push({
data: arr,
type: 'line',
name: col.title,
legend: {},
grid: {
left: '3%',
right: '4%',
bottom: '3%',
containLabel: true
},
tooltip: {
trigger: 'axis',
axisPointer: {
type: 'shadow'
}
},
label: {
show: false,
position: 'center'
}
});
}
});
const option = {
xAxis: {
type: 'category',
data: xAxis
},
yAxis: {
type: 'value'
},
series
};
return option;
}
function getPieOption(cols, source) {
const data = source.map(item => {
const temp = {};
cols.forEach(col => {
if (col.etype === 'number') {
temp.value = item[col.dataIndex];
} else {
temp.name = item[col.dataIndex];
}
});
return temp;
});
const option = {
tooltip: {
trigger: 'item'
},
legend: {
orient: 'vertical',
left: 'left'
},
series: [{
name: '饼图',
type: 'pie',
radius: '50%',
data,
emphasis: {
itemStyle: {
shadowBlur: 10,
shadowOffsetX: 0,
shadowColor: 'rgba(0, 0, 0, 0.5)'
}
}
}]
};
return option;
}
var _default = {
getBarOption
};
exports.default = _default;