Derk Arts
Derk Arts

Reputation: 3460

Can't get trendlines to work

Check out this fiddle: http://jsfiddle.net/b8e8t/1/

I wasn't able to get the fiddle to work by splitting the JS and the HTML, so I just left it in the HTML window.

Check the console when loading this fiddle, it will show 2 errors:

Error: Problem parsing d="M0.5,-3.879860269285669e+59L11.599999999999........

The offending part is:

var options = {"title": "User activity","theme": "maximized","width": 1000,"height": 500,"trendlines": "2: {color: 'purple'}"};

Specifically the trendlines part. I cannot for the live of me figure out why the trendlines don't work, the data looks alright to me.

ANy ideas?

Upvotes: 0

Views: 143

Answers (2)

Derk Arts
Derk Arts

Reputation: 3460

I discovered what was wrong. I used the PHP wrapper Chart.php and it was outputting data from Mysql as strings, not as integers. Casting the data as int solved the issue. Apparently Google Charts is very stingy about data types.

Upvotes: 0

asgallant
asgallant

Reputation: 26340

Your syntax for adding a trendline is wrong. The trendlines option is an object, not a string. Also, you must specify the type of trendline ('linear' or 'exponential'). It should look like this:

trendlines: {
    // trendline for the first data series (patients)
    0: {
        type: 'exponential',
        color: 'purple'
    }
}

Also, you should only use one callback from the google loader (multiple callbacks are not supported). Create a function that calls your draw functions and pass that as the callback:

function init () {
    drawChart1();
    drawChart2();
    drawChart3();
}
google.load('visualization', '1.0', {'packages': ['corechart'],'language': 'en', callback: init});

Upvotes: 1

Related Questions