解决ECharts两条条折线图数据一样时,拐点处数据重合(设置ECharts两条折线图拐点处数据一上一下)

解决办法:在series里选择一条数据,给其labelposition赋值为“top”或“bottom”,与另一个进行区分。

示例代码如下:

option = {
    backgroundColor: '#080b30',
    title: {
        text: '',
        textStyle: {
            align: 'center',
            color: '#fff',
            fontSize: 20,
        },
        top: '5%',
        left: 'center',
    },
    tooltip: {
        trigger: 'axis',
        axisPointer: {
            lineStyle: {
                color: {
                    type: 'linear',
                    x: 0,
                    y: 0,
                    x2: 0,
                    y2: 1,
                    colorStops: [{
                        offset: 0,
                        color: 'rgba(0, 255, 233,0)'
                    }, {
                        offset: 0.5,
                        color: 'rgba(255, 255, 255,1)',
                    }, {
                        offset: 1,
                        color: 'rgba(0, 255, 233,0)'
                    }],
                    global: false
                }
            },
        },
    },
    grid: {
        top: '15%',
        left: '5%',
        right: '5%',
        bottom: '15%',
        // containLabel: true
    },
    xAxis: [{
        type: 'category',
        axisLine: {
            show: true
        },
        splitArea: {
            // show: true,
            color: '#f00',
            lineStyle: {
                color: '#f00'
            },
        },
        axisLabel: {
            color: '#fff'
        },
        splitLine: {
            show: false
        },
        boundaryGap: false,
        data: ['A', 'B', 'C', 'D', 'E', 'F'],

    }],

    yAxis: [{
        type: 'value',
        min: 0,
        // max: 140,
        splitNumber: 4,
        splitLine: {
            show: true,
            lineStyle: {
                color: 'rgba(255,255,255,0.1)'
            }
        },
        axisLine: {
            show: false,
        },
        axisLabel: {
            show: false,
            margin: 20,
            textStyle: {
                color: '#d1e6eb',

            },
        },
        axisTick: {
            show: false,
        },
    }],
    series: [{
            name: '注册总量',
            type: 'line',
            // smooth: true, //是否平滑
            showAllSymbol: true,
            // symbol: 'image://./static/images/guang-circle.png',
            symbol: 'circle',
            // symbolSize: 25,
            lineStyle: {
                normal: {
                    color: "#6c50f3",
                    shadowColor: 'rgba(0, 0, 0, .3)',
                    shadowBlur: 0,
                    shadowOffsetY: 5,
                    shadowOffsetX: 5,
                },
            },
            label: {
                show: true,
                position: 'top',
                textStyle: {
                    color: '#6c50f3',
                }
            },
            tooltip: {
                show: false
            },
            areaStyle: {
                normal: {
                    color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                            offset: 0,
                            color: 'rgba(108,80,243,0.3)'
                        },
                        {
                            offset: 1,
                            color: 'rgba(108,80,243,0)'
                        }
                    ], false),
                    shadowColor: 'rgba(108,80,243, 0.9)',
                    shadowBlur: 20
                }
            },
            data: [281.84, 205.97, 332.79, 281.55, 398.35, 214.02, ]
        },
        {
            name: '注册总量',
            type: 'line',
            // smooth: true, //是否平滑
            showAllSymbol: true,
            // symbol: 'image://./static/images/guang-circle.png',
            symbol: 'circle',
            // symbolSize: 25,
            lineStyle: {
                normal: {
                    color: "#00ca95",
                    shadowColor: 'rgba(0, 0, 0, .3)',
                    shadowBlur: 0,
                    shadowOffsetY: 5,
                    shadowOffsetX: 5,
                },
            },
            label: {
                show: true,
                position: 'top',
                textStyle: {
                    color: '#00ca95',
                }
            },

            tooltip: {
                show: false
            },
            areaStyle: {
                normal: {
                    color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                            offset: 0,
                            color: 'rgba(0,202,149,0.3)'
                        },
                        {
                            offset: 1,
                            color: 'rgba(0,202,149,0)'
                        }
                    ], false),
                    shadowColor: 'rgba(0,202,149, 0.9)',
                    shadowBlur: 20
                }
            },
            data: [280.84, 204.97, 333.79, 282.55, 397.35, 213.02, ],
        },
    ]
};

示例结果如下(当两条折线图拐点的数据大小很相似的时候,其数据就会发生重合现象,因为两条折线图的position都为top):
在这里插入图片描述
此时我们可以将其中一条折线图的数据显示在下方(将其中一条折线图的position设置为bottom,例如“注册总量”这条线)。

部分代码如下:

label:{
    show: true,
    position: 'bottom', // 设置拐点处数字出现的位置
    textStyle: {
        color: '#00ca95',
    }
},

结果如下:
在这里插入图片描述
这样就可以很好的进行区分。

  • 6
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 6
    评论
根据引用\[1\],当两条折线图拐点数据大小很相似,可能会发生重合现象。为了解决这个问题,可以将其中一折线图数据显示在下方,将其position设置为bottom,例如将"注册总量"这线设置为bottom。 根据引用\[2\],可以使用Echarts的data属性来设置折线图数据。例如,可以使用以下格式来设置A折线数据:\[\['2022-09-01',10\],\['2022-09-02',20\],\['2022-09-04',40\],\['2022-09-06',60\]\]。 根据引用\[3\],在Activity中可以使用EchartsView来显示折线图。可以使用EchartOptionUtil.getLineChartOptions方法来设置折线图的选项,包括x轴和y轴的数据。可以通过设置随机数来生成测试数据,并将数据传递给echartView.refreshEchartsWithOption方法来刷新折线图。 综上所述,可以通过设置折线图的position属性、使用Echarts的data属性来设置折线图数据,以及使用EchartOptionUtil.getLineChartOptions方法来设置折线图的选项来创建两条数据不一样的折线图。 #### 引用[.reference_title] - *1* [解决ECharts两条折线图数据一样拐点数据重合设置ECharts两条折线图拐点数据一上一下)](https://blog.csdn.net/weixin_42881768/article/details/118218138)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* [Echarts折线图X轴数据不同数据错乱](https://blog.csdn.net/qq_37301074/article/details/127023023)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] - *3* [Android Echarts折线图和多折线图的使用](https://blog.csdn.net/erjia_/article/details/124061718)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值