I'm struggling to find a solution to produce a line chart which shows a trend from a Time Series metric.

I try to make my line chart look similar to the following:

Time series

Basically, I want to make use of relative change rates, but I struggle to find a calculation which makes a visualization as seen above possible. The graph should always be relative to a specific time window, meaning that I can query my data dynamically with a start and end timestamp.

My (incomplete) sample data set is the following:


Any ideas warmly appreciated. Thanks a lot in advance!


1 Answer 1


While it is not very clear to me what specific relationships between your data you want to display, I can give some general advice. I think that this time series visualization calls for so-called diverging color scheme (as opposed to sequential, categorical and other ones). ColorBrewer is nice online tool for selecting an appropriate color scheme and other parameters (note that ColorBrewer's color schemes have built-in support in major data analysis and visualization software, such as R, Python, d3.js, plot.ly and others).

If you would use R environment, it would be quite easy to produce the time series trend line chart that you want by using ggplot2 package and its scale_color_gradient2() function:

... + scale_color_gradient2(midpoint=midValue, low="blue", mid="white", high="orange" )

A quick glance at your profile suggested me that you would prefer a JavaScript solution. In that case, I would advise to use d3.js library or one of multiple other JavaScript visualization libraries or packages. For more details, check this relevant answer of mine.

  • 1
    $\begingroup$ Thanks a lot for your answer! Maybe my question is not very clear, but I struggle more with the calculation of the Y value than with the diverging color scheme. I have the absolute values of the metric, but that doesn't really help me showing the "speed" of change, and if the "speed" is positive compared to the last "step"/"time bucket". $\endgroup$
    – Tobi
    Mar 17, 2015 at 14:55
  • $\begingroup$ A line gradient solution with D3 can be found at bl.ocks.org/d3noob/3e72cafd95e1834f599b and (better) codepen.io/ekrembk/pen/ights for example... $\endgroup$
    – Tobi
    Mar 17, 2015 at 15:03
  • 1
    $\begingroup$ You're very welcome! I couldn't display the result of your most recently referred code, as it's anon. Anyway, I don't see calculation of speed/rate of change as a problem. Rate of chage $R_i$ (for a time delta $\Delta t_i$) = $\frac{Y_{i+1} - Y_i}{\Delta t_i}$. So your $Y$ for the trend chart should be the $R_i$. What is the problem with that? $\endgroup$ Mar 17, 2015 at 15:45
  • 1
    $\begingroup$ @Tobi: Very easy (if I understand you correctly) - you just need to calculate second derivative (rate of change of rate of change) at your predefined intervals. Those will be your $Y$ values. $\endgroup$ Mar 17, 2015 at 16:04
  • 1
    $\begingroup$ @Tobi: No need to apologize. Nobody knows everything :-). Yes, I believe that's the quadratic approximation. There are lots of resources on the topic. Have a look at this discussion, for example. Good luck and let me know, if I can be of more help! $\endgroup$ Mar 17, 2015 at 16:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.