Search code examples
javascriptreactjsamchartsamcharts4

amCharts (V4): first month format in DateAxis without year


In a XYChart I am trying to set on the x-Axes, the twelve months as lables, from Jan to Dec, but as shown in the picture, the first month has also the Year (yyyy).

let dateAxis = chart.xAxes.push(new am4charts.DateAxis());

How can I show just the name of the month, in this case, just "Jan" ?

DateAxis


Solution

  • You have to use dateFormats.setKey and periodChangeDateFormats.setKey to format the dates on a date axis; see this tuto.

    Here the smoking gun is periodChangeDateFormats. This option controls the formatting when a period changes (e.g. a new year when the scale is month). I have not tried but I think you need:

    dateAxis.dateFormats.setKey("month", "MMM"); // useless, this is the default
    dateAxis.periodChangeDateFormats.setKey("month", "MMM");
    

    while the default is dateAxis.periodChangeDateFormats.setKey("month", "MMM yyyy").