2

我有两个图表,它们是由 javascript 以完全相同的方式创建的,其中一个正确显示 x 轴上的值,另一个则没有。

这是交通图 在此处输入图像描述

如您所见,日期在 x 轴下正确显示,这是生成此图表的代码

function drawTrafficChart(processedData, humanReadableName, params) {
    dataArray = [];
    dataArrayRow = ['Date', 'Impressions', 'Detail Page Views'];
    dataArray.push(dataArrayRow);
    for (i in processedData) {
        dateString = processedData[i].date;
        dateString = formatDateStringAccordingToAggregationType(dateString, params);
        dataArrayRow = [dateString, processedData[i].event1, processedData[i].event2];
        dataArray.push(dataArrayRow);
    }

    var dataTable = google.visualization.arrayToDataTable(dataArray);
    var chartOptions = {
        title: 'Traffic Chart',
        hAxis: {title: humanReadableName},
        vAxis: {minValuex: 0},
        pointSize: 5,
        width: 670,
        height: 300
    };
    var chart = new google.visualization.LineChart(document.getElementById('traffic_chart'));
    chart.draw(dataTable, chartOptions);
}

这是点击图表 在此处输入图像描述

这是生成点击图表的代码

function drawClickChart(processedData, humanReadableName, params) {
    dataArray = [];
    dataArrayRow = ['Date', 'Website Clicks', 'Image Clicks', 'Video Clicks'];
    dataArray.push(dataArrayRow);
    for (i in processedData) {
        dateString = processedData[i].date;
        dateString = formatDateStringAccordingToAggregationType(dateString, params);
        dataArrayRow = [dateString, processedData[i].event3, processedData[i].event4, processedData[i].event5];
        dataArray.push(dataArrayRow);
    }

    var dataTable = google.visualization.arrayToDataTable(dataArray);
    var chartOptions = {
        title: 'Click Chart',
        hAxis: {title: humanReadableName},
        vAxis: {minValuex: 0},
        pointSize: 5,
        width: 670,
        height: 300
    };
    var chart = new google.visualization.LineChart(document.getElementById('click_chart'));
    chart.draw(dataTable, chartOptions);
}

如您所见,x 轴上的日期搞砸了,我能做些什么来解决这个问题吗?

4

0 回答 0