【ReactEcharts】折线图常规案例实现

详细配置项可跳转至我的文章 ReactEcharts常见基础配置项解析

代码实现

import React from 'react';
import ReactEcharts from 'echarts-for-react';
import * as echarts from 'echarts';

export default function LineEcharts(props) {
    const { dataList, nameList } = props;
    let option = {
        background:
            'linear-gradient(270deg, rgba(0,0,0,0) 0%, rgba(3,7,22,0.73) 47%, #061135 100%);',
        grid: {
            left: '10%',
            right: '10%',
            top: '30%',
            bottom: '10%',
            containLabel: true,
        },
        tooltip: {
            show: true,
            trigger: 'item',
            confine: true,
        },
        legend: {
            show: true,
            data: ['案例1', '案例2'],
            top: '10%',
            left: 'center',
            icon: 'rect',
            textStyle: {
                color: '#fff',
            },
        },
        xAxis: [
            {
                type: 'category',
                name: 'X轴',
                nameLocation: 'end',
                nameTextStyle: {
                    nameGap: 10, //坐标轴名称与轴线之间的距离
                    nameRotate: 0, // 坐标轴名字旋转
                },
                boundaryGap: false,
                // 轴线配置
                axisLine: {
                    show: true,
                    lineStyle: {
                        color: 'rgba(255,255,255,0.2)',
                        type: 'solid',
                        width: 1,
                    },
                },
                // 刻线
                axisTick: {
                    show: true,
                    length: 10,
                },
                // x轴标签配置
                axisLabel: {
                    show: true,
                    rotate: 30, //旋转角度
                    margin: 30, // 刻度标签和轴线之间的距离
                    formatter: (value, index) => {
                        return `${value}++`;
                    },
                },
                splitLine: {
                    // 分割线
                    show: true,
                    lineStyle: {
                        color: 'rgba(255,255,255,0.2)',
                    },
                },
                data: nameList,
            },
        ],
        yAxis: [
            {
                type: 'value',
                name: '单位:分',
                nameTextStyle: {
                    align: 'right',
                    verticalAlign: 'bottom',
                    padding: [5, 0, 0, 0], //调整Y轴单位位置
                    color: '#fff',
                    fontWeight: 500, // 调整Y轴单位字号
                },
                axisLabel: {
                    formatter: '{value}分',
                    textStyle: {
                        color: '#ccc222',
                    },
                },
                axisLine: {
                    lineStyle: {
                        color: '#a11',
                    },
                },
                axisTick: {
                    show: false,
                },
                splitLine: {
                    show: true,
                    lineStyle: {
                        type: 'dashed',
                        color: 'rgba(0,192,255,0.6)',
                    },
                },
            },
        ],
        series: [
            {
                name: '案例1',
                type: 'line',
                stack: '总量',
                symbol: 'circle',
                symbolSize: 8,
                itemStyle: {
                    color: '#16B2FB',
                },
                lineStyle: {
                    color: '#16B2FB',
                    width: 1,
                    borderWidth: 2,
                },
                opacity: 0,
                areaStyle: {
                    color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                        {
                            offset: 0,
                            color: 'rgba(22,178,251,0.8)',
                        },
                        {
                            offset: 1,
                            color: 'rgba(139, 185, 255, 0.01)',
                        },
                    ]),
                },
                data: dataList,
            },
        ],
    };
    return (
        <ReactEcharts
            option={option}
            notMerge
            lazyUpdate
            style={{ height: '400px', width: '400px' }}
        />
    );
}

效果图

在这里插入图片描述

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值