Echarts中联动和共享数据集图表中叠加了上一条的数据?

作者站长头像
站长
· 阅读数 12
var chartDom = document.getElementById('main')
var myChart = echarts.init(chartDom)
var option = {
    color: ['#673AB7', '#02A9F4', '#8BC34B', '#FFC109', '#F44335', '#9D27B0', '#00BCD4', '#CDDD38', '#FFEB3A', '#FF6434', '#403AB5','#2196F3','#4BAF50','#FF9800','#E92662'],
    legend: {
        icon: "circle",
        bottom: '0%'
    },
    tooltip: {
        trigger: 'axis',
        showContent: false
    },
    dataset: {
        source: res
    },
    xAxis: { 
        type: 'category',
        boundaryGap: false,
        axisLine:{
            lineStyle:{
                color: '#C8C8C8' //x轴轴线颜色
            }
        },
        axisLabel: {
            color: '#C8C8C8',// x轴字体颜色
        }
    },
    yAxis: { 
        gridIndex: 0,
        axisLine:{
            lineStyle:{
                color: "#C8C8C8" //x轴轴线颜色
            }
        }
    },
    grid: { 
        top: '55%' 
    },
    series: [
        {
            type: 'line',
            smooth: true,
            seriesLayoutBy: 'row',
            emphasis: { focus: 'series' }
        },
        {
            type: 'line',
            smooth: true,
            seriesLayoutBy: 'row',
            emphasis: { focus: 'series' }
        },
        {
            type: 'line',
            smooth: true,
            seriesLayoutBy: 'row',
            emphasis: { focus: 'series' }
        },
        {
            type: 'line',
            smooth: true,
            seriesLayoutBy: 'row',
            emphasis: { focus: 'series' }
        },
        {
            type: 'line',
            smooth: true,
            seriesLayoutBy: 'row',
            emphasis: { focus: 'series' }
        },
        {
            type: 'line',
            smooth: true,
            seriesLayoutBy: 'row',
            emphasis: { focus: 'series' }
        },
        {
            type: 'line',
            smooth: true,
            seriesLayoutBy: 'row',
            emphasis: { focus: 'series' }
        },
        {
            type: 'line',
            smooth: true,
            seriesLayoutBy: 'row',
            emphasis: { focus: 'series' }
        },
        {
            type: 'line',
            smooth: true,
            seriesLayoutBy: 'row',
            emphasis: { focus: 'series' }
        },
        {
            type: 'line',
            smooth: true,
            seriesLayoutBy: 'row',
            emphasis: { focus: 'series' }
        },
        {
            type: 'line',
            smooth: true,
            seriesLayoutBy: 'row',
            emphasis: { focus: 'series' }
        },
        {
            type: 'line',
            smooth: true,
            seriesLayoutBy: 'row',
            emphasis: { focus: 'series' }
        },
        {
            type: 'line',
            smooth: true,
            seriesLayoutBy: 'row',
            emphasis: { focus: 'series' }
        },
        {
            type: 'line',
            smooth: true,
            seriesLayoutBy: 'row',
            emphasis: { focus: 'series' }
        },
        {
            type: 'line',
            smooth: true,
            seriesLayoutBy: 'row',
            emphasis: { focus: 'series' }
        },
        {
            type: 'line',
            smooth: true,
            seriesLayoutBy: 'row',
            emphasis: { focus: 'series' }
        },
        {
            type: 'pie',
            id: 'pie',
            radius: '30%',
            center: ['50%', '25%'],
            emphasis: {
            focus: 'self'
        },
        label: {
            formatter: '{b}:{@[1]}人 ({d}%)',
            color: '#000000'
        },
        encode: {
            itemName: 'product',
            value: [1],
            tooltip: [1]
        }
    }]
};
myChart.on('updateAxisPointer', function (event) {
    // console.log('qqqqqqqqq', event)
    const xAxisInfo = event.axesInfo[0]
    if (xAxisInfo) {
        const dimension = xAxisInfo.value + 1
        myChart.setOption({
            series: {
                id: 'pie',
                label: {
                    formatter: '{b}: {@[' + dimension + ']}人 ({d}%)'
                },
                encode: {
                    value: dimension,
                    tooltip: dimension
                }
            }
        })
    }
    myChart.setOption(option)
})
option && myChart.setOption(option)

Echarts中联动和共享数据集图表中叠加了上一条的数据?Echarts中联动和共享数据集图表中叠加了上一条的数据?

回复
1个回答
avatar
test
2024-07-14

option && myChart.setOption(option, { notMerge: 'true'})

回复
likes
适合作为回答的
  • 经过验证的有效解决办法
  • 自己的经验指引,对解决问题有帮助
  • 遵循 Markdown 语法排版,代码语义正确
不该作为回答的
  • 询问内容细节或回复楼层
  • 与题目无关的内容
  • “赞”“顶”“同问”“看手册”“解决了没”等毫无意义的内容