highcharts tooltip wrong date

2020-03-27 02:33发布

I had made one highchart in that tooltip is shows date and time in format but it is showing wrong date and time.

Please go through the code below.

HTML Code

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="http://code.highcharts.com/highcharts.js"></script>
<script src="http://code.highcharts.com/modules/exporting.js"></script>
<div id="container" style="min-width: 310px; height: 400px; margin: 0 auto"></div>

Javascript Code

var maxval="94";
$(function () {
var chart;
$(document).ready(function() {
    chart = new Highcharts.Chart({

    credits: {
        enabled: false
    },  
    chart: {
        type: 'column',
        renderTo: 'container',
    },
    title: {
        text: 'Weekly Traffic'
    },
    xAxis: {
        type: 'datetime',
        labels: {
            format: '{value:%d-%b-%Y}',
            rotation:-45,
        },
    },

    yAxis: {
        labels:{enabled: false},
     title: {
              text: ''
           },
    }, 

          tooltip: {
                formatter: function() {
                        return '<b>'+ this.series.name +'</b><br/>'+': '+Highcharts.dateFormat('%Y-%m-%d %H:%M', this.x) +'<br>'+   Highcharts.numberFormat((this.y /maxval ) * 100) + '%';
                }
            },

    plotOptions: {
        line: {
         enableMouseTracking: false
        },

        series:{
         pointStart: 1444242600000,
        pointInterval: 86400000,
             shadow:false,
         dataLabels:{
            enabled:true,
            formatter:function()
                {
                var pcnt = (this.y /maxval ) * 100;
                return Highcharts.numberFormat(pcnt) + '%';
                }
            }
        }    
},

    series: [{
        name: 'Firefox',
        data: [10,56,32,12,64,13,38],
    },{
        name: 'Chrome',
        data: [52,59,10,60,94,3,8],
    },{
        name: 'Edge',
        data: [22,56,20,35,14,73,38],
    },{
        name: 'Opera',
        data: [30,36,80,65,44,53,81],
    },{
        name: 'Safari',
        data: [40,16,50,77,34,33,36],

    }],

    });

});

});

The working fiddle is given here.

1条回答
家丑人穷心不美
2楼-- · 2020-03-27 03:16

you need to set utc false in global option of highcharts.

 Highcharts.setOptions({
global: {
    useUTC: false
}
});

see Updated fiddle here

查看更多
登录 后发表回答