Newbie
Newbie

Reputation: 281

How to change last two column colors in sparkline charts

In Google Sheets, sparkline charts is known to have an option to change the last column color.

=sparkline((A1:A5),{"charttype","column";"lastcolor","green"})enter image description here

What if I want to change last two column colors? Any option like this, or any workaround?

=sparkline((A1:A5),{"charttype","column";"lasttwocolor","green"}) enter image description here

Upvotes: 1

Views: 561

Answers (3)

player0
player0

Reputation: 1

alternative with SPARKLINE and some column width magic:

=INDEX({SPARKLINE(A1:INDEX(A:A, MAX(ROW(A:A)*(A:A<>""))-1), 
 {"charttype", "column"; "lastcolor", "green"; "ymax", LOOKUP(9^9, A:A)}), 
 SPARKLINE(OFFSET(A:A, MAX(ROW(A:A)*(A:A<>""))-1, ), 
 {"charttype", "column"; "color", "green"})})

enter image description here

end result visual:

enter image description here


update fix:

=INDEX(LAMBDA(a, {SPARKLINE(A1:INDEX(a, MAX(ROW(a)*(a<>""))-1), 
 {"charttype", "column"; "lastcolor", "green"; "ymax", MAX(a)}), 
 SPARKLINE(OFFSET(a, MAX(ROW(a)*(a<>""))-1,), 
 {"charttype", "column"; "color", "green"; 
  "ymax", MAX(a); "ymin", MIN(a)})})(A:A))

enter image description here

Upvotes: 2

player0
player0

Reputation: 1

enter image description here

while this is possible to get, it is not doable with one single SPARKLINE. but you can use a column chart:

enter image description here

after some customization it could look like your desired output:

enter image description here

then double-click the last two columns and set them as alt color:

enter image description here

Upvotes: 1

The God of Biscuits
The God of Biscuits

Reputation: 3207

You can't achieve this within one single sparkline, however if you can tolerate an additional column to the right what you could do is to to join two sparklines together horizontally using an array literal with first sparkline containing all data points up to the penultimate one and the second containing just the last data point. Then colour the second sparkline the same as the last data point of the first and resize the column width so the bar width matches the other data points.

Obviously this won't be possible in every context.

Upvotes: 1

Related Questions