Graph
A line graph of one or more virtual pins. The server stores the readings, and the graph can show live data or a past day, week, or month.
Set it up on the server
- Sign in to the Box IO dashboard and open the project that uses this device key.
- Turn on Edit.
- In Edit, add Graph.
- Assign the project device key, or set Device on this widget.
- Use Add pin for each virtual pin you want on the chart. Each row is a pin number, a name, and a color. Remove drops one pin. The graph holds up to 16 pins.
- Set Store a reading to one per second, one per minute, or one per hour. One per second is kept 31 days. One per minute is kept 400 days. One per hour is kept 5 years. A new reading in the same period replaces the earlier one.
- Set Live view to the window shown while Live is selected: 1 minute, 15 minutes, 1 hour, 6 hours, 1 day, 1 week, or 1 month.
- Save the layout. Until you save, the server does not store these pins.
- Open Live. Live follows the window you chose and draws stored readings through the current time. The line starts on the left at the value already in effect, and it ends on the value the pin holds now, the same value a meter on that pin shows. If the first stored reading is later than the start of that window, the chart starts at the first reading so the line fills the graph. On 1 minute the window keeps sliding once the line reaches the left side, instead of clearing and drawing again from the right. Day shows 24 hours from the date and time you pick. Week shows the Monday-to-Monday week of that date. Month shows that calendar month. Prev and Next move the date.
- Turn on Time scale to label the bottom with the clock or the date. Turn on Horizontal data scale to draw horizontal lines and the values they mark. Both stay off until you turn them on. The line fills the widget when you resize it.
- Set Font size to change the caption, the buttons, the pin names, and both scales together. Leave it blank to keep the usual small type.
- In Live, click or tap the plot to zoom in around that spot. Each click shows half the time and half the value range, centered where you clicked, until the window is about two seconds wide. Reset zoom returns to the full Live, Day, Week, or Month window. Changing those controls also clears the zoom.
- Flash the sketch below with the same device key, host, and port
5923. KeepBoxIO.run()inloop().
Properties
Sketch values are always strings, including numbers: BoxIO.setProperty(V2, "max", "200").
| Property | Where to set it | Format | Example | Effect |
|---|---|---|---|---|
sampleEvery | Dashboard | second, minute, or hour | minute | How often a reading is stored for every pin on this graph. |
liveSpan | Dashboard | minute, 15m, hour, 6h, day, week, or month | hour | How far back the Live button looks. |
showTimeScale | Dashboard | On or off | off | Labels along the bottom for the time window. |
showDataScale | Dashboard | On or off | off | Horizontal lines labeled with the data values. |
graphSeries | Dashboard | Pin, name, and color rows | V4 Temp, V5 Hum | The virtual pins drawn on the chart. Each pin is stored on the device key for this widget. |
label | Dashboard or sketch | Plain text | Pump | Caption above the widget, taken from the label saved on that widget. Live shows that caption only. Edit also shows the pin and the device name. A sketch setProperty for label does not rename it. On a round or oval button this is the caption, not the word on the button face. |
hideLabel | Dashboard | On or off | checked | Hides the caption. Button face text, meter numbers, and label text stay visible. |
fontSize | Dashboard | Whole number 8 to 160, or blank for automatic size | 28 | Text size in pixels inside the widget. On a graph this sizes the caption, the buttons, the pin names, and the time and value scales. |
opacity | Dashboard | 10% to 100% | 70% | Lets an overlapping widget show through. 100% is solid. |
Formatting
- The sketch still uses
virtualWrite. The graph does not need a special call. A number is stored. Text is skipped. - Two writes in the same second, minute, or hour keep the later number.
- Day view starts at the selected time and runs 24 hours. Week view starts Monday at midnight. Month view is the calendar month of the selected date.
- The chart draws at most 720 points for a window, using the last stored reading in each slice. The value already in effect is drawn at the left edge, and the last value is held to the current time. Zooming in loads that shorter window again, so a closer view can show finer stored readings.
- A click or tap on the plot zooms in. Reset zoom, or a change of Live, Day, Week, Month, or the date, restores the full window.
Sketch
Paste the device key over bx_paste_your_device_key_here. Wi-Fi boards include BoxIOEsp32.h. Ethernet boards use the same calls with an EthernetClient.
#define BOXIO_AUTH "bx_paste_your_device_key_here"
#define WIFI_SSID "your-ssid"
#define WIFI_PASS "your-password"
#define BOXIO_HOST "localhost"
#define BOXIO_PORT 5923
#include <BoxIOEsp32.h>
void setup() {
BoxIO.begin(BOXIO_AUTH, WIFI_SSID, WIFI_PASS, BOXIO_HOST, BOXIO_PORT);
BoxIO.setTimer(1000, sendTemp);
BoxIO.setTimer(1000, sendHum);
}
void loop() {
BoxIO.run();
}
void sendTemp() {
BoxIO.virtualWrite(V4, analogRead(34));
}
void sendHum() {
BoxIO.virtualWrite(V5, analogRead(35));
}
What you should see
After you save the layout, each virtualWrite on those pins leaves one reading at the rate you set. Live shows those stored readings through the current time. The line begins at the value already in effect and ends on the value the pin holds now. A shorter history fills the chart from the first stored reading. Day, Week, and Month show the stored readings for the date you pick.