1、x轴只显示首末日期,其他日期隐藏
2、y轴数字在标线之上
3、tooltip显示带单位的提示
效果如下:
var fontColor = '#DDDDDD'; //轴线的颜色
var legendName = '国庆收入';
var month = 10;
var xData = [
'10月1日',
'10月2日',
'10月3日',
'10月4日',
'10月5日',
'10月6日',
'10月7日'
];
var seriesData = [82000, 93002, 90100, 93004, 120090, 133000, 130020];
option = {
tooltip: {
trigger: 'axis',
formatter: function (params) {
return (
'时间:' +
params[0].name +
'<br/>' +
params[0].seriesName +
':' +
params[0].value +
'万<br/>'
);
}
},
legend: {
data: legendName
},
xAxis: {
type: 'category',
boundaryGap: false,
offset: 5,
axisLine: {
//坐标轴轴线相关设置
show: true,
lineStyle: {
color: fontColor
}
},
axisTick: {
show: false
},
axisLabel: {
show: true,
textStyle: {
color: fontColor
},
// 只显示第一个和最后一个日期
formatter: function (value, index) {
return index == 0 || index == xData.length - 1 ? value : '';
}
},
data: xData
},
yAxis: {
type: 'value',
name: month + '月国庆节收入曲线图',
nameLocation: 'end',
nameGap: 30,
nameTextStyle: {
padding: [0, 0, 0, 110]
}, //坐标轴名称的文字样式
axisLine: {
//坐标轴轴线相关设置
show: false
},
axisTick: {
show: false
}, //标记长度
axisLabel: {
show: true,
inside: true, //刻度标签是否朝内,默认朝外
margin: 0,
verticalAlign: 'bottom', //文字垂直对齐方式
textStyle: {
color: fontColor
}
},
splitLine: {
show: true,
lineStyle: {
color: fontColor,
width: 1,
type: 'solid'
}
} //分割线
},
series: [
{
name: legendName,
data: seriesData,
type: 'line',
smooth: true,
symbol: 'none',
itemStyle: {
normal: {
color: '#FEA25A'
}
},
areaStyle: {
//折线颜色不取渐变色,取color设置值
normal: {
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
{
offset: 0,
color: 'rgba(254,162,90,1)'
},
{
offset: 1,
color: 'rgba(254,162,90,.1)'
}
])
}
}
}
]
};
或者x轴的 boundaryGap: true,展示如下效果