代码之家  ›  专栏  ›  技术社区  ›  Miles M.

使用datazoom缩放时出现eCharts xAxis错误

  •  0
  • Miles M.  · 技术社区  · 6 年前

    我正在努力寻找解决这个错误的方法。我正在显示一个有2个Y轴和数据缩放的图表。大多数情况下工作正常:

    Chart with 2 Yaxis and datazoom

    如果我取消选择一行(比如Price),那么其中一个Yaxis就会隐藏起来。那很好。但是如果我再放大一点,我会遇到一个错误,X轴指向图表的中心。

    Chart with 1 Yaxis selected and buggy

    我一直在尝试X轴和Yaxis上的每一个选项,但没有运气。有什么建议吗?

    这是我传递给echart图书馆的选项数组

    let stacked_scores_options = {
    
                 color: ['#000', '#ff7f50', '#87cefa', '#ba55d3', '#32cd32', '#6495ed', '#ff69b4'],
    
                // Setup grid
                grid: {
                    x: 55,
                    x2: 42,
                    y: 30,
                    y2: 95
                },
    
                title : {
                    textStyle: {
                        fontFamily: "Roboto",
                        fontSize: "17",
                        fontWeight: "400"
                    },
                    padding: [0,0,5,10]
                },
                tooltip : {
                    trigger: 'axis',
                    formatter: tooltipSentScore,
                },
                legend: {
                     data:['Price', 'Sentscore', 'News', 'Social', 'Buzz', 'Fundamental', 'Technical'],
                    selected: {
                        // 'Price': true,
                        'Sentscore': true,
                        'News': false,
                        'Social': false,
                        'Buzz': false,
                        'Fundamental': false,
                        'Technical': false,
                    },
                },
                dataZoom : {
                    show : true,
                    y: 410,
                    realtime: true,
                    start : 0,
                    end : 100
                },
                xAxis : [
                    {
                        type : 'category',
                        boundaryGap : true,
                        position: 'bottom',
                        axisTick: {
                            inside: true,
                            alignWithLabel: true,
                        },
                        data : [],
                        scale: true,
                        axisLabel: {
                            showMaxLabel: true,
                            showMinLabel: true,
                            formatter: function (value, index) {
                                var res = value.split(" ");
                                return res.join('\n');
                            }
                        }
                    }
                ],
                yAxis : [
                    {
                        type : 'value',
                        scale:true,
                        splitNumber: 'auto',
                        boundaryGap: [0.01, 0.01]
                    },
                    {
                        type : 'value',
                        scale:true,
                        splitLine: { show: false },
                        splitNumber: 'auto',
                        boundaryGap: [0.01, 0.01],
    
                        axisLabel : {
                            formatter: '${value}'
                        },
                        name: 'USD Prices',
                        nameLocation: 'middle',
                        nameGap: 50
                    }
                ],
                series : [
                     {
                         name:'Price',
                         type:'line',
                         symbol: 'none',
                         yAxisIndex: 1,
                         data: []
                    },
                    {
                        name:'Sentscore',
                        type:'line',
                        symbol: 'none',
                        data: []
                    },
                    {
                        name:'News',
                        type:'line',
                        symbol: 'none',
                        data: []
                    },
                    {
                        name:'Social',
                        type:'line',
                        symbol: 'none',
                        data: []
                    },
                    {
                        name:'Buzz',
                        type:'line',
                        symbol: 'none',
                        data: []
                    },
                    {
                        name:'Fundamental',
                        type:'line',
                        symbol: 'none',
                        data: []
                    },
                    {
                        name:'Technical',
                        type:'line',
                        symbol: 'none',
                        data: []
                    }
                ]
            };
    
    1 回复  |  直到 6 年前
        1
  •  1
  •   Miles M.    6 年前

    我找到了解决办法。对于有相同问题的人,您要添加 axisLine: {onZero: false} 你的X轴是这样的:

                xAxis : [
                    {
                        type : 'category',
                        boundaryGap : true,
                        axisLine: {onZero: false}, //Fix the bug
                        axisTick: {
                            inside: true,
                            alignWithLabel: true,
                        },
                        axisLabel: {
                            showMaxLabel: true,
                            showMinLabel: true,
                            formatter: function (value) {
                                var res = value.split(" ");
                                return res.join('\n');
                            }
                        },
                        data : []
                    }
                ],