0

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

Gheeroppa
  • 59
  • 1
  • 9

2 Answers2

2

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").

Stéphane Laurent
  • 75,186
  • 15
  • 119
  • 225
1

You can also simply disable marking the unit changes with dateAxis.markUnitChange = false.

This property is used to apply the different formats defined in periodChangeDateFormats to the first label in bigger time unit, i.e.

  • when the resolution is monthly and a new year starts
  • when the resolution is weekly and a new months starts
  • when the resolution is hourly and a new day starts
  • etc.

(There is an exception for the daily resolution, where the period changes with the next months and not with the next week.)