HighChart:动态添加xaxis不会考虑我给它的类型

HighChart: Add xaxis dynamically doesn't consider what type I give it

本文关键字:类型 动态 添加 xaxis HighChart      更新时间:2023-09-26

我正在尝试动态添加一个x轴:

         $('#highchartcontainer').highcharts().addAxis({
                id: i,
                title: {
                    text: tag.name,
                    style: {
                        color: color
                    }
                },
                xAxis: {
                    type: 'datetime',
                },
                lineWidth: 1,
                lineColor: color}, true);

裁判:http://api.highcharts.com/highcharts Chart.addAxis

但是当它开始绘制时,我得到了这个奇怪的数字,如图所示:https://i.stack.imgur.com/OQya6.jpg

如何将新添加的轴改为datetime?

似乎我通过将typexAxis中移出来解决了这个问题

    $('#highchartcontainer').highcharts().addAxis({
            id: i,
            title: {
                text: tag.name,
                style: {
                    color: color
                }
            },
            type: 'datetime',
            lineWidth: 1,
            lineColor: color}, true);

进一步说明:

设置代码的方式相当于在另一个xAxis对象中嵌套xAxis对象,并将type属性应用于子对象。

在options对象中发送的所有属性都自动包装在创建的xAxis对象中-嵌套另一个是不必要的,也是无效的。

所以,你发送的选项就像在你的主配置中这样做:

xAxis: {
  xAxis: {
    type: 'datetime',
  },
  id: i,
  title: {
    text: tag.name,
    style: {
      color: color
    }
  },
  ineWidth: 1,
  lineColor: color
}

不行