【问题标题】:Is there any way to merge this two x-axis in one axis?有没有办法将这两个 x 轴合并到一个轴上?
【发布时间】:2016-12-20 13:18:59
【问题描述】:

我正在尝试将两个 x 轴合并到一个轴上。

我有两个不同的系列,它们之间的区别在于时间(有时以秒为单位,有时以分钟为单位)

这是我的代码:

var chart = new Highcharts.Chart({
chart:{
  renderTo:'chart',
  zoomType: 'xy',
  type:'line'
},
title: {
  text: '',
  x: -20
},
subtitle:{
  text:'',
  x: -20
},
xAxis:[{
  id:0,
  type:'categories',
  categories:finalarray.time1
},
{
  id:1,
  type:'categories',
  categories:finalarray.time2,
}],
yAxis:{
    title:{
      text:'',
      align:'high'
    },
    labels:{
      overflow:'justify'
    }
  },
  tooltip:{
    crosshairs: [{
      width: 1,
      color: 'red'
    }, true],
    valueSuffix: ''
  },
  plotOptions:{
    series:{
      cursor:'pointer'
    },
    line:{
      dataLabels:{
        enabled:true
      }
    }
  },
  credits:{
    enabled:false
  },
  series:[
    {
      xAxis:0,
      name: finalarray.description1 + " ( " + finalarray.unit1 + " ) ",
      data: finalarray.value1
    },
    {
      xAxis:1,
      name: finalarray.description2 + " ( " + finalarray.unit2 + " ) ",
      data: finalarray.value2
    }
  ]
  });

【问题讨论】:

  • 这个问题没有正确提出。请参考:stackoverflow.com/help/how-to-ask。您甚至没有费心去完成 2 分钟的实地考察,这一事实看起来也很糟糕。
  • 你想如何合并坐标轴?

标签: javascript highcharts


【解决方案1】:

要仅使用一个xAxis,请将轴类型设置为datetime,并使用数据x 值作为时间戳:

Highcharts.chart('container', {
    xAxis: {
        type: 'datetime',
        tickInterval: 5 * 60 * 1000
    },

    series: [{
        data: [
            {x: 1547480600, y: 12},
            {x: 1547540600, y: 21},
            {x: 1547600600, y: 9},
            {x: 1547660600, y: 37}
        ]
    }, {
        data: [
            {x: 1547480600, y: 9},
            {x: 1547535600, y: 2},
            {x: 1547590600, y: 29},
            {x: 1547645600, y: 41}
        ]
    }]
});

现场演示:http://jsfiddle.net/BlackLabel/9c2zba74/

【讨论】:

    猜你喜欢
    • 2021-06-06
    • 2017-12-11
    • 2021-11-01
    • 1970-01-01
    • 2020-06-19
    • 1970-01-01
    • 2023-04-02
    • 2021-05-30
    • 1970-01-01
    相关资源
    最近更新 更多