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 
相关推荐
谢尔登23 分钟前
【React】React 18 并发特性
前端·react.js·前端框架
Joker`s smile26 分钟前
使用React+ant Table 实现 表格无限循环滚动播放
前端·javascript·react.js
国家不保护废物31 分钟前
🌟 React 魔法学院入学指南:从零构建你的第一个魔法阵(项目)!
前端·react.js·架构
然我32 分钟前
从原生 JS 到 React:手把手带你开启 React 业务开发之旅
javascript·react.js·前端框架
import_random33 分钟前
[机器学习]svm支持向量机(优势在哪里)
前端
国家不保护废物35 分钟前
从刀耕火种到现代框架:DOM编程 vs Vue/React 进化史
前端·vue.js·react.js
陈随易35 分钟前
Univer v0.8.0 发布,开源免费版 Google Sheets
前端·后端·程序员
wkj00139 分钟前
QuaggaJS 配置参数详解
java·linux·服务器·javascript·quaggajs
代码搬运媛40 分钟前
React 中 HTML 插入的全场景实践与安全指南
安全·react.js·html
不怎么爱学习的dan40 分钟前
实现 ECharts 多国地区可视化方案
前端