Colors for stacked bar chart #166
Replies: 2 comments
-
|
Hello :). The argument #import "@preview/cetz:0.4.2"
#import "@preview/cetz-plot:0.1.3": *
#let data = (
([1], 1,3,5,7,9),
([2], 2,3,4,5,6),
([3], 5,6,7,8,9)
)
#cetz.canvas({
chart.barchart(mode: "stacked",
size: (3, auto),
bar-style: n => (fill: (red, blue, green, yellow).at(calc.rem(n, 4))),
value-key: (..range(1, 6)),
x-tick-step: 6,
data)
}) |
Beta Was this translation helpful? Give feedback.
-
|
Thanks for the quick reply! That’s brilliant, and works perfectly! Can I make a more general point, please? Not everyone is a programmer, and so writing code to address an issue like this will not be everyone’s initial instinct, or even something they’d want to do. And that may be especially true for those of us coming from LaTeX where writing macros and code is, well, beyond the average person who just wants to typeset a document to a deadline. So Typst and CeTZ-plots might be more welcoming if they have layers of discoverability. In this instance it seems “natural” (to me at least) that Fill should accept an array of colors. That it could also accept a function would be an advanced depth that would delight those with programming skills and more complex typesetting needs. That would also add a level of compatibility with, say #table cells – where Fill can accept a value, an array, and a function (among other things). Anyway, wish-list over – thanks again! |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello!
I am trying to render a stacked bar chart, and I'd like each of the segments in a bar to be a different color.
My simple mind says that'd need an array eg:
That does not work for me.
I've tried a few other things, but I am clearly clueless. Please advise!
Beta Was this translation helpful? Give feedback.
All reactions