Search code examples
amcharts

Amcharts4 XYChart remove space between container and chart data


I need to remove paddings/spaces between data visible on the XYChart.

I removed paddings from chart and tried to remove it from valueaxis and lineseries but nothing helped.

chart.padding(0, 0, 0, 0);

I also noticed that if I have more dates with values there is no space on the left and right. But what if there is less data, how to fix it.

https://codepen.io/lrobotka/pen/ZVdvyg


Solution

  • You need to set startLocation and endLocation on your DateAxis instance:

    var dateAxis = chart.xAxes.push(new am4charts.DateAxis());
    // Change this to 0.5
    dateAxis.renderer.grid.template.location = 0.5;
    // Add the following
    dateAxis.startLocation = 0.5;
    dateAxis.endLocation = 0.5;
    
    // Change the padding values
    chart.padding(0, 30, 0, 30);
    

    Please check more about setting where axis starts and ends here.