Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
344 views
in Technique[技术] by (71.8m points)

google sheets - Sparkline to change colour based on different values

I'm looking to get my sparkline to change colour based on values to reflect a product expiring and to also show when a product has been delivered:

Issue Date(C10), Expiration Date(D10), Sparkline(J10), certificate status(K10):

Ideally I would like the cell to be green, and as the date moves closer to expiration I would like the cell to fill as red - Once the certificate status has been changed to "Delivered" The sparkline would change to grey. I'm a newbie to this apart from a basic sparkline, anything else produces an Error or parse error

question from:https://stackoverflow.com/questions/65845341/sparkline-to-change-colour-based-on-different-values

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Sounds like what you want is to change color1 dynamically. You can do this by interpolating a value and concatenating to a string. Assuming input row 10, like in your question:

=SPARKLINE(NOW()-C10,
{
  "charttype","bar";
  "max",D10-C10;
  "color1",IF(
    K10="Delivered",
    "gray",
    "rgb("&INT(255*(NOW()-C10)/(D10-C10))&","&INT(255*(D10-NOW())/(D10-C10))&",0)"
  )
})
  • Here, your data input is Now()-C10, which gets passed to the sparkline.
  • The IF Statement overrides the color to gray if K10="Delivered".
  • The rgb string sets the color to more red as the date gets closer to the expiration date and more green as the date gets closer to the Issue Date.

If you want a full gray bar upon delivery, you can set the max property to (K10<>"Delivered")*(D10-C10).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...