Closed michaelrommel closed 2 weeks ago
Hey @michaelrommel, thanks for checking out LayerChart.
I would recommend using the newer, simplified <BarChart>
with series
support, which greatly simplifies this use case.
Take a look at this example, and other related examples
<BarChart>
uses all those components under the hood (Chart, Tooltip, etc), but orchestrates them to simplify most use cases. It also provides many extension points includes props
, named slots (marks, tooltip, etc) and default slot if you want to build most of the chart manually but with preconfigured defaults.
Feel free to hop on the Discord to troubleshoot as well
It can be so easy, if you know, which component to take...
Thanks for the quick help. I was standing in my own way. Normally I like to figure things out myself, but this one question would have saved me a lot of time... I'll have a look at the discord as well. Thanks!!
Still need to style that somehow, because I see the numbers on the Axis are now cut off...
You can add left (y) and bottom (x) padding
to account for the Axis.
<BarChart padding={{ left: 16, bottom: 16 }}>
BarChart
will setup some default padding for you (based on axis and legend), but it kind of looks like it's being overridden here, but could be wrong. It's not uncommon to set your own padding to, based on the length of axis label values.
Yeah, I was just looking at that code... Good to know, how I can add that padding. Is there also a way to increase the font size?
The easiest way is to use props={{ xAxis: ..., yAxis: ... }}
to pass props/classes to the underlying <Axis>
instance
<BarChart
data={dateSeriesData}
x="date"
y="value"
props={{ xAxis: { tickLabelProps: { class: 'text-sm' } }, yAxis: ... }}
/>
You can also override the axis
slot and pass your own Axis
instance. See the Axis docs for examples of different props/use cases, including the rotated/styled example
Hello,
I tried to use a stacked barchart in one of my projects. It works, but the stacked bars all have the same color, even though the tooltip correctly maps the colors. If I add a argument to the Bar component with
class="fill-gruvgreen"
the bars are all green. But shouldn't be the bars automatically have a different colour? They all are at the moment mapped tosurface-content
.I have now spent a couple of hours in investigating it, but I am at a loss here, no idea, where the colours would be mapped in the Bars component. It may have to do with the Context, but I am not sure. I also think the documentation and examples are outdated. I had to change c, cScale, cDomain and cRange to the z-equivalent, see above.
I would appreciate a pointer, what I am doing wrong.
Thanks,
Michael.