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

> La función genera un histograma de frecuencias para los valores `x` y la tasa de repetición `y` de esos valores en el intervalo `[min_x, max_x]`.

# sparkbar

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

Introducido en: v21.11.0

La función representa un histograma de frecuencias para los valores `x` y la tasa de repetición `y` de estos valores en el intervalo `[min_x, max_x]`.
Las repeticiones de todos los `x` que caen en el mismo bucket se promedian, por lo que los datos deben agregarse previamente.
Las repeticiones negativas se ignoran.

Si no se especifica ningún intervalo, el `x` mínimo se usa como inicio del intervalo y el `x` máximo como fin.
De lo contrario, se ignoran los valores fuera del intervalo.

**Sintaxis**

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

**Alias**: `sparkBar`

**Parámetros**

* `buckets` — El número de segmentos. [`(U)Int*`](/es/reference/data-types/int-uint)
* `min_x` — Opcional. El inicio del intervalo. [`(U)Int*`](/es/reference/data-types/int-uint) o [`Float*`](/es/reference/data-types/float) o [`Decimal`](/es/reference/data-types/decimal)
* `max_x` — Opcional. El final del intervalo. [`(U)Int*`](/es/reference/data-types/int-uint) o [`Float*`](/es/reference/data-types/float) o [`Decimal`](/es/reference/data-types/decimal)

**Argumentos**

* `x` — El campo con valores. [`const String`](/es/reference/data-types/string)
* `y` — El campo con la frecuencia de los valores. [`const String`](/es/reference/data-types/string)

**Valor devuelto**

Devuelve el histograma de frecuencias. [`String`](/es/reference/data-types/string)

**Ejemplos**

**Sin especificar el intervalo**

```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)─┐
│ ▂▅▂▃▆█  ▂                    │
└──────────────────────────────┘
```

**Con especificación del intervalo**

```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)─┐
│ ▂▅▂▃▇▆█                                                                  │
└──────────────────────────────────────────────────────────────────────────┘
```
