Google Charts
Google Charts Introduction Getting Started Area Charts Bar Charts Bubble Charts Calendar Charts Candlestick Charts Column Charts Combination Chart Gauge Chart Geo Charts Histogram Charts Line Charts Maps Organization Chart Pie Charts Sankey Charts Scatter Charts Stepped Area Charts Table Chart Trendline Charts Wordtree Charts

Google Trendline Chart

A trendline is a line superimposed on a chart revealing the overall direction of the data.

Google Charts can automatically generate trendlines for Scatter Charts, Bar Charts, Column Charts, and Line Charts.

Google Charts supports three types of trendlines:

  • linear
  • exponential
  • polynomial

Linear Trendlines

A linear trendline is the straight line that most closely approximates the data in the chart.

To draw a trendline on a chart, use the trendlines option and specify which data series to use:

var options = { title: 'Age vs. Weight comparison', hAxis: {title: 'Age', minValue: 0, maxValue: 15}, vAxis: {title: 'Weight', minValue: 0, maxValue: 15}, legend: 'none', trendlines: { 0: {} } // Draw a trendline for data series 0 };
Run code

Exponential Trendlines

If your data is best explained by an exponential of the form eax+b, you can use the type attribute to specify an exponential trendline, as shown below.

For this chart, we also use visibleInLegend: true to display the exponential curve in the legend:

var options = { title: 'Age vs. Weight comparison', hAxis: {title: 'Age', minValue: 0, maxValue: 15}, vAxis: {title: 'Weight', minValue: 0, maxValue: 15}, legend: 'none', trendlines: { 0: { type: 'exponential', visibleInLegend: true, } } };
Run code

Polynomial Trendlines

To generate a polynomial trendline, specify type polynomial and a degree.

var options = { title: 'Age vs. Weight comparison', hAxis: {title: 'Age', minValue: 0, maxValue: 15}, vAxis: {title: 'Weight', minValue: 0, maxValue: 15}, legend: 'none', trendlines: { 0: { type: 'polynomial', degree: 3, visibleInLegend: true, } } };
Run code