1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Recharts Tooltipの数値をフォーマットする

Posted at

RechartのTooltipの数値をフォーマットする際に迷ったので備忘録。

Tooltipのフォーマット

Rechartでは、Tooltipを使うと、マウスオーバで数値の詳細が確認できるようになる。

<BarChart>
  <Tooltip />
</BarChart>

表示される数値は、formatter propに関数を渡せばフォーマットできる。

<BarChart>
  <Tooltip formatter={(value) => new Intl.NumberFormat('ja-JP', {maximumFractionDigits: 0}).format(value)} />
</BarChart>

TypeScrpitの場合は、valueを数値に変換してNumberFormat.formatに渡せばok

<BarChart>
  <Tooltip formatter={(value) => new Intl.NumberFormat('ja-JP', {maximumFractionDigits: 0}).format(+value)} />
</BarChart>

変数に名前を付ける場合は、[formatted_value, name]の配列を返す

<BarChart>
  <Tooltip formatter={(value, name) => [new Intl.NumberFormat('ja-JP', {maximumFractionDigits: 0}).format(+value), idToLabelMap.get(name)]} />
</BarChart>

参考

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?