0

I am trying to show past 3 month with year in the y axis value in highcharts. but it is not working it is coming like 0 1 2 3 4...

I want to show like ( Apr 2023 May 2023 Jun 2023) in the x axis.

   xAxis: {
  type: 'year',
  dateTimeLabelFormats: {
    // do display the month and year
    month: '%b %y',
    year: '%Y',
  },
  },

Demo : https://stackblitz.com/edit/highcharts-cloning-barchart-wpj4ti?file=src%2Fapp%2Fapp.component.ts

EMahan K
  • 417
  • 1
  • 19

1 Answers1

1

You should use xAxis.type: 'datetime' and xAxis.dateTimeLabelFormats set to month: '%b %Y'. Besides that, you need to also define x values as a timestamp or alternatively set pointStart and pointInterval options.

Demo: https://stackblitz.com/edit/highcharts-cloning-barchart-npvldx?file=src%2Fapp%2Fapp.component.ts

API References: https://api.highcharts.com/highcharts/xAxis.type https://api.highcharts.com/highcharts/xAxis.dateTimeLabelFormats

magdalena
  • 2,657
  • 1
  • 7
  • 12
  • You have used like pointStart: Date.UTC(2023, 3, 1) for 2023. So, What happened for next year. Every year i want to update the year in the code ?? – EMahan K Jul 17 '23 at 16:59
  • It all depends on your requirements and data that you represent on the chart. This is an example only, but if you want, e.g. get the current year, you can achieve it by JS Date() object and it's methods, as follows: https://stackblitz.com/edit/highcharts-cloning-barchart-adiosw?file=src%2Fapp%2Fapp.component.ts – magdalena Jul 18 '23 at 08:58
  • Can you answer this : 76774162 – EMahan K Jul 26 '23 at 18:48