Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/445.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 显示错误月份的高位图表_Javascript_Highcharts - Fatal编程技术网

Javascript 显示错误月份的高位图表

Javascript 显示错误月份的高位图表,javascript,highcharts,Javascript,Highcharts,我目前正在使用HighCharts将一些数据嵌入到我的用户界面中,其中显示了过去7天的销售利润,以下是我目前使用的Javascript: function weeks_ago(date_object) { var d = new Date(); var newDate = d.setDate(d.getDate()-6); var date = new Date(newDate); return date.getDate(); }

我目前正在使用HighCharts将一些数据嵌入到我的用户界面中,其中显示了过去7天的销售利润,以下是我目前使用的Javascript:

function weeks_ago(date_object) {
        var d = new Date();
        var newDate = d.setDate(d.getDate()-6);
        var date = new Date(newDate);
        return date.getDate();
}

var d = new Date();

function createGraph(jsonObj) {
    $('#container').highcharts({
        credits: {
            enabled: false
        },
        chart: {
            type: 'line'
        },
        title: {
            text: 'Profit Graph'
        },
        subtitle: {
            text: 'Data from the past week'
        },
        xAxis: {
            type: "datetime",
               dateTimeLabelFormats: {
                    month: "%e. %b",
                    year: "%b"
                }
        },
        yAxis: {
            title: {
                text: 'Profit'
            },
            min: 0
        },
        tooltip: {
            formatter: function() {
                return '<span style="color:#33333;">'+this.series.name +': '+ Highcharts.numberFormat(this.y,0);
            }
        },
        series: [
            {
                name: 'Platform1',
                data: jsonObj.Platform1,
                pointStart: Date.UTC(d.getUTCFullYear(), d.getUTCMonth(), weeks_ago(new Date())),
                pointInterval: 24 * 3600 * 1000,
                color: '#55CCA2',
            }, {
                name: "Platform2",
                data: jsonObj.Platform2,
                pointStart: Date.UTC(d.getUTCFullYear(), d.getUTCMonth(), weeks_ago(new Date())),
                pointInterval: 24 * 3600 * 1000,
                color: '#3498db',
            }
        ]
    });
};
但不知为什么我的图表显示从10月30日到11月5日?数据点位置正确,只是xAxis标签错误。

您的函数weeks\u ago返回6天前的日期。但是当您设置pointStart时,您只设置日期,而不是月份和年份。因此,今天你有以下几点:

{"Platform1":[0,0,0,14580,105585,75410,19212],"Platform2":[0,0,0,0,0,0,0]}
Today: 2017 10 06
Today - 6 days = 2017 09 30
You set pointStart = Date.UTC(2017, 10, 30).
因此,如果您创建了返回月份和年份的新函数,则可以使其正常工作

或者将其更改为weeks_ago返回date对象,如下所示:

function weeks_ago(date_object) {
    var d = new Date();
    var newDate = d.setDate(d.getDate()-6);
    return new Date(newDate);
}

pointstart: Date.UTC(weeks_ago(new Date()).getUTCFullYear(),
                     weeks_ago(new Date()).getUTCMonth(), 
                     weeks_ago(new Date()).getDate())
在要调试的帖子中添加jsonObjissue@Deep3015jsonObj不是问题所在,它只是保存数据。我的问题是起点