
<script>
import 'echarts/lib/chart/bar'
import echarts from 'echarts'
var xData = ['MAC', 'IP']
var line = ['50', '90']
var attr = {
name: '月平均单价',
unit: '元/单'
}
export default {
data() {
return {
options: {
tooltip: {
trigger: 'item',
padding: 1,
formatter: function (param) {
var resultTooltip =
"<div style='background:rgba(13,5,30,.6);border:1px solid rgba(255,255,255,.2);padding:5px;border-radius:3px;'>" +
"<div style='text-align:center;'>" +
param.name +
'</div>' +
"<div style='padding-top:5px;'>" +
"<span style=''> " +
attr.name +
': </span>' +
"<span style=''>" +
param.value +
'</span><span>' +
attr.unit +
'</span>' +
'</div>' +
'</div>'
return resultTooltip
}
},
grid: {
left: '8%',
top: '10%',
right: '8%',
bottom: '15%'
},
xAxis: [
{
name: '数量',
nameTextStyle: {
align: 'left',
verticalAlign: 'bottom',
lineHeight: 280,
color: '#fff'
},
data: xData,
axisLabel: {
textStyle: {
color: '#fff',
fontSize: 14
},
margin: 20 // 刻度标签与轴线之间的距离。
},
axisLine: {
show: false // 不显示x轴
},
axisTick: {
show: false // 不显示刻度
},
boundaryGap: true
}
],
yAxis: [
{
splitLine: {
show: true,
lineStyle: {
color: '#fff',
type: 'solid'
}
},
axisTick: {
show: false
},
axisLine: {
show: false
},
axisLabel: {
textStyle: {
color: '#fff'
}
}
}
],
series: [
{
// 柱底圆片
name: '',
type: 'pictorialBar',
symbolSize: [60, 22], // 调整截面形状
symbolOffset: [0, 10],
label: {
show: true,
position: 'top',
distance: 15, // 数据显示上方的距离
color: '#fff'
},
itemStyle: {
normal: {
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
{
offset: 0,
color: '#bbce45'
},
{
offset: 1,
color: '#bbce45'
}
])
}
},
data: line
},
// 柱体
{
name: '',
type: 'bar',
barWidth: 60,
barGap: '0%',
itemStyle: {
normal: {
color: {
x: 0,
y: 0,
x2: 0,
y2: 1,
type: 'linear',
global: false,
colorStops: [
{
// 第一节下面
offset: 0,
color: '#bbce45'
},
{
offset: 1,
color: '#bbce45'
}
]
}
}
},
data: line
},
// 柱顶圆片
{
name: '',
type: 'pictorialBar',
symbolSize: [60, 22], // 调整截面形状
symbolOffset: [0, -10],
z: 12,
symbolPosition: 'end',
itemStyle: {
normal: {
color: new echarts.graphic.LinearGradient(
0,
0,
0,
1,
[
{
offset: 0,
color: '#cad344'
},
{
offset: 1,
color: '#cad344'
}
],
false
)
}
},
data: line
}
]
}
}
}
}
</script>
柱状图双y轴刻度线对齐

// 鼠标滑过纵轴线渐变色 两种写法 axisPointer
tooltip: {
trigger: 'axis',
axisPointer: {
lineStyle: {
color: {
type: 'linear',
x: 0,
y: 0,
x2: 0,
y2: 1,
colorStops: [{
offset: 0,
color: 'rgba(0, 255, 233,0)'
}, {
offset: 0.5,
color: 'rgba(255, 255, 255,1)',
}, {
offset: 1,
color: 'rgba(0, 255, 233,0)'
}]
}
},
}
// axisPointer: {
// type: 'line',
// lineStyle: {
// color: new echarts.graphic.LinearGradient(0, 1, 0, 0, [
// {
// offset: 0,
// color: 'transparent'
// },
// {
// offset: 0.2,
// color: '#5989D2'
// },
// {
// offset: 0.5,
// color: '#729EE2'
// },
// {
// offset: 0.8,
// color: '#5989D2'
// },
// {
// offset: 1,
// color: 'transparent'
// }
// ])
// }
// }
},
yAxis: [
{
type: 'value',
splitLine: {
show: true,
lineStyle: {
color: '#C1D7F3',
type: 'dotted'
}
},
min: 0,
max: 0,
interval: 0,
axisLine: {
show: false, // 不显示x轴
lineStyle: {
color: &

本文介绍了如何使用Echarts创建具有双Y轴的柱状图,确保刻度线对齐,同时处理含有负值的数据。还详细讲解了设置轴名称的位置以及为柱状图添加立体阴影的方法。
最低0.47元/天 解锁文章
1433

被折叠的 条评论
为什么被折叠?



