March Docs

ScrollChart

lib/scroll/scroll_chart.march — Charts for notebooks.

import ScrollChart

ScrollChart.new()
|> ScrollChart.title("French electricity load forecast errors")
|> ScrollChart.x_label("Delivery lead (hours)")
|> ScrollChart.y_label("Mean absolute error (MW)")
|> ScrollChart.line("Weekly naive", hours, naive_mae)
|> ScrollChart.line("Chronos-2 Small", hours, chronos_mae)
|> ScrollChart.band("Chronos P10–P90", hours, p10, p90)
|> ScrollChart.show()

Every series gets a legend entry and a hover tooltip, and the chart fills the notebook's width. show prints one __SCROLL_BLOB__ block of type application/vnd.scroll.chart+json holding a Vega-Lite spec, which the notebook renders interactively and HTML export embeds as a static SVG. to_spec returns the spec itself, for use outside a notebook.

The x values of one chart are all numbers (line, points, band), all ISO dates (line_dates, points_dates, band_dates) or all category labels (bars).

Types

typeXValuesXValues = Numbers(List(Float)) | Dates(List(String)) | Labels(List(String))#

The x values of one layer.

typeLayerLayer = Layer(String, String, XValues, List(Float), List(Float))#

One layer: a mark, the series name shown in the legend, x values, and one or two y value lists (a band has a low and a high).

typeChartChart = Chart(String, String, String, Int, Bool, List(Layer))#

title, x label, y label, height in pixels, y axis starts at zero, layers (newest first).

Functions

fnbandband(c : Chart, name : String, xs : List(Float), lows : List(Float), highs : List(Float)) : Chart#

Add a shaded band between lows[i] and highs[i], e.g. a prediction interval.

fnband_datesband_dates(c : Chart, name : String, dates : List(String), lows : List(Float), highs : List(Float)) : Chart#

Add a shaded band over ISO dates.

fnbarsbars(c : Chart, name : String, labels : List(String), values : List(Float)) : Chart#

Add bars, one per category label; several bars layers sit side by side.

fnheightheight(c : Chart, h : Int) : Chart#

Set the chart's height in pixels (its width follows the notebook).

fnlineline(c : Chart, name : String, xs : List(Float), ys : List(Float)) : Chart#

Add a line through (xs[i], ys[i]).

fnline_datesline_dates(c : Chart, name : String, dates : List(String), ys : List(Float)) : Chart#

Add a line over ISO dates (YYYY-MM-DD, optionally with a time).

fnmake_sentinelmake_sentinel(spec : String) : String#

The sentinel block that displays spec (for tests and composition).

fnmimemime() : String do "application/vnd.scroll.chart+json" end#

The MIME type the notebook renders as a chart.

fnnewnew() : Chart do Chart("", "", "", 320, false, Nil) end#

An empty chart, 320 pixels high and as wide as the notebook.

fnpointspoints(c : Chart, name : String, xs : List(Float), ys : List(Float)) : Chart#

Add unconnected points at (xs[i], ys[i]).

fnpoints_datespoints_dates(c : Chart, name : String, dates : List(String), ys : List(Float)) : Chart#

Add points over ISO dates.

fnshowshow(c : Chart) : Unit#

Display the chart in the notebook.

fntitletitle(c : Chart, t : String) : Chart#

Set the chart's title.

fnto_specto_spec(c : Chart) : String#

The chart as a Vega-Lite v5 spec (one line of JSON).

fnx_labelx_label(c : Chart, l : String) : Chart#

Set the x axis label.

fny_from_zeroy_from_zero(c : Chart) : Chart#

Start the y axis at zero instead of fitting it to the data.

fny_labely_label(c : Chart, l : String) : Chart#

Set the y axis label.