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 props
プロパティー | タイプ |
---|---|
| 必須
The data used to generate the chart. |
| 必須
The property or accessor for the point on the x axis. Related types: Channel. |
| 必須
The property or accessor for the point on the y axis. Related types: Channel. |
| オプション
Determines whether to render labels and ticks for each axis. |
| オプション
Groups data by color based on a property or accessor. Related types: Channel. |
| オプション
Determines whether to render grid lines for each axis. |
| オプション
Determines whether to render the legend (when more than one item is present). |
| オプション
Determines whether to render a tooltip when hovering over the chart. |
| オプション
Groups data based on a property or accessor. Related types: Channel. |
Channel
プロパティー | タイプ |
---|---|
| オプション
|
| オプション
Related types: 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> )