Search code examples
amchartsamcharts4

shown dateaxis by all datetime not hour in amcharts4


Im tired to try all paramter in dateAxis but it shown label date hour part

var dateAxis = chart.xAxes.push(new am4charts.DateAxis());
dateAxis.renderer.minGridDistance = 20;
dateAxis.renderer.grid.template.location = 0.5;
dateAxis.startLocation = 0.5;
dateAxis.endLocation = 0.5;
dateAxis.dateFormats.setKey("day", "YYYY/MM/dd hh:mm");
dateAxis.tooltipDateFormat = "YYYY/MM/dd HH:mm";
// Setting up label rotation
dateAxis.renderer.labels.template.rotation = 45;

image hown just hour in lable


Solution

  • You are setting format for a "day", while your DateAxis is in "hour" mode. You need to set it for that. While you're at it make sure you set for period change as well:

    dateAxis.dateFormats.setKey("hour", "YYYY/MM/dd hh:mm");
    dateAxis.periodChangeDateFormats.setKey("hour", "YYYY/MM/dd hh:mm");
    

    Make sure your read this about formats on DateAxis.