简体   繁体   English

ECharts:如何显示所有轴标签?

[英]ECharts: how to show all axis labels?

Echarts seems to have a nice feature that automatically chooses which labels to display depending on the space provided. Echarts 似乎有一个不错的功能,可以根据提供的空间自动选择要显示的标签。 However, this algorithm seems to be bit too aggressive at times and does not take into account text rotate.然而,这个算法有时似乎有点过于激进,并且没有考虑到文本旋转。 I've gone through the chart options and there doesn't appear to be a way to disable this feature.我浏览了图表选项,似乎没有办法禁用此功能。 I'm hoping it's just something I've overlooked.我希望这只是我忽略的东西。 Help appreciated.帮助表示赞赏。

"

axisLabel (under yAxis or xAxis ) has an option interval . axisLabel (在yAxisxAxis )有一个选项interval Set this to 0 and labels will be displayed.将此设置为0 ,将显示标签。

You can try this to force the label of the x-axis,你可以试试这个来强制x轴的标签,

xAxis: {
      type: "category",
      data: data[0],
      axisLabel: {
        interval: 0,
        rotate: 30 //If the label names are too long you can manage this by rotating the label.
      }

//If your label is in the `y-axis` simply change the code `xAxis` to `yAxis`.

If your axis label is not showing in a chart frame (mean ECharts label's length is too long), Try this,如果您的轴标签未显示在图表框架中(意味着 ECharts 标签的长度太长),请尝试此操作,

grid: { containLabel: true },

2 ways to solve long label text解决长标签文本的2种方法

  1. Using rotate option xAxis : { axisLabel: { rotate: 45 } }使用旋转选项 xAxis : { axisLabel: {rotate: 45 } }
  2. Using formatter and introducing '/n' to break the text使用格式化程序并引入 '/n' 来中断文本

just for the record:仅作记录:

If your categories have a fixed width, you can also set it up like this, in order to show all labels:如果您的类别有固定宽度,您也可以这样设置,以便显示所有标签:

      axisLabel: {
        width: 100, //fixed number of pixels
        overflow: 'truncate', // or 'break' to continue in a new line
        interval: 0,
      },

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM