Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set PointIntervals per month in HighChart

I used HighCharts to plot number of users created on a monthly basis. I managed to show month in x-axis and i set pointInterval as below

pointInterval :24 * 3600 * 1000 * 31

But this was given blindly and it won't plot points correctly. I need to plot points 1st of every month. But the above interval helps to bind points on monthly basis not at the 1st day of month. This example describes my issue. Tooltip gives the clear idea. Here is my code

series: [{
        type: 'area',
        name: 'CDP Created',
        pointInterval: 24 * 3600 * 1000 * 31,
        pointStart: Date.UTC(2005, 0, 01),          
        dataGrouping: {
            enabled: false
        },
        data: [0, 0, 0, 0, 0, 0, 0, 148.5, 216.4, 194.1, 95.6, 54.4]

    }]

Is there anyway to set pointInterval depends on month. Because if i simply given pointInterval as above it will calculate every 31 days. This creates problem when the month has 28 or 30 days. How to acheive it. Also adjusting the width of the container div makes x-axis values not displaying properly. Thanks in advance

like image 749
Satheesh Avatar asked Jul 31 '13 06:07

Satheesh


1 Answers

The other answers to this are out of date.

Now all you need to do is add the pointIntervalUnit property. You can combine this with pointInterval to draw irregular intervals :

Highcharts.chart('container', {

...

plotOptions: {
    series: {
        pointStart: Date.UTC(2015, 0, 1),
        pointIntervalUnit: 'month'
    }
},
...

See: https://api.highcharts.com/highcharts/plotOptions.series.pointInterval

Also: https://jsfiddle.net/gh/get/library/pure/highcharts/highcharts/tree/master/samples/highcharts/plotoptions/series-pointintervalunit/

like image 96
Robbie Avatar answered Oct 28 '22 05:10

Robbie