The granularity of Value axis labels depends on available space and some settings. Sometimes, when there’s enough space, and the range of values is not great, the axis will throw in intermediate non-integer values as labels. This tutorial will show how to hide those non-integer labels.
Let’s use this bar chart as an example:
Run * --------------------------------------------------------
* This demo was created using amCharts V4 preview release.
* V4 is the latest installement in amCharts data viz
* library family, to be released in the first half of
* For more information and documentation visit:
* https://www.amcharts.com/docs/v4/
* --------------------------------------------------------
am4core . useTheme ( am4themes_animated );
var chart = am4core . create ( " chartdiv " , am4charts . XYChart );
category: " Distribution " ,
var categoryAxis = chart . yAxes . push ( new am4charts . CategoryAxis ());
categoryAxis . dataFields . category = " category " ;
categoryAxis . renderer . grid . template . location = 0 ;
var valueAxis = chart . xAxes . push ( new am4charts . ValueAxis ());
valueAxis . renderer . minGridDistance = 30 ;
var series = chart . series . push ( new am4charts . ColumnSeries ());
series . dataFields . valueX = " value " ;
series . dataFields . categoryY = " category " ;
< div id = " chartdiv " ></ div >
-apple-system , BlinkMacSystemFont, " Segoe UI " , Roboto, Helvetica , Arial , sans-serif ,
" Apple Color Emoji " , " Segoe UI Emoji " , " Segoe UI Symbol " ;
hiding non-integer labels on value axis (1) hiding-non-integer-labels-on-value-axis-1
Even though our data is integer, we get a lot of non-integer labels, that might be throwing off the user.
Let’s see what we can do about it.
We are going to be using adapters to selectively remove non-integer labels.
Basically an adapter allows defining a custom function that will have a chance to modify a value or setting before it is used.
We can set one on our Value axis’ label template. It would need to check if the value is integer, and return empty text if it isn’t, effectively eliminating all non-integer labels.
valueAxis.renderer.labels.template.adapter.add("text", function(text, target) {
return text.match(/\./) ? "" : text;
valueAxis.renderer.labels.template.adapter.add("text", function(text, target) {
return text.match(/\./) ? "" : text;
"text": function(text, target) {
return text.match(/\./) ? "" : text;
Let’s check how our chart looks now:
Run * --------------------------------------------------------
* This demo was created using amCharts V4 preview release.
* V4 is the latest installement in amCharts data viz
* library family, to be released in the first half of
* For more information and documentation visit:
* https://www.amcharts.com/docs/v4/
* --------------------------------------------------------
am4core . useTheme ( am4themes_animated );
var chart = am4core . create ( " chartdiv " , am4charts . XYChart );
category: " Distribution " ,
var categoryAxis = chart . yAxes . push ( new am4charts . CategoryAxis ());
categoryAxis . dataFields . category = " category " ;
categoryAxis . renderer . grid . template . location = 0 ;
var valueAxis = chart . xAxes . push ( new am4charts . ValueAxis ());
valueAxis . renderer . minGridDistance = 30 ;
valueAxis . renderer . labels . template . adapter . add ( " text " , function ( text , target ) {
return text && text . match ( / \. / ) ? "" : text ;
// alternatively you can use maxPrecision:
// valueAxis.maxPrecision = 0;
var series = chart . series . push ( new am4charts . ColumnSeries ());
series . dataFields . valueX = " value " ;
series . dataFields . categoryY = " category " ;
< div id = " chartdiv " ></ div >
-apple-system , BlinkMacSystemFont, " Segoe UI " , Roboto, Helvetica , Arial , sans-serif ,
" Apple Color Emoji " , " Segoe UI Emoji " , " Segoe UI Symbol " ;
hiding non-integer labels on value axis (2) hiding-non-integer-labels-on-value-axis-2
Only integer labels.