Skip to content Skip to sidebar Skip to footer

Displaying Persian Dates In Highchart From Its Corresponding Georgian Date

Can we use Gregorian dates together with a Georgian to Persian date converter script to show Persian dates in Highchart and Highstock?

Solution 1:

Then better way to override date formating is to use Highcharts.dateFormats (and persianDate library), This allows conversion of all dates (not x or y axis) to Persian calendar.

Sample: http://jsfiddle.net/smpaB/1/

Highcharts with persian date

Add pesianDate library with:

<scriptsrc="http://rawgithub.com/babakhani/PersianDate/master/dist/persian-date.min.js"></script>

And configure highcharts with:

Highcharts.dateFormats = {
    'a': function(ts){returnnewpersianDate(ts).format('dddd')},
    'A': function(ts){returnnewpersianDate(ts).format('dddd')},
    'd': function(ts){returnnewpersianDate(ts).format('DD')},
    'e': function(ts){returnnewpersianDate(ts).format('D')},
    'b': function(ts){returnnewpersianDate(ts).format('MMMM')},
    'B': function(ts){returnnewpersianDate(ts).format('MMMM')},
    'm': function(ts){returnnewpersianDate(ts).format('MM')},
    'y': function(ts){returnnewpersianDate(ts).format('YY')},
    'Y': function(ts){returnnewpersianDate(ts).format('YYYY')},
    'W': function(ts){returnnewpersianDate(ts).format('ww')}
};

Solution 2:

I developed a Jalali Date library, JDate, that is compatible with original javascript Date class. Dates in highchart/highstock charts can be converted to Jalali by replacing window.Date with JDate. With this method all date outputs is converted to jalali calendar, And also, date input features (like YTD feature, or range selector) works with jalali calendar.

Demo: https://tahajahangir.github.io/jdate/jalali-highcharts-demo.htmlJalali date support for highcharts

The main part of script in above demo, is:

<scriptsrc="//raw.githack.com/tahajahangir/jdate/master/jdate.min.js"></script><script>window.Date = JDate;
    Highcharts.setOptions({
        lang: {
            months: ['فروردين', 'ارديبهشت', 'خرداد', 'تیر', 'مرداد', 'شهریور', 'مهر', 'آبان', 'آذر', 'دی', 'بهمن', 'اسفند'],
            shortMonths: ['فروردين', 'ارديبهشت', 'خرداد', 'تیر', 'مرداد', 'شهریور', 'مهر', 'آبان', 'آذر', 'دی', 'بهمن', 'اسفند'],
            weekdays: ["یکشنبه", "دوشنبه", "سه شنبه", "چهارشنبه", "پنج‌شنبه", "جمعه", "شنبه"]
        }
    });
</script>

Solution 3:

I borrowed this js script and tried it out here. Not sure if that is what you are after though.

enter image description here

Solution 4:

You can use it babakhani persian date js for example:


xAxis: {
                    type: 'datetime',
                    labels: {
                        formatter: function () {
                            var date = newDate(this.value);
                            var pdate = persianDate(date);
                            return (pdate.pDate.year - 1300) + "/" + pdate.pDate.month;
                        }
                    }
                }

Solution 5:

Update for 2 first answer

<scriptsrc="http://code.highcharts.com/highcharts.js"></script><scriptsrc="https://cdn.jsdelivr.net/npm/persiandate@0.2.1/dist/persiandate.min.js"></script><divid="container"style="height: 400px"></div>
var chart = newHighcharts.Chart({
    chart: {
        renderTo: 'container'
    },
    xAxis: {        
        type: 'datetime',
        labels: {
            formatter: function() {
                var someDate = newDate(this.value);
                returnpersianDate(someDate).format('YYYY-MMMM-D');
            }
        }
    },
    
    
    
    series: [{
        data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4],
        pointStart: Date.UTC(2010, 0, 1),
        pointInterval: 24 * 3600 * 1000// one day
    }]
});```

Post a Comment for "Displaying Persian Dates In Highchart From Its Corresponding Georgian Date"