The `||light:graph||`

block also writes the number from **value** to the serial port as a way to help you record
values.

# graph

Graph a number using the pixels on the pixel ring.

`light.graph(0, 0);`

The `||light:graph||`

block turns the pixel ring into a lighted graph to display number values.

`light.graph(6, 10)`

In this case, the *range* of values you want to graph is `10`

. This matches the total number of pixels on the board, so 6 pixels would light up.

If you wanted to graph values between `0`

and `20`

, each pixel now means a difference in value of `2`

instead of `1`

. That means if you show a value of `6`

when the range is `20`

, 3 pixels will light up. This graph block shows the value of `6`

when the range limit is `20`

:

`light.graph(6, 20)`

The pixel ring will have 3 pixels turned on since each pixel represents a change of `2`

in value:

`light.graph(6, 20)`

## Auto scale

If you use `0`

for **high** (or leave the parameter empty), the graph will *auto scale*. That means that the largest number you use in **value** will set the limit of the range. This way you can use `||light:graph||`

many times, like in a loop, to show a bunch of numbers when you’re not sure what the biggest one will be. As an example, let’s graph the value of `10`

once, then graph `100`

. Graph `10`

again and see how many pixels light up.

```
light.graph(10)
pause(1000)
light.clear()
pause(1000)
light.graph(100)
pause(1000)
light.clear()
pause(1000)
light.graph(10)
```

The first two times a value is graphed, a new limit for the range is set. All the pixels are used to show both `10`

and `100`

. The next time `10`

is graphed only one pixel is on because the last maximum value was `100`

and that value set the range limit.

Auto scale will eventually reset and current **value** becomes the range limit if you haven’t used `||light:graph||`

in the last 10 seconds.

## Parameters

**value**: a number that is the value to show on the pixels.**high**: an optional high number that is limit of the graphing range. A value of`0`

lets the graph auto scale.

## Examples

### Graph of ten

Graph all 10 values between 1 and 10 on the pixels. Set the range limit to `10`

.

```
for (let i = 0; i <= 9; i++) {
light.graph(i + 1, 10)
pause(500)
}
```

### Accelerometer (g-meter)

Graph the acceleration of the board in the `x`

direction on the pixels.

```
forever(function () {
light.graph(input.acceleration(Dimension.X))
})
```

### Sound meter

Show the loudness of sounds nearby on the pixels.

```
forever(function () {
light.graph(input.soundLevel())
})
```

### Auto range graph

Graph random values upto `1000`

. Let them auto scale when displayed.

```
forever(() => {
light.graph(Math.randomRange(0, 1000))
pause(500)
})
```

## See also

`circuit-playground`