Javascript 谷歌分析:绘制一年中的一周数据,x轴显示完整日期,y轴显示访问量

Javascript 谷歌分析:绘制一年中的一周数据,x轴显示完整日期,y轴显示访问量,javascript,graph,google-analytics,flot,Javascript,Graph,Google Analytics,Flot,我试图在我的网站的管理端绘制一组谷歌分析图。我正在使用javascript api获取数据,并使用它绘制图形 我的问题是,我必须显示y轴访问(数字)与x轴一年中的一周 我可以让图表绘制,但我需要标签以月/日/年的格式显示日期,但要以周为单位绘制点 如果我按日期查询,我会得到每天不需要的数据。如果我按周查询,就不能得到完整的日期 请帮我解答这个问题 我当前的Google Analytics API调用: // Use the Analytics Service Object to query th

我试图在我的网站的管理端绘制一组谷歌分析图。我正在使用javascript api获取数据,并使用它绘制图形

我的问题是,我必须显示y轴访问(数字)与x轴一年中的一周

我可以让图表绘制,但我需要标签以月/日/年的格式显示日期,但要以周为单位绘制点

如果我按日期查询,我会得到每天不需要的数据。如果我按周查询,就不能得到完整的日期

请帮我解答这个问题

我当前的Google Analytics API调用:

// Use the Analytics Service Object to query the Core Reporting API
gapi.client.analytics.data.ga.get({
    'ids': 'ga:' + profileId,
    'dimensions':'ga:year,ga:month,ga:week',
    'start-date': '2013-03-03',
    'end-date': '2014-01-23',
    'metrics': 'ga:visits'
}).execute(handleCoreReportingResults);
我的Flot.js代码:

var coordinated =[["2013", "03", "10", "0"], ["2013", "03", "11", "0"], ["2013", "03", "12", "0"], ["2013", "03", "13", "0"], ["2013", "03", "14", "0"], ["2013", "04", "14", "0"], ["2013", "04", "15", "0"], ["2013", "04", "16", "0"], ["2013", "04", "17", "0"], ["2013", "04", "18", "0"], ["2013", "05", "18", "0"], ["2013", "05", "19", "0"], ["2013", "05", "20", "0"], ["2013", "05", "21", "0"], ["2013", "05", "22", "0"], ["2013", "06", "22", "0"], ["2013", "06", "23", "0"], ["2013", "06", "24", "0"], ["2013", "06", "25", "0"], ["2013", "06", "26", "0"], ["2013", "06", "27", "0"], ["2013", "07", "27", "0"], ["2013", "07", "28", "0"], ["2013", "07", "29", "0"], ["2013", "07", "30", "0"], ["2013", "07", "31", "29"], ["2013", "08", "31", "247"], ["2013", "08", "32", "647"], ["2013", "08", "33", "609"], ["2013", "08", "34", "589"], ["2013", "08", "35", "617"], ["2013", "09", "36", "697"], ["2013", "09", "37", "793"], ["2013", "09", "38", "665"], ["2013", "09", "39", "673"], ["2013", "09", "40", "214"], ["2013", "10", "40", "504"], ["2013", "10", "41", "648"], ["2013", "10", "42", "544"], ["2013", "10", "43", "564"], ["2013", "10", "44", "389"], ["2013", "11", "44", "170"], ["2013", "11", "45", "510"], ["2013", "11", "46", "558"], ["2013", "11", "47", "548"], ["2013", "11", "48", "580"], ["2013", "12", "49", "513"], ["2013", "12", "50", "533"], ["2013", "12", "51", "531"], ["2013", "12", "52", "677"], ["2013", "12", "53", "296"], ["2014", "01", "01", "386"], ["2014", "01", "02", "634"], ["2014", "01", "03", "633"], ["2014", "01", "04", "498"]];
var sin = []

for (var i = 0; i < coordinated.length; i++) {
    sin.push([ (new Date(coordinated[i][0]+"/"+coordinated[i][2]+'/'+coordinated[i][2]).getTime()), coordinated[i][3]]);
}

var plot = $.plot($(".chart"),
       [ { data: sin, label: "Visits"} ], {
           series: {
               lines: { show: true },
               points: { show: true }
           },
           grid: { hoverable: true, clickable: true },
           //yaxis: { min: 0, max: 1000 },
           xaxis: { 
            //min:(new Date(sin[0][3])).getTime(), max: (new Date(sin[sin.length-1][4])).getTime(), 
            mode: "time", timeformat: "%m/%d/%y", 
            minTickSize: [1, "day"], 
            tickSize: [1, "month"] },

         });
var协调=[“2013”、“03”、“10”、“0”]、[“2013”、“03”、“11”、“0”]、[“2013”、“03”、“13”、“0”]、[“2013”、“03”、“13”、“0”]、[“2013”、“03”、“14”、“0”]、[“2013”、“04”、“14”、“0”]、[“2013”、“04”、“15”、“0”]、[“2013”、“04”、“04”、“16”、“0”]、[“2013”、“04”、“17”、“0”、[“2013”、“04”、“18”、“0”]、[“2013”、“05”、“18”、“0”]、[“2013”、“05”、“0”、[“0”]["2013", "05", "20", "0"], ["2013", "05", "21", "0"], ["2013", "05", "22", "0"], ["2013", "06", "22", "0"], ["2013", "06", "23", "0"], ["2013", "06", "24", "0"], ["2013", "06", "25", "0"], ["2013", "06", "26", "0"], ["2013", "06", "27", "0"], ["2013", "07", "27", "0"], ["2013", "07", "28", "0"], ["2013", "07", "29", "0"], ["2013", "07", "30", "0"], ["2013", "07", "31", "29"], ["2013", "08", "31", "247"], ["2013", "08", "32", "647"], ["2013", "08", "33", "609"], ["2013", "08", "34", "589"], ["2013", "08", "35", "617"], ["2013", "09", "36", "697"], ["2013", "09", "37", "793"], ["2013", "09", "38", "665"], ["2013", "09", "39", "673"], ["2013", "09", "40", "214"], ["2013", "10", "40", "504"], ["2013", "10", "41", "648"], ["2013", "10", "42", "544"], ["2013", "10", "43", "564"], ["2013", "10", "44", "389"], ["2013", "11", "44", "170"], ["2013", "11", "45", "510"], ["2013", "11", "46", "558"], ["2013", "11", "47", "548"], ["2013", "11", "48", "580"], ["2013", "12", "49", "513"], ["2013", "12", "50", "533"], ["2013", "12", "51", "531"], ["2013", "12", "52", "677"], ["2013", "12", "53", "296"], ["2014", "01", "01", "386"], ["2014", "01", "02", "634"], ["2014", "01", "03", "633"], ["2014", "01", "04", "498"]];
var sin=[]
对于(变量i=0;i
此代码后面的视图:

我需要帮助。我真的很感激!

我让它工作了

我将for循环更改为

for (var i = 0; i < coordinated.length; i++) {
    var myDate = new Date(coordinated[i][0],0,1);
    var newDate = myDate.getDate() + (coordinated[i][2] * 7);
    myDate.setDate(newDate);
    sin.push([myDate.getTime(), coordinated[i][3]]);
}
for(变量i=0;i
现在它开始工作了

我得到并想要的输出: