linkmore-design
Version:
🌈 🚀lm组件库。🚀
147 lines • 2.99 kB
JavaScript
export function getBarOption(cols, source) {
var xAxis = [];
var series = [];
cols.forEach(function (col) {
var _xAxis;
var arr = source.map(function (item) {
return item[col.dataIndex];
});
// 第一个非number类型作为x轴
if (col.etype !== 'number' && !((_xAxis = xAxis) !== null && _xAxis !== void 0 && _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'
}
});
}
});
var option = {
xAxis: {
type: 'category',
data: xAxis
},
yAxis: {
type: 'value'
},
series: series
};
return option;
}
export function getLineOption(cols, source) {
var xAxis = [];
var series = [];
cols.forEach(function (col) {
var _xAxis2;
var arr = source.map(function (item) {
return item[col.dataIndex];
});
// 第一个非number类型作为x轴
if (col.etype !== 'number' && !((_xAxis2 = xAxis) !== null && _xAxis2 !== void 0 && _xAxis2.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'
}
});
}
});
var option = {
xAxis: {
type: 'category',
data: xAxis
},
yAxis: {
type: 'value'
},
series: series
};
return option;
}
export function getPieOption(cols, source) {
var data = source.map(function (item) {
var temp = {};
cols.forEach(function (col) {
if (col.etype === 'number') {
temp.value = item[col.dataIndex];
} else {
temp.name = item[col.dataIndex];
}
});
return temp;
});
var option = {
tooltip: {
trigger: 'item'
},
legend: {
orient: 'vertical',
left: 'left'
},
series: [{
name: '饼图',
type: 'pie',
radius: '50%',
data: data,
emphasis: {
itemStyle: {
shadowBlur: 10,
shadowOffsetX: 0,
shadowColor: 'rgba(0, 0, 0, 0.5)'
}
}
}]
};
return option;
}
export default {
getBarOption: getBarOption
};