react中使用echarts

先上一张效果图
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 
相关推荐
aklry5 分钟前
uniapp三步完成一维码的生成
前端·vue.js
Rubin9312 分钟前
判断元素在可视区域?用于滚动加载,数据埋点等
前端
爱学习的茄子12 分钟前
AI驱动的单词学习应用:从图片识别到语音合成的完整实现
前端·深度学习·react.js
用户38022585982413 分钟前
使用three.js实现3D地球
前端·three.js
程序无bug15 分钟前
Spring 面向切面编程AOP 详细讲解
java·前端
zhanshuo15 分钟前
鸿蒙UI开发全解:JS与Java双引擎实战指南
前端·javascript·harmonyos
JohnYan15 分钟前
模板+数据的文档生成技术方案设计和实现
javascript·后端·架构
撰卢39 分钟前
如何提高网站加载速度速度
前端·javascript·css·html
10年前端老司机44 分钟前
在React项目中如何封装一个可扩展,复用性强的组件
前端·javascript·react.js
Struggler2811 小时前
解决setTimeout/setInterval计时不准确问题的方案
前端