11

I use Google Visualization API to plot Line Chart. Here are the codes:

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: ''}});
}

The result looks like this:

Screenshot

Question is: How can I remove the -0.5, -1.0 ? Also, I would like to have integers (e.g. 0, 1, 2, 3, ...) in Y-axis. Which parameter should I add?

2 Answers 2

23

In your chart.draw call, add: vAxis:{viewWindow: {min: 0}}

Sign up to request clarification or add additional context in comments.

2 Comments

For GoogleVisualr::Interactive::LineChart, It's not working. Please let me know if anybody have solution. Thanks.
This doesn't work for a LineChart as mentioned above. Looks like you have to set a max value as mentioned in another answer: stackoverflow.com/a/37482770/6619548
4

if set options vAxis: {viewWindow: {min: 0}} did not work try to set vAxis:{viewWindow: {min: 0, max: 10}}

1 Comment

This does work for a LineChart but it would be a lot better if you didn't have to set a max value. In my case I know that there will never be any values less than 0, but I don't know what the max is. It means having to loop through the dataset to check what the max value actually is so you don't crop any values off.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.