Boardy
Boardy

Reputation: 36217

Google Charting API stop negative numbers from being displayed

I am working with Google's Charting API and I have a problem where the graph will sometimes have 0 in the middle of the y axis and underneath show negative numbers.

I want to set the chart to be a minimum of 0 and found on Google that all I need to do is add vAxis:{viewWindow: {min: 0}}.

I'm drawing my chart like the below

function (result)
                    {
                        alert(result);
                        var obj = $.parseJSON(result);
                        var resultData = obj.DATA;
                        var data = new google.visualization.DataTable(resultData);

                        var options = {
                            title: "Crash counts for ",
                            pointSize: 6,
                            hAxis: {showTextEvery: 2, slantedText: true, slantedTextAngle: 30},
                            animation: {
                                duration: 1000,
                                easing: 'out'
                            }
                            vAxis:{viewWindow: {min: 0}}
                        };

                        var chart = new google.visualization.LineChart(document.getElementById("lineChart"));
                        chart.draw(data, options);
                    }
                ), "json";
            }

Chrome says that the line vAxis has an error which is unexpected identifier.

Upvotes: 0

Views: 299

Answers (1)

juvian
juvian

Reputation: 16068

Well, really simple mistake, you just forgot to add a , after animation :

                   var options = {
                        title: "Crash counts for ",
                        pointSize: 6,
                        hAxis: {showTextEvery: 2, slantedText: true, slantedTextAngle: 30},
                        animation: {
                            duration: 1000,
                            easing: 'out'
                        }, // here is the change
                        vAxis:{viewWindow: {min: 0}}
                    };

Upvotes: 1

Related Questions