Trend lines on custom charts

Would it be possible to have the ability to have tend lines on the custom charts you can create on the fitness page? I think it would be an excellent addition to helping track some key metrics.

Eg. Very crude… :joy:

image

1 Like

I agree this would be very useful and appreciated as an option to add to charts.

1 Like

Yep, great idea. I love a graph with a trendline.

1 Like

Creat idea

1 Like

You can add a copy of your line with aggressive rolling averaging. This is how I do it for my sleep and rest HR plots:

I have bars for daily data, a line for weekly rolling average and a shaded band for monthly trend (±0.5 standard deviation). Just a trend line will be nearly horizontal for both plots, but with this setup I can see that lately my HR has been statistically significantly trending downward with respect to the last 42 days variations.

6 Likes

@Olly_Thomas, are you looking for something different than a moving average? Isn’t that all a trend line is?
i.e. HRV & rHR graphs


Trendlines can be Linear, Logarithmic, Polynomial, Power, Exponential or Moving Average. “It all depends” on the type of data that is required to be measured.

3 Likes

<eyes glazing over> as I try to imagine what all those options might indicate. 🥹

FWIW, here’s some info:
https://support.microsoft.com/en-us/office/trendline-options-in-office-92157920-fee4-4905-bc89-6a0f48152c52

2 Likes

The trend line is something quite interesting, especially to see evolutions, but also in sessions to see how the pulse or power has been along the activity, even selecting intervals to see the trend of that interval.

1 Like

The purpose of a trendline is to detect a mathematical relation so that it can be used to not only see what already happened, but also predict what might be coming. Trends are widely used in the financial world to predict stock values, insurance trends and the like.

2 Likes

Hello Guys,

Did was implemented this Feature Request? I’d want to use a linear trend for several metrics I have during the year but could not do it. If not, is there any way to get the linear trend? I am using moving average but does not show the info as I would want to…

Or maybe can I put the formula of linear trend for a custom chart in fitness page?

Thank you!

Nope, not implemented yet…I would like to be implemented still though!

1 Like

Thank you! @david another vote here to put in to do :grimacing: :+1:

1 Like

I have added this as an option for custom fitness charts. Tx @Inigo_Tolosa for the linear fit function. Will look at other charts soon. You can also select “None” for the marker value position to hide that.

11 Likes

Excellent thank you David!

1 Like

Wowwwww that was fast! Thanks a lot @david !!!

Hi @david, or @Inigo_Tolosa

I can see you allow us to create trend lines on custom charts for activity page too, great! Thanks!

image

I am trying to get a custom interval field that give me the change of the trend line of a data stream (power, hr, etc…) but I need to get the trend line equation (linear regression y=mx+c) and use the “slope” (m) value to calculate the value.

Is it available as a method for data model or do I have to make the whole function in javascript to get the equation?

Thanks a lot!

Tito.

Unfortunately you need to do that in Javascript. The trend line is added client side as a post processing step on the data stream so it is not available on the server where the custom activity fields run.

Here is the client side code. The calc_linear_trend function data parameter is the stream you want to get a trend for. The time parameter is the time stream.

// from Iñigo Tolosa
export function linFit(_x, _y, ini, end) {
  let SXi2 = 0
  let SXi = 0
  let SXiYi = 0
  let SYi = 0
  let n = end - ini
  for (let i = ini; i < end; i++) {
    SXi = SXi + _x[i]
    SXi2 = SXi2 + _x[i] * _x[i]
    SYi = SYi + _y[i]
    SXiYi = SXiYi + _x[i] * _y[i]
  }

  let det_A = SXi2 * n - SXi * SXi
  let m = (SXiYi * n - SXi * SYi) / det_A
  let c = (SXi2 * SYi - SXiYi * SXi) / det_A
  return [m, c]
}

function calc_linear_trend(data, time, start, end) {
  let x = [], y = []
  for (let i = start; i < end; i++) {
    let v = data[i]
    if (typeof v === 'number') {
      x.push(time[i])
      y.push(v)
    }
  }
  if (x.length > 1) {
    const [m, c] = linFit(x, y, 0, x.length)
    for (let i = start; i < end; i++) data[i] = time[i] * m + c
  }
  return data
}
2 Likes

Perfect! Thank you @david and @Inigo_Tolosa

1 Like