Skip to main content

Generate charts from your test data and save them as standalone HTML files. Charts are useful for visualizing benchmark results, test metrics, or any numeric data produced during a run.

Info

What you will learn

  • Which chart types are supported.
  • How to create single-series and multi-series charts.
  • How to export charts to HTML.

Supported chart types#

  • Pie
  • Bar (vertical bars)
  • Line
  • Area (a filled line)
  • Column (horizontal bars)

Values are i32.

Single-series chart#

The Chart type needs no browser. Build it, add data points, and save it:

Multi-series chart#

The labels come from the primary series. An extra series is matched to them by label, and a label it lacks is drawn as 0.

Output#

save_chart (and Chart::save) writes one HTML file that draws the chart with Chart.js. The file embeds the data but loads the Chart.js library from cdn.jsdelivr.net, so opening it needs internet access.

Tip

Open it in any browser or attach it to test reports.

Related methods on BaseCase:

  • display_chart() saves the chart to a temporary chart.html and opens it in the test’s browser, returning the path.
  • extract_chart() returns the chart as a JSON string with the title, type, labels and datasets.

sbrs mkchart --file results.html writes a small fixed example chart (a Passed/Failed/Skipped bar chart) to edit by hand.

Troubleshooting#

Chart file is empty

Likely cause: No data points added.

Fix: Call add_data_point before save_chart.

No chart created error

Likely cause: add_data_point or save_chart before any create_*_chart.

Fix: Create the chart first.

Extra series shows zeros

Likely cause: Its labels differ from the primary series.

Fix: Use the same labels as the primary series.

Chart does not render

Likely cause: Offline: Chart.js is loaded from a CDN.

Fix: Open the file on a machine with internet access, or edit the <script src> to point at a local copy.