VChart 图表坐标轴能否设置不出现小数?

178 阅读1分钟

问题描述

使用柱状图描述问题数量,不存在小数个的情况,怎么避免轴文字出现 0.5 的现象?

解决方案

  • 可以通过 axes.tick.noDecimals 属性来配置连续轴不出现小数
 axes: [
    {
      orient: 'left',
      tick:{
        noDecimals: true
      }
    }
  ],

代码示例

const spec = {
  type: 'bar',
  data: [
    {
      id: 'barData',
      values: [
        { month: 'Monday', sales: 1 },
        { month: 'Tuesday', sales: 1 },
        { month: 'Wednesday', sales: 2 },
        { month: 'Thursday', sales: 0 },
        { month: 'Friday', sales: 1 }
      ]
    }
  ],
  axes:[{orient:"left", tick:{noDecimals: true}}],
  xField: 'month',
  yField: 'sales'
};

const vchart = new VChart(spec, { dom: CONTAINER_ID });
vchart.renderSync();

// Just for the convenience of console debugging, DO NOT COPY!
window['vchart'] = vchart;

结果展示

相关文档