Stripe Apps の BarChart コンポーネント
棒グラフは、棒を使用してデータを一連のデータポイントとして視覚化します。
BarChart
コンポーネントをアプリに追加するには、以下のようにします。
import {BarChart} from '@stripe/ui-extension-sdk/ui';
BarChart
コンポーネントのプレビューを以下に示します。
const sales = [ { date: 'Jan', sold: 1, }, { date: 'Feb', sold: 4, }, { date: 'Mar', sold: 2, }, { date: 'Apr', sold: 3, }, ]; return ( <Box css={{width: 'fill'}}> <BarChart data={sales} x="date" y="sold" /> </Box> )
BarChart プロパティ
プロパティー | タイプ |
---|---|
| 必須
チャートの生成に使用されるデータ。 |
| 必須
x 軸上の点のプロパティまたはアクセサー。 関連タイプ: Channel。 |
| 必須
y 軸上の点のプロパティまたはアクセサー。 関連タイプ: Channel。 |
| オプション
各軸のラベルと目盛をレンダリングするかどうかを決定します。 |
| オプション
プロパティまたはアクセサーに基づいてデータを色でグループ化します。 関連タイプ: Channel。 |
| オプション
各軸のグリッド線をレンダリングするかどうかを決定します。 |
| オプション
凡例をレンダリングするかどうかを決定します (複数の項目が存在する場合)。 |
| オプション
チャート上にマウスを合わせたときにツールチップを表示するかどうかを決定します。 |
| オプション
プロパティまたはアクセサーに基づいてデータをグループ化します。 関連タイプ: Channel。 |
Channel
プロパティー | タイプ |
---|---|
| オプション
|
| オプション
関連タイプ: Currency、UnitIdentifier。 |
| オプション
|
| オプション
|
通貨
プロパティー | タイプ |
---|---|
| 必須
|
UnitIdentifier
プロパティー | タイプ |
---|---|
| 必須
|
色の使用
color
チャネルは、データを次のようにグループ化します。
const sales = [ { date: 'Jan', sold: 1, product: 'tables', }, { date: 'Jan', sold: 2, product: 'chairs', }, { date: 'Feb', sold: 4, product: 'tables', }, { date: 'Feb', sold: 6, product: 'chairs', }, { date: 'Mar', sold: 2, product: 'tables', }, { date: 'Mar', sold: 4, product: 'chairs', }, { date: 'Apr', sold: 7, product: 'tables', }, { date: 'Apr', sold: 9, product: 'chairs', }, ]; return ( <Box css={{width: 'fill'}}> <BarChart data={sales} x="date" y="sold" color="product" /> </Box> )
軸と値の形式設定
axis 値に文字列を渡す代わりに、value
、label
、または format
プロパティーが含まれたオブジェクトを渡すことで、より豊富な形式設定を追加できます。
プロパティ | タイプ |
---|---|
|
データセット内のプロパティー名。必須。 |
|
軸の表示テキスト。 |
|
サポートされている通貨コード ( |
<Box css={{width: 'fill'}}> <BarChart data={[ { date: 'January', sold: 10, }, { date: 'February', sold: 41, }, { date: 'March', sold: 22, }, { date: 'April', sold: 38, }, ]} x="date" y={{value: 'sold', label: 'Price', format: {currency: 'USD'}}} /> </Box>
ドメイン
軸の最小値と最大値を設定するには、domain
プロパティーを使用します。たとえば、y
軸を (提供されたデータに合わせて自動調整するのではなく) 常に 0 から 10 の範囲にしたい場合は、設定に domain
プロパティーを追加します。
const sales = [ { date: 'Jan', sold: 1, }, { date: 'Feb', sold: 4, }, { date: 'Mar', sold: 2, }, { date: 'Apr', sold: 3, }, ]; return ( <Box css={{width: 'fill'}}> <BarChart data={sales} x="date" y={{value: 'sold', label: 'Sold', domain: [0, 10]}} /> </Box> )