Changing X axis type from category to datetime on drilldown

浪尽此生 提交于 2019-12-31 02:45:09

问题


Is it possible to change a graph's x axis type from category to datetime on drilldown? I have stacked column style graph where each column is a different category. When I click on one of the columns I want to drilldown to a dedicated column graph of that category with a datetime x axis.

I have been able to successfully drilldown to another category style graph, and set each category to a day in a daterange, but using the datetime format would be much better.

Here is the "onClick" code I am running to try to do this. Obviously the data is sample data just to keep things simple. Currently, this crashes Firefox with a memory limit.

Is it even possible to switch x axis type dynamically like this?

function setChart() {



    while(hChart.series.length > 0){
        hChart.series[0].remove();
    }


    hChart.xAxis[0].update({
        type: 'datetime'
    });

    console.log(hChart.xAxis[0]);


    data = [
            [Date.UTC(2010, 0, 1), 5],
            [Date.UTC(2010, 0, 2), 11],
            [Date.UTC(2010, 0, 3), 3],
            [Date.UTC(2010, 0, 6), 7],
            [Date.UTC(2010, 0, 7), 4],
            [Date.UTC(2010, 0, 8), 1]
    ];
    console.log(data);



    hChart.addSeries({
       type: 'column',
      data: data,
    }, false);

    hChart.redraw();
}

回答1:


Unforunately this option is not avaialble, you need to destroy and create new chart.




回答2:


For someone still looking for answer. The solution is:

Define X-axis in an array:

xAxis: [{
          id: 0,
          type: 'category'
        }, {
          id: 1,
          type: 'datetime'
        }]

For each series in drilldown

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


来源:https://stackoverflow.com/questions/18234418/changing-x-axis-type-from-category-to-datetime-on-drilldown

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!