数据全0时,如何配置x轴的位置?

阅读 2.7k
2 个回答

试一下y轴最小值给0

解决方案 Solution

不同图表库的解决方案不一样,根据你给的demo,只需要将Y轴的axes-linear.`zero 设置为true`即可。

  • barChart-axes-linear.`zero` = true 仅当轴为线性轴时生效,是否包含 0 值。当配置了 min 和 max,该配置项失效。

image.png

代码示例 Code Example

代码参考 Code Example

const spec = {
  type: 'line',
  data: {
    values: [
      {
        time: '2:00',
        value: 0
      },
      {
        time: '4:00',
        value: 0
      },
      {
        time: '6:00',
        value: 0
      },
      {
        time: '8:00',
        value: 0
      },
      {
        time: '10:00',
        value: 0
      },
      {
        time: '12:00',
        value: 0
      },
      {
        time: '14:00',
        value: 0
      },
      {
        time: '16:00',
        value: 0
      },
      {
        time: '18:00',
        value: 0
      }
    ]
  },
  xField: 'time',
  yField: 'value',
  axes:[
    {
      orient: 'left',
      zero: true,
    }
]
};

结果展示 Results

在线效果参考:https://codesandbox.io/s/data-is-all-0-smhq6h

image.png

相关文档 Related Documentation

基础折线图demo:https://www.visactor.io/vchart/demo/line-chart/basic-line

坐标轴教程:https://www.visactor.io/vchart/guide/tutorial_docs/Chart_Conc...

相关api:https://www.visactor.io/vchart/option/lineChart-axes-linear#zero

github:https://github.com/VisActor/VChart

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进