echarts icon indicating copy to clipboard operation
echarts copied to clipboard

Markline文字与Y轴文字重叠,有多条Markline时,线条与文字也会重叠,导致看不清楚

Open jeffreywyp opened this issue 9 years ago • 7 comments

One-line summary [问题简述]

使用场景: 1.曲线与柱状结合图表,两个Y轴(一左一右),这样的话左右两侧都有Y轴数字,当设置了Markline并指定lable显示在左右两侧的情况下,Markline的label会与Y轴的文字重叠,影响可读性与美观; 2.设置了Markline针对于Y轴的固定线({ name: "目标值", yAxis: targetPoint}),同时设置了平均值的Markline,当平均值与目标值非常接近时,两条线及文字会重叠;当数据最大值达不到目标值时,目标值的Markline又不会显示出来(例:目标值10000,但数据的最大值才5000,自动生成的Y轴也只会到5000,这时Markline的yAxis:10000这条线就不会显示出来了。 3.当鼠标放在Markline上时,没有tooltip层显示;

Version & Environment [版本及环境]

  • ECharts version [ECharts 版本]:
  • Browser version [浏览器类型和版本]:
  • OS Version [操作系统类型和版本]:

Expected behaviour [期望结果]

1.MarkLine的文字能比较显眼的显示,而且不与Y轴重叠; 2.比较接近或重叠的Markline能想办法区分; 3.当Markline 设置了yAxis值大于自动生成的Y轴时,Y轴能自动延展到设置的yAxis值; 4.Markline能有tooltip显示;

ECharts option [ECharts配置项]

app.title = '折柱混合';

option = {
    tooltip: {
        trigger: 'axis',
        axisPointer: {
            type: 'cross',
            crossStyle: {
                color: '#999'
            }
        }
    },
    toolbox: {
        feature: {
            dataView: {show: true, readOnly: false},
            magicType: {show: true, type: ['line', 'bar']},
            restore: {show: true},
            saveAsImage: {show: true}
        }
    },
    legend: {
        data:['蒸发量','降水量','平均温度']
    },
    xAxis: [
        {
            type: 'category',
            data: ['1月','2月','3月','4月','5月','6月','7月','8月','9月','10月','11月','12月'],
            axisPointer: {
                type: 'shadow'
            }
        }
    ],
    yAxis: [
        {
            type: 'value',
            name: '水量',
            min: 0,
            max: 250,
            interval: 50,
            axisLabel: {
                formatter: '{value} ml'
            }
        },
        {
            type: 'value',
            name: '温度',
            min: 0,
            max: 25,
            interval: 5,
            axisLabel: {
                formatter: '{value} °C'
            }
        }
    ],
    series: [
        {
            name:'蒸发量',
            type:'bar',
            markLine:{
                label: {
                normal: {
                    show: true,
                    position: "left",
                    
                    textStyle: {
                
                        fontStyle: 'italic',
                        fontSize: 13,
                        fontWeight: 600
                    }
                },
                emphasis: {
                    show: true,
                    postion: "left"
                }
            },
            data: [
                         { name: '平均值', type: "average"
                         },
                          { name: '目标值', yAxis:200
                         }//Markline与Y轴数据重叠
                    ]
        },
            data:[2.0, 4.9, 7.0, 23.2, 25.6, 76.7, 135.6, 162.2, 32.6, 20.0, 6.4, 3.3]
        },
        {
            name:'降水量',
            type:'bar',
            markLine:{
                label: {
                normal: {
                    show: true,
                    position: "left",
                    
                    textStyle: {
                
                        fontStyle: 'italic',
                        fontSize: 13,
                        fontWeight: 600
                    }
                },
                emphasis: {
                    show: true,
                    postion: "left"
                }
            },
            data: [
                         { name: '平均值', type: "average"
                         },
                          { name: '目标值', yAxis:202
                         }//Markline与Y轴数据重叠,同时与前面的Markline重叠
                    ]
        },
            data:[2.6, 5.9, 9.0, 26.4, 28.7, 70.7, 175.6, 182.2, 48.7, 18.8, 6.0, 2.3]
        },
        {
            name:'平均温度',
            type:'line',
            yAxisIndex: 1,
            markLine:{
                label: {
                normal: {
                    show: true,
                    position: "left",
                    
                    textStyle: {
                
                        fontStyle: 'italic',
                        fontSize: 13,
                        fontWeight: 600
                    }
                },
                emphasis: {
                    show: true,
                    postion: "left"
                }
            },
            data: [
                         { name: '平均值', type: "average"
                         },
                          { name: '目标值', yAxis:30
                         }//Markline yAxis超出自动生成的Y轴的最大值,没有显示出来
                    ]
        },
            data:[2.0, 2.2, 3.3, 4.5, 6.3, 10.2, 20.3, 23.4, 23.0, 16.5, 12.0, 6.2]
        }
    ]
};


Other comments [其他信息]

jeffreywyp avatar Jun 12 '17 06:06 jeffreywyp

遇到同样的问题,楼主是怎么解决的呢?

mlf75 avatar Dec 25 '17 01:12 mlf75

同问,两条相接近的辅助线,label重叠概率高,看不清楚。

xuchao008 avatar Sep 10 '18 06:09 xuchao008

我也遇到了同样的问题,求解答

heianqishizhisuiyuan avatar Apr 08 '20 08:04 heianqishizhisuiyuan

我在使用柱状图时也遇到了同样的问题,双坐标轴markline右侧与右侧y轴重叠导致看不清楚。尝试了修改markline的长度、偏移量都没效果,最后使用其他方式pollyfill了,即隐藏掉markline的文案,设置自定义tooltip,加上markline的值,这样hover上去就会显示当前的markline的值,与其他节点的交互一致。 wecom-temp-b5d4fd6b63814a95bc89f8b9369dbb76 配置如下 // 隐藏markline右侧文案 markLine: { data: [{ type: 'average', yAxis: 30 }], label: { show: false, }, lineStyle: { color: '#1890ff', } } // 自定义tooltip tooltip: { trigger: 'axis', formatter: () => { return 点击数:70<br> 唤起率:20%<br> <span style="color: #1890ff">基线:30%</span> ; } }

Songshuangshuang avatar Nov 02 '21 03:11 Songshuangshuang

This issue has been automatically marked as stale because it did not have recent activity. It will be closed in 7 days if no further activity occurs. If you wish not to mark it as stale, please leave a comment in this issue.

github-actions[bot] avatar Nov 02 '23 21:11 github-actions[bot]

This issue has been automatically closed because it did not have recent activity. If this remains to be a problem with the latest version of Apache ECharts, please open a new issue and link this to it. Thanks!

github-actions[bot] avatar Nov 10 '23 21:11 github-actions[bot]

【已解决】效果图 image
Editor Demo 添加如下配置看效果

markLine: {
  data: [
    {
      type: 'average',
      name: '平均值',
      label: {
        show: true,
        position: 'insideEndBottom',
        distance: [-50, 8],
        color: '#91cc75',
        formatter: function (params) {
          return '{a|' + params.name + '}\n {b|' + params.value + '}';
        },
        rich: {
          a: {
            fontSize: 12,
            color: '#91cc75'
          },
          b: {
            padding: [4, 0, 0, 0],
            fontSize: 12,
            color: '#91cc75',
            fontStyle: 'italic'
          }
        }
      }
    }
  ]
}

Alicehhhmm avatar Mar 27 '24 02:03 Alicehhhmm