Google Visualization API:折线图 - 隐藏Y轴中的负值

时间:2012-03-19 02:28:28

标签: google-visualization

我使用Google Visualization API绘制折线图。以下是代码:

google.load("visualization", "1", {packages:["corechart"]});
google.setOnLoadCallback(drawCharts);
function drawCharts() {
    // Total Coupon View
    var data_total_users = new google.visualization.DataTable();
    data_total_users.addColumn('string', 'Total Users');
    data_total_users.addColumn('number', 'User Count');

    data_total_users.addRows(7);
    data_total_users.setValue(0, 0, 'Sunday');
    data_total_users.setValue(0, 1, 10);
    data_total_users.setValue(1, 0, 'Monday');
    data_total_users.setValue(1, 1, 4);
    data_total_users.setValue(2, 0, 'Tuesday');
    data_total_users.setValue(2, 1, 3);
    data_total_users.setValue(3, 0, 'Wednesday');
    data_total_users.setValue(3, 1, 7);
    data_total_users.setValue(4, 0, 'Thursday');
    data_total_users.setValue(4, 1, 8);
    data_total_users.setValue(5, 0, 'Friday');
    data_total_users.setValue(5, 1, 10);
    data_total_users.setValue(6, 0, 'Saturday');
    data_total_users.setValue(6, 1, 10);
    var chart = new google.visualization.LineChart(document.getElementById('chart_users_total'));
    chart.draw(data_total_users, {width: 1000, height: 400, title: '', hAxis: {title: ''}});
}

结果如下:

Screenshot

问题:如何删除-0.5,-1.0?另外,我想在Y轴上有整数(例如0,1,2,3 ......)。我应该添加哪个参数?

2 个答案:

答案 0 :(得分:22)

在您的chart.draw电话中,添加: vAxis:{viewWindow:{min:0}}

答案 1 :(得分:2)

如果设置选项vAxis:{viewWindow:{min:0}}无效,请尝试设置vAxis:{viewWindow:{min:0,max:10}}