【问题标题】:Highcharts: Logarithmic y-axis with seconds, minutes, hours and daysHighcharts:对数 y 轴,带秒、分、小时和天
【发布时间】:2018-01-04 16:10:11
【问题描述】:

我想在 Highchart 图表的y-axis 上显示时间值的数据。这些时间值可以从 10 秒到 10 天不等

目前我可以像这样设置 y 轴类型:

yAxis: {
  type: 'logarithmic'
}

然后得到一些看起来像这样的东西:

使用对数时间刻度的最佳方式是什么,而不是只显示分钟,显示秒、分钟、小时和天

类似:10 秒、30 秒、1 分钟、2 分钟、5 分钟、10 分钟、30 分钟、1 小时、2 小时、4 小时、8 小时、1 天、2 天、5 天、10 天.我知道这不完全是对数级数,但希望你能明白我的意思。

【问题讨论】:

    标签: javascript highcharts logarithm


    【解决方案1】:

    这个话题请参考我的第一篇文章(Highcharts官方论坛):https://forum.highcharts.com/highstock-usage/chart-customisation-t39677/?hilit=logarithmic#p137385

    我在那里解释了如何连接对数轴和日期时间输入。

    我简化了原来的demo并根据您的需要进行了调整:http://jsfiddle.net/kkulig/5Ldowjbr/

    在这种情况下,x 轴是对数的(不是 y):

      yAxis: [{
        type: 'logarithmic',
        showFirstLabel: false,
        labels: {
          formatter: function() {
            return Highcharts.dateFormat("%Hh %Mm %Ss", this.value + baseline - timeOffset);
          }
        }
      }],
    

    我还将日期的显示格式更改为%Hh %Mm %Ss,并将点的timestamp 属性重命名为miliseconds

    【讨论】:

    • 在我的情况下,y 轴不是 dateTime 轴,所以这种方法对我不起作用。不过,这可能对其他人有所帮助
    【解决方案2】:

    Moment.js 救援:

    yAxis: {
      type: 'logarithmic',
      labels: {
        formatter: function () {
          return moment.duration(this.value, 'minutes').humanize()
        }
      }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-10-01
      • 1970-01-01
      • 1970-01-01
      • 2013-11-17
      • 1970-01-01
      • 1970-01-01
      • 2012-01-06
      相关资源
      最近更新 更多