javascript - echarts在折线图和y轴标签之间添加填充

标签 javascript echarts

我使用echarts plugin在某些网页上构建折线图。它工作得很好,但我在里面找不到documentation如何在折线图和y轴标签之间添加填充并将y轴标签移动到y轴分割线之间的中心?

当前行echarts插件实例 View :

Current line echarts plugin instance view

预期行echarts插件实例 View :

Expected line echarts plugin instance view

上面的屏幕截图意味着我在心里将图形从内部标签移开,这样它们就不会相交,并沿着游戏的 y 轴将标签移动到分割线之间的正下方

Mentally shifted the graph away from the internal label so that they would not intersect and moved the labels along the y-axis of the game below exactly in the center between the split lines

我需要更改插件中的哪些设置才能获得与屏幕截图中相同的结果和预期结果?

最佳答案

您可以通过不同的方式来实现这一目标,但大多数方式的支持成本很高并且实现起来很困难。这是一种安全且简单的方法,但您需要注意 xAxis 的点比系列数据多一点,以显示差距。

var myChart = echarts.init(document.getElementById('main'));
var option = {
  tooltip: {
    trigger: 'axis'
  },
  grid: {
    left: '3%',
    right: '10%',
    bottom: '3%',
    containLabel: true
  },
  xAxis: {
    type: 'category',
    boundaryGap: false,
    data: [1, 2, 3, 4, 5, 6, 7, 8, 9]
  },
  yAxis: {
    type: 'value',
    position: 'right',
    axisLabel: {
      inside: true,
      margin: 50,
      fontSize: 18
    }
  },
  series: [{
    type: 'line',
    areaStyle: {
      color: 'rgba(104, 216, 214, 0.4)'
    },
    lineStyle: {
      width: 2,
      color: 'rgba(104, 216, 214, 1)'
    },
    data: [120, 132, 101, 134, 90, 230, 210]
  }, ]
};

myChart.setOption(option);
<script src="https://cdn.jsdelivr.net/npm/<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="492c2a21283b3d3a097d67716779" rel="noreferrer noopener nofollow">[email protected]</a>/dist/echarts.min.js"></script>
<div id="main" style="width: 600px;height:400px;"></div>

关于javascript - echarts在折线图和y轴标签之间添加填充,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63505287/

相关文章:

echarts - echarts中不同图表如何链接缩放

javascript - 如何从 for 循环创建数组并在稍后使用它

javascript - 如何在使用 jquery 动态添加行时更改 object_id

r - Echarts4r 的条形图从 0 以外的值开始

angular - 通过编程更新无法在 Angular 7 中看到任何带有 echart 的图表

vue.js - vue echarts 的自动调整大小不起作用

javascript - 为什么 map() 在这种情况下得到 2 个参数?

javascript - 当日期选择器和相邻元素之间没有空格时,Angular-Datepicker 不起作用?

javascript - 在 IE : alternative for setAttribute method 中动态设置输入元素的 id 属性

charts - 如何从Echart库的折线图中删除网格