Highcharts chart with 'datetime' xAxis - use categories on drilldown

后端 未结 2 1669
半阙折子戏
半阙折子戏 2021-01-06 08:11

Is there a way to have \'datetime\' for the xAxis type on the main series, but then when a series is clicked on, have the drilldown use categories for that time?

I

相关标签:
2条回答
  • 2021-01-06 08:40

    I have found a solution for your problem! Sebastian Bochan gave me some ideas. You need to separate xAxis and set a different type to each one. So, here you have to add your categories as Highcharts's way.

    xAxis: [{
             id: 0,
             type: 'datetime'
           },
           {
             id: 1,
             type: 'categories',
             categories: data.categories
           }
       ]
    

    Then you have to add this code in your serie to link it with your new Axis.

    drilldown: {
          series: [{
            name: "test",
            id: "test",
            xAxis: 1, // <--- your desired X axis ID
            data: [
              [your data]
            ]
          }]
        }
    

    Probably you'll see a small difference on bottom chart, but all works for me.

    I hope this help to you ;)

    0 讨论(0)
  • 2021-01-06 08:42

    You need to add this to your xAxis:

    labels: {
            formatter: function() {
                  return Highcharts.dateFormat('%a %d %b', this.value);
             }
    },
    

    Check out the fiddle.

    0 讨论(0)
提交回复
热议问题