karlo292
karlo292

Reputation: 47

shadcn chart has no space between label and value

The issue I'm facing can be seen on the image, essentially some bigger values don't have any padding in between value and label, I'd like to know how I can make it at least 2px

Image:

enter image description here

Part of code:

    <ChartTooltip
      cursor={false}
      content={
        <ChartTooltipContent
          labelFormatter={(value) => {
            return new Date(value).toLocaleDateString("en-US", {
              month: "short",
              day: "numeric",
            });
          }}
          indicator="line"
        />
      }
    />

Upvotes: 0

Views: 230

Answers (1)

shafeman
shafeman

Reputation: 26

Looks like this is something Shadcn doesn't currently let you customize via props. You could solve it by setting a min width on the ChartTooltip via the className prop, but that is not ideal. However, since Shadcn is meant to be tweaked you can modify the raw ChartTooltipContent component by adding a gap-2 className or similar at the end after the indicator bit

<div
  className={cn(
    'flex flex-1 justify-between leading-none gap-2', // <-- add gap-2 here
    nestLabel ? 'items-end' : 'items-center'
  )}
>
  <div className="grid gap-1.5">
    {nestLabel ? tooltipLabel : null}
    <span className="text-muted-foreground">
      {itemConfig?.label || item.name}
    </span>
  </div>
  {item.value && (
    <span className="font-mono font-medium tabular-nums text-foreground">
      {item.value.toLocaleString()}
    </span>
  )}
</div>

Or make this a prop you can pass through to the component.

Upvotes: 1

Related Questions