图表以周间隔显示当月数据

时间:2018-09-27 04:27:49

标签: javascript jquery highcharts

我正在使用highchart折线图以每周间隔显示当月数据。 但是图表线没有显示 这是我的代码:

    $(function () {
    $('#container').highcharts({
        chart: {
            type: 'line'
        },
        title: {
            text: 'Monthly Average Rainfall'
        },
        subtitle: {
            text: 'Source: WorldClimate.com'
        },
        xAxis: {
            type: 'datetime',
             min : Date.UTC(2015, 8, 1),
             max: Date.UTC(2015, 8, 30),
            dateTimeLabelFormats: {
                second: '%H:%M:%S',
                minute: '%H:%M',
                hour: '%H:%M',
                day: '%e. %b',
                week: '%e. %b',
                month: '%b \'%y',
                year: '%Y'
            },
            tickInterval: 7 * 24 * 3600 * 1000 // interval of 1 day
        },
         yAxis: [{ // left y axis
        title: {
            text: null
        },
        labels: {
            align: 'left',
            x: 3,
            y: 16,
            format: '{value:.,0f}'
        },
        showFirstLabel: false
    }, { // right y axis
        linkedTo: 0,
        gridLineWidth: 0,
        opposite: true,
        title: {
            text: null
        },
        labels: {
            align: 'right',
            x: -3,
            y: 16,
            format: '{value:.,0f}'
        },
        showFirstLabel: false
    }],
        tooltip: {
            headerFormat: '<span style="font-size:10px">{point.key}</span><table>',
            pointFormat: '<tr><td style="color:{series.color};padding:0">{series.name}: </td>' +
                '<td style="padding:0"><b>{point.y:.1f} mm</b></td></tr>',
            footerFormat: '</table>',
            shared: true,
            useHTML: true
        },
       legend: {
        align: 'left',
        verticalAlign: 'top',
        borderWidth: 0
    }, 

        /* plotOptions: {
            column: {
                pointPadding: 0,
                borderWidth: 0,
                groupPadding: 0.1,
                //pointStart: Date.UTC(2015, 1, 12) // feb 12, 2015
            }
        }, */

         plotOptions: {
        series: {
            cursor: 'pointer',
            point: {
                events: {
                    click: function (e) {
                        hs.htmlExpand(null, {
                            pageOrigin: {
                                x: e.pageX || e.clientX,
                                y: e.pageY || e.clientY
                            },
                            headingText: this.series.name,
                            maincontentText: Highcharts.dateFormat('%A, %b %e, %Y', this.x) + ':<br/> ' +
                                this.y + ' sessions',
                            width: 200
                        });
                    }
                }
            },
            marker: {
                lineWidth: 1
            }
        }
    },

        series: [{
            name: 'Tokyo',
            data: [49.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4],
            pointStart: Date.UTC(2015, 1, 12),
            pointInterval: 7 * 24 * 3600 * 1000 // interval of 1 day

        },
        {
            name: 'New York',
            data: [83.6, 78.8, 98.5, 93.4, 106.0, 84.5, 105.0, 104.3, 91.2, 83.5, 106.6, 92.3],
            pointStart: Date.UTC(2015, 1, 12),
            pointInterval: 7 * 24 * 3600 * 1000 // interval of 1 day

        }, {
            name: 'London',
            data: [48.9, 38.8, 39.3, 41.4, 47.0, 48.3, 59.0, 59.6, 52.4, 65.2, 59.3, 51.2],
            pointStart: Date.UTC(2015, 1, 12),
            pointInterval: 7 * 24 * 3600 * 1000 // interval of 1 day
        }, {
            name: 'Berlin',
            data: [42.4, 33.2, 34.5, 39.7, 52.6, 75.5, 57.4, 60.4, 47.6, 39.1, 46.8, 51.1],
            pointStart: Date.UTC(2015, 1, 12),
            pointInterval: 7 * 24 * 3600 * 1000 // interval of 1 day
        } 
]
    });
});

任何人都可以提出任何解决方案的建议,以周为单位在本月的折线图中显示点。我需要像这样的高图表示例https://www.highcharts.com/demo/line-ajax这样的星期间隔。

1 个答案:

答案 0 :(得分:1)

您已将tickInterval的{​​{1}}设置为从xAxisDate.UTC(2015, 8, 1)的7天,但是将Date.UTC(2015, 8, 30)的{​​{1}}设置为来自pointStart

因此,只需将series更改为Date.UTC(2015, 1, 12)

顺便说一句,pointStart是7天。

Date.UTC(2015, 8, 1)

7 * 24 * 3600 * 1000
(7 days * hours per day * seconds per hour * milliseconds per second)