如何在高图表的X轴中设置每周范围?

时间:2017-03-11 18:49:44

标签: javascript html charts highcharts

我有一张图表,我需要将X轴设置为每周范围。 从1月 - 3月开始。如何将X间隔设置为7天范围?

我需要的是每7天出现一次的要点。厌倦了几种方式,但似乎没有用。我已经附上了迄今为止所做的一切。

Highcharts.chart('container', {
    title: {
        text: 'Fee Collected'
    },

    subtitle: {
        text: 'Actual Vs Budget'
    },

    yAxis: {
        title: {
            text: '%'
        },
         min: 80,
         max:120   
    },
xAxis: {
        type: 'datetime',
        labels: {
            style: {
                fontFamily: 'Tahoma'
            },
            rotation: -45
        },
        tickInterval: 24 * 3600 * 1000
    },
    legend: {
        layout: 'vertical',
        align: 'right',
        verticalAlign: 'middle'
    },

    plotOptions: {
        series: {
            pointStart: 0
        }
    },

    series: [{
        data: [88,90,88,96,97,105,106,110,118],
        pointStart: Date.UTC(2010, 0, 1),
        pointInterval: 24 * 3600 * 1000 // one day
    }]

});
#container {
	min-width: 310px;
	max-width: 800px;
	height: 400px;
	margin: 0 auto
}
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>

<div id="container"></div>

1 个答案:

答案 0 :(得分:0)

tickPositionertickInterval: 24 * 3600 * 1000 * 7七天

Highcharts.chart('container', {
  title: {
    text: 'Fee Collected'
  },

  subtitle: {
    text: 'Actual Vs Budget'
  },

  yAxis: {
    title: {
      text: '%'
    },
    min: 80,
    max: 120
  },
  xAxis: {
    type: 'datetime',
    labels: {
      style: {
        fontFamily: 'Tahoma'
      },
      rotation: -45
    },
    tickInterval: 24 * 3600 * 1000 * 7,
    /*seven days*/
    tickPositioner: function(min, max) {
      var interval = this.options.tickInterval,
        ticks = [],
        count = 0;

      while (min < max) {
        ticks.push(min);
        min += interval;
        count++;
      }

      ticks.info = {
        unitName: 'day',
        count: 7,
        higherRanks: {},
        totalRange: interval * count
      }


      return ticks;
    }

  },
  legend: {
    layout: 'vertical',
    align: 'right',
    verticalAlign: 'middle'
  },

  plotOptions: {
    series: {
      pointStart: 0
    }
  },

  series: [{
    data: [88, 90, 88, 96, 97, 105, 106, 110, 118],
    pointStart: Date.UTC(2009, 0, 1),
    pointInterval: 24 * 3600 * 1000 * 7 // seven days
  }]

});
#container {
  min-width: 310px;
  max-width: 800px;
  height: 400px;
  margin: 0 auto
}
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>

<div id="container"></div>