一个项目需求:折线图中每个区间展示一个文案
使用echarts中的graphic配置选项
graphic: [
{
type:'text',
right: '15%',
top: '10%',
z: 999,
style:{
text: '极度拥挤',
fill: '#E72938',
fontWeight: 400,
fontSize: 10
}
},
{
type:'text',
right: '15%',
top: '25%',
z: 999,
style:{
text: '拥挤',
fill: '#FF891A',
fontWeight: 400,
fontSize: 10
}
},
{
type:'text',
right: '15%',
top: '41%',
z: 999,
style:{
text: '正常',
fill: '#523CF2',
fontWeight: 400,
fontSize: 10
}
},
{
type:'text',
right: '15%',
top: '55%',
z: 999,
style:{
text: '畅通',
fill: '#50A5FE',
fontWeight: 400,
fontSize: 10
}
},
{
type:'text',
right: '15%',
top: '71%',
z: 999,
style:{
text: '极度畅通',
fill: '#1CD6F3',
fontWeight: 400,
fontSize: 10
}
}
],
完整的options选项
{
graphic: [
{
type:'text',
right: '15%',
top: '10%',
z: 999,
style:{
text: '极度拥挤',
fill: '#E72938',
fontWeight: 400,
fontSize: 10
}
},
{
type:'text',
right: '15%',
top: '25%',
z: 999,
style:{
text: '拥挤',
fill: '#FF891A',
fontWeight: 400,
fontSize: 10
}
},
{
type:'text',
right: '15%',
top: '41%',
z: 999,
style:{
text: '正常',
fill: '#523CF2',
fontWeight: 400,
fontSize: 10
}
},
{
type:'text',
right: '15%',
top: '55%',
z: 999,
style:{
text: '畅通',
fill: '#50A5FE',
fontWeight: 400,
fontSize: 10
}
},
{
type:'text',
right: '15%',
top: '71%',
z: 999,
style:{
text: '极度畅通',
fill: '#1CD6F3',
fontWeight: 400,
fontSize: 10
}
}
],
grid: {
x: 0,
y: 10,
x2: 0,
y2: 30,
containLabel: true
},
xAxis: {
boundaryGap: false,
type: 'category',
data: dateList,
axisTick: {
// 是否显示x轴刻度
show: false
},
axisLine: {
// 是否显示x轴线
show: false
},
axisLabel: {
color: '#999999',
interval: 0,
formatter: (value, index) => {
const length = dateList.length
if (index === 0) {
return ' ' + dayjs(value).format('YYYY-MM')
}
if (index === length - 1) {
return dayjs(value).format('YYYY-MM') + ' '
}
if (length > 3 && parseInt(length / 2) === index) {
return dayjs(value).format('YYYY-MM')
}
return ''
}
}
},
yAxis: [
{
type: 'value',
min: 100,
max: 0,
splitNumber: 10, //设置坐标轴的分割段数
interval: (100 - 0) / 5, // 标轴分割间隔
axisLabel: {
color: '#999999'
}
},
{
type: 'value',
min: minData2,
max: maxData2,
splitNumber: 10,
interval: (maxData2 - minData2) / 5,
axisLabel: {
color: '#999999',
formatter: function (value) {
return value.toFixed(0)
}
}
}
],
series: [
{
name: '走势线1',
type: 'line',
color: ['#E72938'],
symbol: 'none',
smooth: true,
yAxisIndex: 0, //在单个图表实例中存在多个y轴的时候有用
data: crowdList,
lineStyle: {
width: 1
},
markArea: { //标记区域
data: [
[{
yAxis: '100',//y轴坐标控制
itemStyle: {
color: {
type: 'linear',
x: 0,
y: 0,
x2: 1,
y2: 0,
colorStops: [{
offset: 0, color: '#FEFAF9' // 0% 处的颜色
}, {
offset: 1, color: '#FEF5F3' // 100% 处的颜色
}],
global: false // 缺省为 false
}
},
emphasis: {
disabled: true
}
}, {
yAxis: '80'
}],
[{
yAxis: '80',//y轴坐标控制
itemStyle: {
color: {
type: 'linear',
x: 0,
y: 0,
x2: 1,
y2: 0,
colorStops: [{
offset: 0, color: '#FFFEFB' // 0% 处的颜色
}, {
offset: 1, color: '#FEFAF3' // 100% 处的颜色
}],
global: false // 缺省为 false
}
},
emphasis: {
disabled: true
}
}, {
yAxis: '60'
}],
[{
yAxis: '60',//y轴坐标控制
itemStyle: {
color: {
type: 'linear',
x: 0,
y: 0,
x2: 1,
y2: 0,
colorStops: [{
offset: 0, color: '#FAFAFF' // 0% 处的颜色
}, {
offset: 1, color: '#F1F0FF' // 100% 处的颜色
}],
global: false // 缺省为 false
}
},
emphasis: {
disabled: true
}
}, {
yAxis: '40'
}],
[{
yAxis: '40',//y轴坐标控制
itemStyle: {
color: {
type: 'linear',
x: 0,
y: 0,
x2: 1,
y2: 0,
colorStops: [{
offset: 0, color: '#F4FAFF' // 0% 处的颜色
}, {
offset: 1, color: '#E5F3FF' // 100% 处的颜色
}],
global: false // 缺省为 false
}
},
emphasis: {
disabled: true
}
}, {
yAxis: '20'
}],
[{
yAxis: '20',
itemStyle: {
color: {
type: 'linear',
x: 0,
y: 0,
x2: 1,
y2: 0,
colorStops: [{
offset: 0, color: '#F6FDFF' // 0% 处的颜色
}, {
offset: 1, color: '#EDFAFE' // 100% 处的颜色
}],
global: false // 缺省为 false
}
},
emphasis: {
disabled: true
},
}, {
yAxis: '0'
}]
]
},
},
{
name: '走势线2',
type: 'line',
color: ['#2C7AF4'],
symbol: 'none',
smooth: true,
yAxisIndex: 1,
data: valueList,
lineStyle: {
width: 1
}
}
]
}