> ## Documentation Index
> Fetch the complete documentation index at: https://private-7c7dfe99-mintlify-8a08bda2.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

> この関数は、区間 `[min_x, max_x]` における値 `x` と、それらの値の出現頻度 `y` の度数ヒストグラムを描画します。

# sparkbar

<div id="sparkbar">
  ## sparkbar
</div>

導入バージョン: v21.11.0

この関数は、値 `x` と、区間 `[min_x, max_x]` におけるそれらの値の出現頻度 `y` の度数ヒストグラムを描画します。
同じバケットに入るすべての `x` の出現頻度は平均化されるため、データは事前に集計しておく必要があります。
負の出現頻度は無視されます。

interval が指定されていない場合は、最小の `x` が区間の開始として使用され、最大の `x` が区間の終了として使用されます。
それ以外の場合、区間外の値は無視されます。

**構文**

```sql theme={null}
sparkbar(buckets[, min_x, max_x])(x, y)
```

**別名**: `sparkBar`

**パラメータ**

* `buckets` — セグメント数。[`(U)Int*`](/ja/reference/data-types/int-uint)
* `min_x` — 任意。区間の開始値。[`(U)Int*`](/ja/reference/data-types/int-uint) または [`Float*`](/ja/reference/data-types/float) または [`Decimal`](/ja/reference/data-types/decimal)
* `max_x` — 任意。区間の終了値。[`(U)Int*`](/ja/reference/data-types/int-uint) または [`Float*`](/ja/reference/data-types/float) または [`Decimal`](/ja/reference/data-types/decimal)

**引数**

* `x` — 値が格納されたフィールド。[`const String`](/ja/reference/data-types/string)
* `y` — 値の出現頻度が格納されたフィールド。[`const String`](/ja/reference/data-types/string)

**戻り値**

度数ヒストグラムを返します。[`String`](/ja/reference/data-types/string)

**例**

**区間を指定しない場合**

```sql title=Query theme={null}
CREATE TABLE spark_bar_data (`value` Int64, `event_date` Date) ENGINE = MergeTree ORDER BY event_date;

INSERT INTO spark_bar_data VALUES (1,'2020-01-01'), (3,'2020-01-02'), (4,'2020-01-02'), (-3,'2020-01-02'), (5,'2020-01-03'), (2,'2020-01-04'), (3,'2020-01-05'), (7,'2020-01-06'), (6,'2020-01-07'), (8,'2020-01-08'), (2,'2020-01-11');

SELECT sparkbar(9)(event_date, cnt) FROM (SELECT sum(value) AS cnt, event_date FROM spark_bar_data GROUP BY event_date);
```

```response title=Response theme={null}
┌─sparkbar(9)(event_date, cnt)─┐
│ ▂▅▂▃▆█  ▂                    │
└──────────────────────────────┘
```

**interval を指定する場合**

```sql title=Query theme={null}
SELECT sparkbar(9, toDate('2020-01-01'), toDate('2020-01-10'))(event_date, cnt) FROM (SELECT sum(value) AS cnt, event_date FROM spark_bar_data GROUP BY event_date);
```

```response title=Response theme={null}
┌─sparkbar(9, toDate('2020-01-01'), toDate('2020-01-10'))(event_date, cnt)─┐
│ ▂▅▂▃▇▆█                                                                  │
└──────────────────────────────────────────────────────────────────────────┘
```
