首页 > 解决方案 > 如何设置 Highcharts 图的最小开始日期?

问题描述

我有 10/19 到 11/01 的数据,我正在使用分散的 Highcharts 绘图(v4.1.10,无法升级)绘制它。出于某种原因,我的 x 轴显示 10/18,但我希望它从 10/19 开始。我尝试使用pointStart,但这不起作用。关于如何获得正确的开始日期以显示在我的 x 轴上的任何建议?

Highcharts.chart('container', {
    yAxis: {
    gridLineWidth: 0.5,
  gridLineColor: '#D6D6D6',
  tickInterval: 5,
  dashStyle: 'LongDash',
  lineColor: '#D6D6D6'
},
xAxis: {
    type: 'datetime',
    dateTimeLabelFormats: {
      day: '%m/%d',
      week: '%d/%b',
      month: '%b/%y',
      year: '%Y'
    },
    title: {
      enabled: true,
      text: 'date'
    },
    gridLineWidth: 0,
    lineColor: '#D6D6D6',
    lineWidth: 0.5,
    startOnTick: true
},
plotOptions: {
    scatter: {
      marker: {
        radius: 5,
        states: {
          hover: {
            enabled: true,
            lineColor: 'rgb(100,100,100)'
          }
        }
      },
      states: {
        hover: {
          marker: {
            enabled: false
          }
        }
      },
      tooltip: this.toolTip
    }
},
chart: {
    marginTop: 5,
    marginRight: 0,
    reflow: false,
    backgroundColor: 'rgba(255, 255, 255, 0.1)',
    style: {
      fontFamily: 'Open Sans'
    },
    type: 'scatter',
    spacingBottom: 0,
    spacingTop: 0,
    spacingLeft: 0,
    spacingRight: 0
},
tooltip: {
    formatter: function () {
        var s = '<b>' + Highcharts.dateFormat('%m/%d %H:%M:%S', this.x) 
        + ' - ' + Highcharts.numberFormat(this.y, 2);
        return s;
    },
},
series: values
});

jsfiddle代码在这里

标签: datechartshighcharts

解决方案


您可以设置 x 轴min值:

xAxis: {
    min:1539950400000

示例:http: //jsfiddle.net/jlbriggs/dwnx6o8e/9/

根据数据和其他选项,您可能需要查看其他属性,例如startOnTicktickInterval等。


推荐阅读