先上一张效果图
React中 配置属性如下,可直接粘贴使用
import React, { useEffect, useMemo, useState } from 'react'
import * as echarts from 'echarts'
import ReactECharts from 'echarts-for-react'
const LineChart = (props: any) => {
const option = {
color: ['#b5e200'],
tooltip: {
trigger: 'axis',
axisPointer: {
type: 'cross',
label: {
backgroundColor: '#6a7985',
},
},
},
grid: {
show: false,
top: 0,
left: 0,
right: 0,
bottom: 20,
containLabel: true,
},
xAxis: {
show: true,
type: 'category',
boundaryGap: true,
splitLine: {
show: false,
lineStyle: {
type: [2, 6],
color: '#64748B',
opacity: 0.6,
},
},
axisLine: {
show: false,
lineStyle: {
color: '#64748B',
fontFamily: 'Lexend',
},
},
axisTick: {
show: false,
},
axisLabel: {
margin: 20,
interval: 0,
},
data: ['02-10','02-11','02-12','02-13','02-14','02-15','02-16'],
},
yAxis: {
type: 'value',
position: 'right',
min: 96,
max: 100,
splitLine: {
show: true,
lineStyle: {
type: [2, 6],
color: '#64748B',
opacity: 0.6,
},
},
axisLine: {
show: false,
lineStyle: {
color: '#64748B',
fontFamily: 'Lexend',
},
},
axisTick: {
show: false,
},
axisLabel: {
inside: true,
margin: 0,
showMinLabel: false,
showMaxLabel: false,
verticalAlign: 'bottom',
formatter: function (value) {
return value + '%'
},
},
},
series: [
{
name: 'category',
type: 'line',
smooth: true,
lineStyle: {
width: 3,
},
showSymbol: false,
areaStyle: {
opacity: 0.5,
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
{
offset: 0,
color: 'rgba(181,226,0,5)',
},
{
offset: 1,
color: 'rgba(255,255,255,1)',
},
]),
},
emphasis: {
focus: 'series',
},
data: [97.2,97.8,98.2,98.7,99.3,99.5,99.8],
},
],
}
return <ReactECharts option={option} style={{ height: 300 }} />
安装包依赖
npm install echarts echarts-for-react --save
或
yarn add echarts echarts-for-react