DEV Community

FlyingAndFly
FlyingAndFly

Posted on

Can the VChart axis be set to avoid decimals?

Problem description

I am using a bar chart to describe the number of problems. There should be no decimal place in the circumstances. How to avoid the phenomenon of axis text appearing 0.5?

Solution

  • You can use the axes.tick.noDecimalsproperty to configure continuous axes without decimals
 axes: [
    {
      orient: 'left',
      tick:{
        noDecimals: true
      }
    }
  ],
Enter fullscreen mode Exit fullscreen mode

Code example

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;
Enter fullscreen mode Exit fullscreen mode

Results show

Related Documents

Image of Datadog

The Essential Toolkit for Front-end Developers

Take a user-centric approach to front-end monitoring that evolves alongside increasingly complex frameworks and single-page applications.

Get The Kit

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more