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 
相关推荐
@PHARAOH9 分钟前
HOW - 浏览器兼容(含 Safari)
前端·safari
undefined在掘金3904120 分钟前
flutter 仿商场_首页
前端
少卿20 分钟前
react-native图标替换
前端·react native
熊猫钓鱼>_>25 分钟前
TypeScript前端架构与开发技巧深度解析:从工程化到性能优化的完整实践
前端·javascript·typescript
JYeontu1 小时前
肉眼难以分辨 UI 是否对齐,写个插件来辅助
前端·javascript
fox_1 小时前
别再踩坑!JavaScript的this关键字,一次性讲透其“变脸”真相
前端·javascript
盛夏绽放1 小时前
uni-app Vue 项目的规范目录结构全解
前端·vue.js·uni-app
少卿1 小时前
React Native Vector Icons 安装指南
前端·react native
国家不保护废物1 小时前
Vue组件通信全攻略:从父子传到事件总线,玩转组件数据流!
前端·vue.js
写不来代码的草莓熊2 小时前
vue前端面试题——记录一次面试当中遇到的题(9)
前端·javascript·vue.js