如何使用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>
    )
}

效果如下

相关推荐
2601_958492555 小时前
Optimizing Engagement with Freehead Skate - HTML5 Game - Construct 3
前端·html·html5
茉莉玫瑰花茶6 小时前
工作流的常见模式 [ 1 ]
java·服务器·前端
zhangxingchao7 小时前
AI应用开发六:企业知识库
前端·人工智能·后端
山峰哥7 小时前
SQL慢查询调优实战:从全表扫描到索引覆盖的完整复盘
前端·数据库·sql·性能优化
红尘散仙7 小时前
一个 `#[uniffi::export]`,把 Rust 接进 React Native
前端·后端·rust
moshuying7 小时前
AI Coding 最大的 token 黑洞,可能根本不是 prompt
前端
红尘散仙7 小时前
一行 `#[specta::specta]`,让 Tauri IPC 有类型
前端·后端·rust
lichenyang4538 小时前
HarmonyOS HMRouter 接入记录:从普通 Tab Demo 到路由跳转
前端
木斯佳8 小时前
前端八股文面经大全:腾讯WXG暑期前端一面(2026-05-15)·面经深度解析
前端·面试·笔试