簡體   English   中英

圖表以周間隔顯示當月數據

[英]HIghchart show current month data with week interval

我正在使用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
        } 
]
    });
});

誰能建議任何解決方案,以周間隔在當月的折線圖中顯示點。 我需要像這種highchart示例https://www.highcharts.com/demo/line-ajax這樣的星期間隔。

您已將xAxistickInterval設置為從Date.UTC(2015, 8, 1) Date.UTC(2015, 8, 30) Date.UTC(2015, 8, 1)Date.UTC(2015, 8, 30) Date.UTC(2015, 8, 1)開始的7天Date.UTC(2015, 8, 30)但是將seriespointStart設置為從Date.UTC(2015, 1, 12)

因此,只需將pointStart更改為Date.UTC(2015, 8, 1)

順便說一句, 7 * 24 * 3600 * 1000是7天。

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

 $(function() { $('#container').highcharts({ chart: { type: 'line' }, title: { text: 'Monthly Average Rainfall' }, subtitle: { text: 'Source: WorldClimate.com' }, xAxis: { type: 'datetime', gridLineWidth: 1, 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: [ [Date.UTC(2015, 8, 1), 49.9], [Date.UTC(2015, 8, 3), 71.5], [Date.UTC(2015, 8, 5), 106.4], [Date.UTC(2015, 8, 7), 129.2], [Date.UTC(2015, 8, 9), 144.0], [Date.UTC(2015, 8, 12), 176.0], [Date.UTC(2015, 8, 15), 135.6], [Date.UTC(2015, 8, 18), 148.5], [Date.UTC(2015, 8, 21), 216.4], [Date.UTC(2015, 8, 24), 194.1], [Date.UTC(2015, 8, 27), 95.6], [Date.UTC(2015, 8, 30), 54.4] ], }, { 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, 8, 1), 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, 8, 1), 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, 8, 1), pointInterval: 7 * 24 * 3600 * 1000 // interval of 1 day } ] }); }); 
 <script src="https://code.jquery.com/jquery-3.1.1.min.js"></script> <script src="https://code.highcharts.com/highcharts.js"></script> <div id="container" style="min-width: 310px; height: 400px; margin: 0 auto"></div> 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM