Abstract base class inherited by Chart and ChartEx. Holds all
shared fields (palette, titles, axis params, legend/label settings) and the
shared private helpers (render_color_core, render_color,
set_axis_params, validate_input).
Users should not instantiate EncharterBase directly; use
encharter() instead.
Public fields
xmlThe raw xml2 object containing the chart space.
series_dataA list containing all added data series and their styles.
typeThe default chart type for the object (e.g.,
"lineChart").paletteA character vector of six-digit hex colors. Series added with
color = NULLtake the next color of the palette. In pie, doughnut and pie-of-pie charts, and in a chart with a single bubble series at its default color, the palette colors the data points. Defaults to the standard Office theme palette.chart_titleNamed list with elements
text(character) andstyle(list of font/fill/line options) for the main chart title.x_titleNamed list with elements
textandstylefor the primary X-axis title.y_titleNamed list with elements
textandstylefor the primary Y-axis title.chart_styleNamed list controlling the outer chart area:
fill(hex),line(hex),line_width(numeric).plot_styleNamed list controlling the inner plot area:
fill(hex),line(hex),line_width(numeric).label_paramsNamed list of global data label defaults:
show_val,show_cat,show_legend_key,leader_lines(logicals),pos,sep,fill(character),style(list).legend_paramsNamed list of legend defaults:
pos(character),overlay("0"/"1"),style(list).axis_paramsNamed list with one entry per axis (
x,x2,y,y2). Each entry is a named list of scaling, formatting, and style parameters. Modified via$set_x_axis(), etc.
Methods
EncharterBase$set_chart_title()
Set the chart's main title.
Usage
EncharterBase$set_chart_title(
text,
font_size = NULL,
font_name = NULL,
font_color = NULL,
bold = NULL,
italic = NULL,
fill = NULL,
line = NULL,
line_width = NULL
)Arguments
textTitle string. Accepts a plain character or an
openxlsx2::fmt_txt()object for rich-text formatting.font_sizeNumeric font size in points (e.g.
14).font_nameFont typeface name (e.g.
"Arial").font_colorSix-digit hex color for the title text (e.g.
"FF0000"for red).boldLogical;
TRUErenders the title in bold.italicLogical;
TRUErenders the title in italics.fillSix-digit hex color for the title background box.
lineSix-digit hex color for the title border.
line_widthNumeric border width in points.
Examples
ec("line")$set_chart_title("Monthly Sales", font_size = 14, bold = TRUE)EncharterBase$set_x_title()
Set the primary X-axis title.
Usage
EncharterBase$set_x_title(
text,
font_size = NULL,
font_name = NULL,
font_color = NULL,
bold = NULL,
italic = NULL,
fill = NULL,
line = NULL,
line_width = NULL
)Arguments
textTitle string.
font_sizeNumeric font size in points.
font_nameFont typeface name.
font_colorSix-digit hex color for the title text.
boldLogical.
italicLogical.
fillSix-digit hex color for the title background box.
lineSix-digit hex color for the title border.
line_widthNumeric border width in points.
Examples
ec("line")$set_x_title("Month", font_color = "888888", italic = TRUE)EncharterBase$set_y_title()
Set the primary Y-axis title.
Usage
EncharterBase$set_y_title(
text,
font_size = NULL,
font_name = NULL,
font_color = NULL,
bold = NULL,
italic = NULL,
fill = NULL,
line = NULL,
line_width = NULL
)Arguments
textTitle string.
font_sizeNumeric font size in points.
font_nameFont typeface name.
font_colorSix-digit hex color for the title text.
boldLogical.
italicLogical.
fillSix-digit hex color for the title background box.
lineSix-digit hex color for the title border.
line_widthNumeric border width in points.
Examples
ec("line")$set_y_title("Revenue (USD)", bold = TRUE)EncharterBase$set_x_axis()
Set primary X-axis scaling, tick marks, and label formatting. Arguments that are not given keep their current value, so the method can be called several times.
Usage
EncharterBase$set_x_axis(
min = NULL,
max = NULL,
major = NULL,
minor = NULL,
major_time = NULL,
minor_time = NULL,
base_time = NULL,
major_tick = NULL,
minor_tick = NULL,
format = NULL,
log_base = NULL,
rev = NULL,
color = NULL,
font_name = NULL,
font_size = NULL,
bold = NULL,
italic = NULL,
font_color = NULL,
rotation = NULL,
grid_color = NULL,
grid_lines = NULL,
minor_grid_color = NULL,
minor_grid_lines = NULL,
cross_between = NULL,
line_width = NULL,
grid_width = NULL,
minor_grid_width = NULL,
crosses = NULL,
crosses_at = NULL,
label_pos = NULL,
tick_lbl_skip = NULL,
tick_mark_skip = NULL,
disp_units = NULL
)Arguments
min, maxNumeric axis limits.
major, minorNumeric major/minor unit intervals. For date axes, unit is set by
major_time/minor_time.major_time, minor_timeTime unit for major/minor steps on date axes:
"days","months", or"years".base_timeBase time unit for date axes:
"days","months", or"years".major_tick, minor_tickTick mark style:
"cross","in","out", or"none".formatNumber or date format string (e.g.
"#,##0","yyyy-mm-dd").log_baseNumeric base for logarithmic scaling (e.g.
10).revLogical to reverse the value order
colorSix-digit hex color for the axis line.
font_nameFont typeface name for tick labels.
font_sizeNumeric label font size in points.
bold, italicLogical font style for tick labels.
font_colorSix-digit hex color for axis tick labels. Defaults to
colorwhen not set.rotationNumeric label rotation in degrees. Extended charts such as waterfall or histogram do not write it, because spreadsheet software offers no label rotation for them; a warning is issued on rendering.
grid_color, minor_grid_colorSix-digit hex colors for major/minor grid_lines.
grid_lines, minor_grid_linesShow grid lines.
TRUE/FALSEto toggle; or a dash style string ("dash","dot","dashDot", etc.) to show styled lines.cross_betweenWhere the value axis crosses:
"between"(default, between categories) or"midCat"(through categories).line_width, grid_width, minor_grid_widthNumeric widths in points for the axis line, major grid lines, and minor grid lines respectively.
crossesWhere this axis crosses its perpendicular axis:
"autoZero"(default),"min", or"max".crosses_atNumeric axis value at which to cross. Overrides
crosseswhen supplied.label_posTick label position:
"nextTo"(default),"high","low", or"none".tick_lbl_skipInteger (>= 1); draw a tick label only every n-th category (category axes only).
tick_mark_skipInteger (>= 1); draw a tick mark only every n-th category (category axes only).
disp_unitsDisplay units for value axes: a built-in unit string (
"hundreds","thousands","tenThousands","hundredThousands","millions","tenMillions","hundredMillions","billions","trillions") or a positive number for a custom unit.
Examples
ec("line")$set_x_axis(
min = 0, max = 12,
major_tick = "out",
grid_lines = TRUE,
font_color = "666666",
rotation = -45
)EncharterBase$set_y_axis()
Set primary Y-axis scaling, tick marks, and label formatting. Arguments that are not given keep their current value, so the method can be called several times.
Usage
EncharterBase$set_y_axis(
min = NULL,
max = NULL,
major = NULL,
minor = NULL,
major_time = NULL,
minor_time = NULL,
base_time = NULL,
major_tick = NULL,
minor_tick = NULL,
format = NULL,
log_base = NULL,
rev = NULL,
color = NULL,
font_name = NULL,
font_size = NULL,
bold = NULL,
italic = NULL,
font_color = NULL,
rotation = NULL,
grid_color = NULL,
grid_lines = NULL,
minor_grid_color = NULL,
minor_grid_lines = NULL,
cross_between = NULL,
line_width = NULL,
grid_width = NULL,
minor_grid_width = NULL,
crosses = NULL,
crosses_at = NULL,
label_pos = NULL,
tick_lbl_skip = NULL,
tick_mark_skip = NULL,
disp_units = NULL
)Arguments
min, maxNumeric axis limits.
major, minorNumeric major/minor unit intervals.
major_time, minor_timeTime unit for date axes:
"days","months", or"years".base_timeBase time unit for date axes.
major_tick, minor_tickTick mark style:
"cross","in","out", or"none".formatNumber format string.
log_baseNumeric base for logarithmic scaling.
revLogical to reverse the value order
colorSix-digit hex color for the axis line.
font_nameFont typeface name.
font_sizeNumeric label font size in points.
bold, italicLogical font style.
font_colorSix-digit hex color for axis tick labels.
rotationNumeric label rotation in degrees. Extended charts such as waterfall or histogram do not write it, because spreadsheet software offers no label rotation for them; a warning is issued on rendering.
grid_color, minor_grid_colorHex colors for major/minor grid lines.
grid_lines, minor_grid_linesTRUE/FALSEor a dash style string.cross_between"between"or"midCat".line_width, grid_width, minor_grid_widthNumeric widths in points.
crosses"autoZero","min", or"max".crosses_atNumeric crossing value; overrides
crosses.label_pos"nextTo","high","low", or"none".tick_lbl_skip, tick_mark_skipInteger (>= 1); label/tick every n-th category (category axes only).
disp_unitsDisplay units: a built-in unit string (e.g.
"thousands","millions") or a positive number for a custom unit. Value axes only.
Examples
ec("bar")$set_y_axis(
min = 0,
max = 1000,
major = 200,
format = "#,##0",
grid_lines = TRUE,
grid_color = "DDDDDD"
)EncharterBase$set_data_label_style()
Configure global data label defaults for all series.
Per-series overrides can be set via the show_val/show_cat
arguments in $add_series().
Usage
EncharterBase$set_data_label_style(
show_val = TRUE,
show_cat = FALSE,
show_legend_key = FALSE,
pos = "t",
show_ser_name = FALSE,
show_percent = FALSE,
show_bubble_size = FALSE,
format = NULL,
...
)Arguments
show_valLogical; show the data point value. Default
TRUE.show_catLogical; show the category name. Default
FALSE.show_legend_keyLogical; show the series color swatch next to each label. Default
FALSE.posLabel position:
"t"(top, default),"b"(bottom),"l","r","ctr","inEnd","outEnd","bestFit".show_ser_nameLogical; show the series name. Default
FALSE.show_percentLogical; show the percentage (pie-type charts). Default
FALSE.show_bubble_sizeLogical; show the bubble size (bubble charts). Default
FALSE.formatNumber format string for the labels (e.g.
"#,##0","0.0%")....Additional font style arguments passed to the label text properties (e.g.
font_size,font_color,bold).
Examples
ec("bar")$set_data_label_style(show_val = TRUE, pos = "outEnd", font_size = 9)EncharterBase$set_legend_style()
Configure the chart legend.
Usage
EncharterBase$set_legend_style(
pos = NULL,
align = "ctr",
overlay = FALSE,
font_size = NULL,
font_name = NULL,
bold = NULL,
italic = NULL,
color = NULL
)Arguments
posLegend position:
"t","b","l","r", or"none"to hide. Not given, the current position is kept:"r"for standard and"t"for extended charts, unless set before.alignLegend alignment relative to the chart:
"ctr"(default),"min", or"max".overlayLogical; if
TRUEthe legend overlaps the plot area.font_sizeNumeric font size in points.
font_nameFont typeface name.
bold, italicLogical font style.
colorSix-digit hex color for the legend text.
Examples
ec("line")$set_legend_style(pos = "b", font_size = 9)EncharterBase$set_chart_style()
Style the outer chart area (background and border).
Arguments
fillSix-digit hex color for the chart background. Default
"FFFFFF".lineSix-digit hex color for the chart border.
NULLfor no border.line_widthNumeric border width in points. Default
1.
Examples
ec("bar")$set_chart_style(fill = "F5F5F5", line = "CCCCCC", line_width = 0.5)EncharterBase$set_plot_style()
Style the inner plot area (background and border).
Arguments
fillSix-digit hex color for the plot area background.
NULLfor transparent.lineSix-digit hex color for the plot area border.
line_widthNumeric border width in points. Default
1.
Examples
ec("line")$set_plot_style(fill = "FAFAFA")Examples
## ------------------------------------------------
## Method `EncharterBase$set_chart_title()`
## ------------------------------------------------
ec("line")$set_chart_title("Monthly Sales", font_size = 14, bold = TRUE)
## ------------------------------------------------
## Method `EncharterBase$set_x_title()`
## ------------------------------------------------
ec("line")$set_x_title("Month", font_color = "888888", italic = TRUE)
## ------------------------------------------------
## Method `EncharterBase$set_y_title()`
## ------------------------------------------------
ec("line")$set_y_title("Revenue (USD)", bold = TRUE)
## ------------------------------------------------
## Method `EncharterBase$set_x_axis()`
## ------------------------------------------------
ec("line")$set_x_axis(
min = 0, max = 12,
major_tick = "out",
grid_lines = TRUE,
font_color = "666666",
rotation = -45
)
## ------------------------------------------------
## Method `EncharterBase$set_y_axis()`
## ------------------------------------------------
ec("bar")$set_y_axis(
min = 0,
max = 1000,
major = 200,
format = "#,##0",
grid_lines = TRUE,
grid_color = "DDDDDD"
)
## ------------------------------------------------
## Method `EncharterBase$set_data_label_style()`
## ------------------------------------------------
ec("bar")$set_data_label_style(show_val = TRUE, pos = "outEnd", font_size = 9)
## ------------------------------------------------
## Method `EncharterBase$set_legend_style()`
## ------------------------------------------------
ec("line")$set_legend_style(pos = "b", font_size = 9)
## ------------------------------------------------
## Method `EncharterBase$set_chart_style()`
## ------------------------------------------------
ec("bar")$set_chart_style(fill = "F5F5F5", line = "CCCCCC", line_width = 0.5)
## ------------------------------------------------
## Method `EncharterBase$set_plot_style()`
## ------------------------------------------------
ec("line")$set_plot_style(fill = "FAFAFA")
## ------------------------------------------------
## Method `EncharterBase$print()`
## ------------------------------------------------
ec("line")
#> An encharter object
#> Number of Series: 0
