如何使用Echarts

以umi为例

首先是下载两个插件(echarts和echarts-for-react)

npm

npm install --save echarts-for-react

npm install echarts

yarn

yarn add echarts-for-react

yarn add echarts

接下来是在tsx或jsx中引入使用

复制代码
import ReactEcharts from "echarts-for-react";
import React from 'react'

export default function Line() {

    let option = {

        legend: {
            data: ['Java', 'C', 'C++', 'Python', 'JavaScript', 'PHP', 'SQL', 'Visual Basic.NET']
            ,textStyle: {
                color: 'white'
            }
        },
        grid: {
            left: '3%',
            right: '4%',
            bottom: '3%',
            containLabel: true
        },
        xAxis: {
            type: 'category',
            boundaryGap: false,
            data: ['1989', '1994', '19999', '2004', '2009', '2014', '2019']
        },
        yAxis: {
            type: 'value'
        },
        series: [
            {
                name: 'Java',
                type: 'line',

                data: [120, 132, 101, 134, 90, 230, 210
                ]
            },
            {
                name: 'C',
                type: 'line',

                data: [220, 182, 191, 234, 290, 330, 310]
            },
            {
                name: 'C++',
                type: 'line',

                data: [150, 232, 201, 154, 190, 330, 410]
            },
            {
                name: 'Python',
                type: 'line',

                data: [320, 332, 301, 334, 390, 330, 320]
            },
            {
                name: ' JavaScript',
                type: 'line',
                data: [430, 578, 321, 478, 135, 457, 120]
            },
            {
                name: 'PHP',
                type: 'line',

                data: [220, 182, 245, 234, 290, 330, 310]
            },
            {
                name: 'SQL',
                type: 'line',

                data: [150, 232, 201, 154, 667, 330, 410]
            },
            {
                name: 'Visual Basic.NET',
                type: 'line',

                data: [320, 332, 371, 334, 390, 330, 258]
            },
        ]
    };


    return (
        <div>
            <ReactEcharts option={option}  />
        </div>
    )
}

效果如下

相关推荐
超绝大帅哥1 天前
React的Fiber是什么? Vue为什么不需要Fiber ?
前端
yingyima1 天前
正则表达式分组与捕获:凌晨3点服务器报警的解决方案
前端
swipe1 天前
从 0 到 1 理解 React 虚拟列表:定高、不定高与 Canvas 版本完整拆解
前端·javascript·面试
铁皮饭盒1 天前
Bun执行python代码
前端·javascript·后端
hunterandroid1 天前
Service 与前台服务:让任务在后台持续运行
前端
米饭同学i1 天前
深扒 LobsterAI 官网前端动效实现方案:从交互细节到代码实践
前端
前端啊1 天前
告别 el-table 打印难题,vue3-print-el-table 来了!
前端·vue.js
JarvanMo1 天前
AI时代跨平台还有必要吗?
前端
Patrick_Wilson1 天前
幂等到底是什么?从前端视角讲透 SQL、HTTP 与 POST 接口的幂等设计
前端·后端·架构
凌览1 天前
一人公司别再上 Jenkins,真不值
前端·后端