Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
242 views
in Technique[技术] by (71.8m points)

javascript - How to set weekly range in X Axis of High Chart?

I have a Chart where I need to set X axis to a weekly range. Starting from January - march.How can i set the X interval to 7 days range?

What I need is the points to appear every 7 days time period. Tired a few ways but it doesn't seem to work. I have attached what I've done so far.

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>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

tickPositioner and tickInterval: 24 * 3600 * 1000 * 7 for seven days

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>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...