You are correct: trendlines only work for continuous-axis charts, as you
can't create a function f(x) when x is a string (solve f(x) = 3x + 5 where
x = "foo" does not compute). You can fake it, however, with a bit of
clever trickery using a DataView and the hAxis.ticks option:
var view = new google.visualization.DataView(data);
view.setColumns([{
type: 'number',
label: data.getColumnLabel(0),
calc: function (dt, row) {
return {v: row, f: data.getValue(row, 0)};
}
}, 1 /*, 2, 3... however many data series you have */]);
var hAxisLabels = [];
for (var i = 0; i < data.getNumberOfRows(); i++) {
hAxisLabels.push({v: i, f: data.getValue(i, 0)});
}
chart.draw(view, {
// options
hAxis: {
ticks: hAxisLabels
}
}
see example here: http://jsfiddle.net/asgallant/yYuu7/
On Monday, January 6, 2014 8:49:17 AM UTC-5, Michael Falkson wrote:
>
> Trendlines seems to only work when the first column is numeric.
>
> I have a combo chart ...
>
> Columns - Months (string), HoursWorked(number/BAR),PerHour(number/LINE).
>
> I need to add a trend line on the 2rd column/series.
>
> Here is what I did (but it's not working)
>
> trendlines: {
>
> 1: {
>
> type: ''linear'',
>
> color: ''red'',
>
> labelInLegend: ''Trend'',
>
> visibleInLegend: true,
>
> }
> Any help would be appreciated.
>
> Mike
>
>
>
--
You received this message because you are subscribed to the Google Groups
"Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/google-visualization-api.
For more options, visit https://groups.google.com/groups/opt_out.