export function capBar(data) {
return {
grid: {
top: '10',
bottom: '20',
left: '30',
right: '5'
},
tooltip: {
trigger: 'axis',
axisPointer: {
type: 'cross',
crossStyle: {
color: '#999'
},
},
// textStyle: {
// color: '#fff',
// fontSize: 20
// },
},
legend: {
show: false,
data: ['产出', '投入', '标准产出'],
right: 50,
top: 70,
itemHeight: 50,
itemWidth: 100,
itemGap: 100, //这个值是⽤来调图例之间的间距
textStyle: {
color: '#fff',
fontSize: 40
}
},
xAxis: [
{
type: 'category',
data: data.map(e => e.lineName),
axisPointer: {
type: 'shadow'
},
axisLine: {
show: true,
lineStyle: {
color: '#122d67',
width: 1
}
},
axisLabel: {
color: '#8ec0ff',
fontSize: 9
}
},
{
type: 'category',
},
{
type: 'category',
}
],
yAxis: [
{
type: 'value',
name: '',
axisLine: {
show: true,
lineStyle: {
color: '#285aaf',
width: 1
}
},
axisLabel: {
formatter: function (value, index) {
if (value >= 1000) {
value = value / 1000 + "k";
} else if (value < 1000) {
value;
}
return value;
},
color: '#8ec0ff',
fontSize: 10
},
splitLine: {
show: true,
lineStyle: {
color: '#091f56'
}
}
}
],
series: [
{
name: '标准产出',
type: 'bar',
// stack: 'all',
barGap:'-92%',
barWidth: '60%',
showBackground: true,
backgroundStyle: {
color: 'rgba( 40, 90, 175, 0)',
},
data: data.map(e => e.standardOutput),
itemStyle: {
normal: {
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
offset: 0,
color: 'rgba( 255, 255, 255, 0.5)'
}, {
offset: 1,
color: 'rgba( 255, 255, 255, 0.5)'
}]),
barBorderRadius: [0, 0, 0, 0],
}
},
label: {
normal: {
show: false, //柱状图上方显示数据
lineHeight: 46,
width: 90,
height: 43,
// backgroundColor: 'rgba(0,160,221,0.2)',
// borderColor: '#50f2ff',
borderWidth: 2,
borderRadius: 100,
position: 'top',
distance: 1,
color: '#fff',
fontSize: 10,
fontWeight: 800,
formatter: function (p) {
// 超过10000加"k"
return p.value > 10000 ? (p.value / 1000).toFixed(1) + 'k' : p.value
},
rich: {
d: {
color: '#50f2ff',
},
a: {
color: '#fedf19',
align: 'center',
fontSize: 10
},
b: {
width: 1,
height: 48,
borderWidth: 1,
borderColor: '#fedf19',
align: 'left'
},
}
}
}
},
{
name: '实际投入',
type: 'bar',
// stack: 'all',
// barGap: '-100%',
// barWidth: '60%',
barWidth: "51%",
showBackground: true,
backgroundStyle: {
color: 'rgba( 40, 90, 175, 0)',
},
data: data.map(e => e.inputNum),
itemStyle: {
normal: {
color: function (params) {
let { value, dataIndex } = params
let {standardOutput, standardRate} = data[dataIndex]
if (accMul(standardOutput, standardRate) <= value) {
return '#0091FF'
} else {
return '#feaa19'
}
},
barBorderRadius: [0, 0, 0, 0],
}
},
label: {
normal: {
show: false, //柱状图上方显示数据
lineHeight: 46,
width: 90,
height: 43,
borderWidth: 2,
borderRadius: 100,
position: 'top',
distance: 1,
color: '#fff',
fontSize: 10,
fontWeight: 800,
formatter: function (p) {
// 超过10000加"k"
return p.value > 10000 ? (p.value / 1000).toFixed(1) + 'k' : p.value
},
rich: {
d: {
color: '#50f2ff',
},
a: {
color: '#fedf19',
align: 'center',
fontSize: 10
},
b: {
width: 1,
height: 48,
borderWidth: 1,
borderColor: '#fedf19',
align: 'left'
},
}
}
}
},
{
name: '实际产出',
type: 'bar',
// stack: 'all',
// barGap: '-100%',
// barWidth: '30%',
// xAxisIndex: 2,
barWidth: "43%",
showBackground: true,
backgroundStyle: {
color: 'rgba( 40, 90, 175, 0)',
},
data: data.map(e => e.outputNum),
itemStyle: {
normal: {
color: function (params) {
let { value, dataIndex } = params
let {standardOutput, standardRate} = data[dataIndex]
if (accMul(standardOutput, standardRate) <= value) {
return '#50f2ff'
} else {
return '#FFF45C'
}
},
barBorderRadius: [0, 0, 0, 0],
}
},
label: {
normal: {
show: false, //柱状图上方显示数据
lineHeight: 46,
width: 90,
height: 43,
borderWidth: 2,
borderRadius: 100,
position: 'top',
distance: 1,
color: '#fff',
fontSize: 10,
fontWeight: 800,
formatter: function (p) {
return p.value > 10000 ? (p.value / 1000).toFixed(1) + 'k' : p.value
},
rich: {
d: {
color: '#50f2ff',
},
a: {
color: '#fedf19',
align: 'center',
fontSize: 10
},
b: {
width: 1,
height: 48,
borderWidth: 1,
borderColor: '#fedf19',
align: 'left'
},
}
}
}
},
]
}
}
let outputDetail = [
{
"inputNum": 40492,
"outputNum": 37294,
"lineName": "D5",
"standardOutput": -3262,
"standardRate": 0.8
},
{
"inputNum": 23288,
"outputNum": 21862,
"lineName": "CT1",
"standardOutput": 44514,
"standardRate": 0.8
}
]
// 产能总况
let capChart = this.$refs.capChart;
let myChart = this.$echarts.init(capChart);
myChart.setOption(charts.capBar(this.outputDetail));
<div class="barCharts" ref="capChart"></div>
echarts柱状图重叠
最新推荐文章于 2024-05-15 11:06:01 发布