plot Bar Graph
Display a bar graph for a number value.
led.plotBarGraph(2, 20);
A bar graph is a kind of chart that shows numbers as lines with different lengths. The value is plotted in LEDs as a ratio of a value to the high value you set as a maximum range. So, if there are 25 LEDs on the screen, then plotting 9
for the high value of 50
would display about 5 LEDs on the screen.
Parameters
- value: a number that is the value of what you are measuring or trying to show. For example, if you are measuring the temperature of ice with the micro:bit,
value
might be0
if the temperature is 0 degrees Celsius. - high: a number that is the highest possible number (maximum) that the value parameter can be. The lines in the bar graph will reach their highest point when value reaches this number. If high is
0
, then the largest value recently plotted is used as the maximum. - valueToConsole: a boolean value that when
true
will also send the value to the serial port. A value offalse
will prevent the number in value from going to the serial output.
Example: chart acceleration
Show a bar graph of the acceleration in the x
direction of the micro:bit. The micro:bit’s x
direction is from left to right (or right to left). The faster you move the micro:bit in this direction, the taller the lines in the bar graph will be. The high paramter is 1023
which sets the highest possible value of acceleration to show. Also, record the acceleration value by sending it to the serial port.
basic.forever(() => { let a = input.acceleration(Dimension.X); led.plotBarGraph(a, 1023, true) })