-1

here is my code tooltip gives correct values but graph is not correct

Highcharts.chart('container5', {
    chart: {
        type: 'column'
    },
    title: {
        text: 'Sleep Graph'
    },
    xAxis: {
        categories: ['Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday', 'Monday', 'Tuesday', ]
    },
    yAxis: {
            title: {
                text: 'Data-Time'
            },
            type: 'datetime',
            dateTimeLabelFormats: {
              minute: '%H:%M:%S',
              hour: '%H:%M:%S',
              day: '%H:%M:%S',
              week: '%H:%M:%S',
              month: '%H:%M:%S',
              year: '%H:%M:%S'             
            },            
            // labels: {
            //   format: '{value:%Y-%b-%e}'
            // },
            min : Date.UTC(2017,0,1,18,0),
        },
    tooltip: {
        formatter: function() {
                return '<b>'+ this.series.name +'</b><br/>'+
                Highcharts.dateFormat('%H:%M:%S', this.y) +': '+ this.x;
        }
    },
    plotOptions: {
        column: {
            stacking: 'normal',
            dataLabels: {
                enabled: false,
                color: (Highcharts.theme && Highcharts.theme.dataLabelsColor) || 'white'
            }
        }
    },
    series: [{
        name: 'Awake',
        data: [Date.UTC(2017,0,2,09,30), Date.UTC(2017,0,2,10,00), Date.UTC(2017,0,2,07,30), Date.UTC(2017,0,2,07,30), Date.UTC(2017,0,2,09,30), Date.UTC(2017,0,2,10,00), Date.UTC(2017,0,2,08,00), ],  
    }, {
        name: 'Sleep',
        data: [Date.UTC(2017,0,2,08,20), Date.UTC(2017,0,2,08,20), Date.UTC(2017,0,2,06,15), Date.UTC(2017,0,2,06,15), Date.UTC(2017,0,2,08,25), Date.UTC(2017,0,2,08,10), Date.UTC(2017,0,2,06,35), ],
    }, {
        name: 'Bed Time',
        data: [Date.UTC(2017,0,1,21,00), Date.UTC(2017,0,1,20,00), Date.UTC(2017,0,1,22,00), Date.UTC(2017,0,1,19,00), Date.UTC(2017,0,1,20,00), Date.UTC(2017,0,1,22,00), Date.UTC(2017,0,1,21,00), ],
    }    
    ]
});

enter image description here

Rob
  • 2,243
  • 4
  • 29
  • 40
Muhammad Rohail
  • 265
  • 4
  • 14

2 Answers2

0

You should mention pointStart and point Interval There is some thing wrong here

data: [Date.UTC(2017,0,2,09,30), Date.UTC(2017,0,2,10,00), Date.UTC(2017,0,2,07,30), Date.UTC(2017,0,2,07,30), Date.UTC(2017,0,2,09,30), Date.UTC(2017,0,2,10,00), Date.UTC(2017,0,2,08,00), ], 

This example might help you. http://jsfiddle.net/gh/get/jquery/2/highcharts/highcharts/tree/master/samples/highcharts/xaxis/datetimelabelformats/

Asmarah
  • 134
  • 8
0

Your values are timestamps (number of miliseconds from 01.01.1970 00:00 UTC). Highcharts stacking mechanism makes a sum from all the points that have the same x value - so in this case it adds timestamps. That's why when you comment out dateTimeLabelFormats code section you'll get values like 2060 on your y axis.

This code:

var d1 = Date.UTC(2017, 0, 1),
  d2 = Date.UTC(2017, 0, 2),
  format = '%Y.%m.%d %H:%M  ';
console.log(Highcharts.dateFormat(format, d1), Highcharts.dateFormat(format, d2), Highcharts.dateFormat(format, d1 + d2));

Outputs:

2017.01.01 00:00   2017.01.02 00:00   2064.01.03 00:00  

type: 'datetime' is just an information for Highcharts how to format labels - all computing is performed on timestamps (which are 'regular' integer numbers).

Possible solution

You can disable grouping instead of using stacking:

  plotOptions: {
    column: {
      //stacking: 'normal',
      grouping: false
    }
  }

Live working example: http://jsfiddle.net/kkulig/7xkt2p0e/

API reference: https://api.highcharts.com/highcharts/plotOptions.column.grouping

Kamil Kulig
  • 5,756
  • 1
  • 8
  • 12