Skip to contents

`xl_chart()` builds a chart from one or more [xl_chart_series()] and places it on a sheet, anchored to a cell. Pass one or a list of them as `xl_sheet(chart = )`.

Placement works exactly as it does for [xl_image()] — `at`, `scale`, `offset`, `position`, `description` and `decorative` mean the same things, because libxlsxwriter describes both with the same fields.

Usage

xl_chart(
  type,
  series,
  title = NULL,
  at = "A1",
  scale = 1,
  offset = NULL,
  position = "move_and_size",
  description = NULL,
  decorative = FALSE,
  style = NA
)

Arguments

type

The chart type: `"column"`, `"bar"`, `"line"`, `"pie"`, `"doughnut"`, `"area"`, `"scatter"`, `"radar"`, and the stacked, percent-stacked, smoothed and marker variants.

series

One [xl_chart_series()], or a list of them.

title

The chart title: a string, or a range holding one. `FALSE` removes the title Excel would otherwise generate.

at

The cell the chart's top-left corner is anchored to.

scale

Scale factor: one number for both axes, or `c(x, y)`.

offset

Offset from the anchor cell's corner in pixels, as `c(x, y)`.

position

How the chart behaves when rows and columns change size; see [xl_image()].

description

Alt text, for screen readers.

decorative

Mark the chart as decorative, so screen readers skip it.

style

Excel's built-in chart style, 1–48.

Value

An `xl_chart` object.

What a chart type supports

Excel silently drops options a chart type cannot use, so writexl refuses them instead, naming the types that would work. Pie and doughnut charts have no axes; only a doughnut has a hole; only pie and doughnut rotate; up-down bars and high-low lines are line-only; the series gap and overlap are bar and column only.

See also

[xl_chart_series], [xl_sheet]

Other images and charts: xl_chart_series(), xl_image()

Examples

xl_chart("column", xl_chart_series(values = list(cols = "revenue")))
#> <xl_chart: column, 1 series>
xl_chart("pie", xl_chart_series(values = "Data!B2:B5"), title = "Share")
#> <xl_chart: pie, 1 series, "Share">