CUI

Components / Charts

Charts

Line, bar and donut charts and sparklines, with axes, a crosshair and a tooltip on hover.

Functions: cui_bar_chart, cui_donut_chart, cui_line_chart, cui_sparkline

Charts

Usage

cui_series s[] = { { "Subscriptions", subs, 12 }, { "Cloud spend", cloud, 12 } };
cui_line_chart(ui, "revenue", s, 2, .labels = months, .label_count = 12, .area = true, .smooth = true, .format = "$%.0fk");
cui_bar_chart(ui, "visits", s, 2, .labels = months, .label_count = 6);
cui_bar_chart(ui, "runs", runs, 3, .labels = weeks, .label_count = 8, .stacked = true);   /* passed, retried, failed */
cui_donut_chart(ui, "share", values, labels, 4, .format = "%.0f%%");
cui_sparkline(ui, values, 12, CUI_PX(120), 32, CUI_COLOR_SERIES(0));

Charts draw in once, pick nice axis ticks, show a crosshair that glides between points and a tooltip with every series on hover. Colors come from the theme's series palette, which starts at the accent hue. With area and several series, only the first is filled, so fills never tint each other into a third color.

Options of cui_bar_chart, cui_donut_chart, cui_line_chart

OptionTypeDefaultDescription
.widthcui_sizeWidth: CUI_FILL, CUI_FIT, CUI_PX(n) or CUI_PCT(n); unset uses the component's own.
.heightfloat220default 220
.labelsconst char *const *x axis labels
.label_countintnumber of labels; 0 means one per data point
.areaboolfill under lines
.no_gridboolHides the grid lines.
.no_legendboolHides the legend.
.stackedboolbar chart
.smoothboolcurved lines
.formatconst char *"%.0f"value format for axis and tooltip, default "%.0f"
.minfloatfixed y range when min != max
.maxfloatfixed y range when min != max

cui_series

FieldTypeDescription
nameconst char *shown in the legend and in the hover tooltip
valuesconst float *the series' data, one value per point
countintnumber of values
colorcui_colordefault: series palette

Related

  • Heatmap: A grid of cells colored by value, for one category against another.
  • Calendar heatmap: A year of days as small squares colored by activity.
  • Treemap and radar: A treemap shows the parts of a whole as rectangles sized by value. A radar chart compares items across several axes.
  • Funnel, split bar and waffle: Three charts for shares: a funnel for the steps of a conversion, a single bar split into parts, and a waffle of 100 squares.