简体   繁体   English

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

[英]HIghchart show current month data with week interval

I am using the highchart line graph to show the current month data in weekly interval. 我正在使用highchart折线图以每周间隔显示当前月份的数据。 But the chart lines not displayed Here is my code: 但是图表线没有显示这是我的代码:

    $(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
        } 
]
    });
});

Can any one please suggest any solution to show the points in line chart for current month with week interval. 谁能建议任何解决方案,以周间隔在当月的折线图中显示点。 I need the week interval like this highchart example https://www.highcharts.com/demo/line-ajax . 我需要像这种highchart示例https://www.highcharts.com/demo/line-ajax这样的星期间隔。

You have set the tickInterval of xAxis to 7 days starts from Date.UTC(2015, 8, 1) to Date.UTC(2015, 8, 30) but set the pointStart of the series starts from Date.UTC(2015, 1, 12) . 您已将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)

So simply change the pointStart to Date.UTC(2015, 8, 1) . 因此,只需将pointStart更改为Date.UTC(2015, 8, 1)

BTW, 7 * 24 * 3600 * 1000 is 7 days. 顺便说一句, 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