highchartspersian

how to change highstock date to persian date


I'm using highcharts. I'm trying to change its date to Persian but since it is using Date.UTC I can not change it!

I've seen the http://api.highcharts.com/highstock#lang but it seems that it doesn't support persian.

Do you know any way to change it into persian date? One method I can come across with is the algorithm that changes UTC date to Persian date.

Is there any way to solve this problem? Please help me...

Thank you


Solution

  • You will have to do a bit of work to get this into highcharts.

    Firstly, convert the Date to Persian, using javascript's native API:
    new Date().toLocaleDateString('fa-IR')

    Secondly, you need to customise the highcharts date formatting. Highcharts provides an API to do this:
    https://api.highcharts.com/highcharts/data.dateFormat

    You need to use the dateFormats hook to add a %P option to the date format string which prints in persian format using the javascript library you choose. Once you have defined a %P format, you can customise the date formats to be used on the x-axis: http://api.highcharts.com/highcharts#xAxis.dateTimeLabelFormats

    {
    second: '%H:%M:%S',
    minute: '%H:%M',
    hour: '%H:%M',
    day: '%P',
    week: '%P',
    month: '%P',
    year: '%P'
    } 
    

    Note, you can define several dateFormat parameters, not just %P, to handle days, months etc.