chart_types.tc¶
Chart Types Demo — shows all supported WebChart types
// Chart Types Demo — shows all supported WebChart types
// Generates synthetic data and displays one of each chart type
// WebChart(type, title, unit, color, pos, count, array, decimals, interval, ymin, ymax)
#define SAMPLES 24
float d_line[SAMPLES];
float d_col[SAMPLES];
float d_bar[SAMPLES];
float d_hist[SAMPLES];
float d_stk1[SAMPLES];
float d_stk2[SAMPLES];
float d_tbl1[7];
float d_tbl2[7];
float d_tbl3[7];
int pos;
int ready;
int main() {
int i;
// generate sample data
for (i = 0; i < SAMPLES; i = i + 1) {
d_line[i] = 20.0 + (i % 7) * 1.5 - (i % 3) * 0.8;
d_col[i] = 5.0 + (i % 5) * 2.0;
d_bar[i] = 10.0 + (i % 6) * 3.0;
d_hist[i] = 15.0 + (i % 8) * 1.2 - (i % 4) * 0.5;
d_stk1[i] = 3.0 + (i % 4) * 1.5;
d_stk2[i] = 2.0 + (i % 5) * 1.0;
}
// table data: 7 days
d_tbl1[0] = 12.5; d_tbl1[1] = 14.2; d_tbl1[2] = 11.8;
d_tbl1[3] = 15.1; d_tbl1[4] = 13.7; d_tbl1[5] = 16.3; d_tbl1[6] = 10.9;
d_tbl2[0] = 3.2; d_tbl2[1] = 4.1; d_tbl2[2] = 2.8;
d_tbl2[3] = 5.5; d_tbl2[4] = 3.9; d_tbl2[5] = 6.1; d_tbl2[6] = 2.4;
d_tbl3[0] = 0.5; d_tbl3[1] = 1.2; d_tbl3[2] = 0.0;
d_tbl3[3] = 2.1; d_tbl3[4] = 0.3; d_tbl3[5] = 0.0; d_tbl3[6] = 1.8;
pos = SAMPLES;
ready = 1;
print("Chart types demo ready. Open web page to view.\n");
return 0;
}
void WebPage() {
if (!ready) {
webSend("<p>Loading...</p>");
return;
}
// Line chart
WebChart('l', "Line Chart", "\u00b0C", 0xe74c3c, pos, SAMPLES, d_line, 1, 30, 0, 0);
// Column chart
WebChart('c', "Column Chart", "kWh", 0x3498db, pos, SAMPLES, d_col, 1, 30, 0, 0);
// Bar chart
WebChart('b', "Bar Chart", "W", 0x27ae60, pos, SAMPLES, d_bar, 1, 30, 0, 0);
// Histogram
WebChart('h', "Histogram", "count", 0x9b59b6, pos, SAMPLES, d_hist, 1, 30, 0, 0);
// Stacked column (2 series)
WebChart('s', "Stacked Column", "Series A", 0xe67e22, pos, SAMPLES, d_stk1, 1, 30, 0, 0);
WebChart('s', "", "Series B", 0x2980b9, pos, SAMPLES, d_stk2, 1, 30, 0, 0);
// Table with row labels
WebChart('t', "Weekly Energy|So|Mo|Di|Mi|Do|Fr|Sa", "Haus", 0, 7, 7, d_tbl1, 1, 0, 0, 0);
WebChart('t', "", "Solar", 0, 7, 7, d_tbl2, 1, 0, 0, 0);
WebChart('t', "", "Regen", 0, 7, 7, d_tbl3, 1, 0, 0, 0);
}