DOCXLibWord documents for Ring

Charts

Native OOXML charts and chart data tables.

Native OOXML Charts#

Chart types are stored as pure XML inside the DOCX package with inline data caches, so charts are completely self-contained with no linked spreadsheet.

Chart Methods#

Category-based charts (use string category labels)#

MethodChart TypeBest Used For
addColumnChart(title, cats, series, opts)Vertical barsCategory comparisons across groups
addBarChart(title, cats, series, opts)Horizontal barsLong category labels
addLineChart(title, cats, series, opts)Lines / trendsTime-series, continuous data
addAreaChart(title, cats, series, opts)Filled areasCumulative or stacked trends
addPieChart(title, cats, series, opts)Pie slicesProportions — uses first series only
addDoughnutChart(title, cats, series, opts)Hollow-centre pieProportions with inner space
addChart(type, title, cats, series, opts)Any type aboveGeneric entry point

Numeric-axis charts (no category labels — pass NULL for cats)#

MethodChart TypeBest Used For
addScatterChart(title, series, opts)XY scatterCorrelation, scientific data, irregular X spacing
addBubbleChart(title, series, opts)BubbleThree-variable data — X, Y, and a size dimension

Series Format#

Category-based series (column, bar, line, area, pie, doughnut)#

KeyTypeRequiredDescription
:nameStringYesSeries label shown in the legend
:valuesListYesNumeric values, one per category
:colorStringNoHex colour override, e.g. "4472C4"

Scatter series#

KeyTypeRequiredDescription
:nameStringYesSeries label shown in the legend
:xValuesListYesX-axis numeric values
:yValuesListYesY-axis numeric values (same length as :xValues)
:colorStringNoHex colour override

Bubble series#

KeyTypeRequiredDescription
:nameStringYesSeries label shown in the legend
:xValuesListYesX-axis numeric values
:yValuesListYesY-axis numeric values
:sizesListYesBubble size values — positive numbers, relative scale
:colorStringNoHex colour override

If :color is omitted for any series type the library cycles through an 8-colour Office palette automatically.

Options Reference#

Layout and legend options (all chart types)#

OptionTypeDefaultDescription
:widthCmNumber14Display width in centimetres
:heightCmNumber9Display height in centimetres
:centeredBooltrueCentre chart horizontally on the page
:showLegendBooltrueShow or hide the legend
:legendPosString"r"Legend position: "r" "b" "t" "l"
:showDataLabelsBoolfalseShow value labels on each data point

Axis formatting options (all non-pie/doughnut chart types)#

OptionTypeDefaultDescription
:yAxisMinNumberautoForce value axis lower bound (e.g. 0 to start at zero)
:yAxisMaxNumberautoForce value axis upper bound
:yAxisFormatString"General"Number format for value axis labels — see table below
:yAxisTitleString""Rotated label alongside the value axis
:xAxisTitleString""Label below the category axis (or X axis for scatter/bubble)
:showGridlinesBooltrueShow major gridlines on the value axis
:showDataTableBoolfalseShow source data in a table below the chart (column/bar/line/area only)
:dataTableShowKeysBooltrueInclude colour legend keys in the data table

Axis format string reference#

Format stringExample outputUse case
"General"1234567Default — no formatting
"#,##0"1,234,567Large integers with thousands separator
"$#,##0"$1,234,567Currency (whole dollars)
"$#,##0.00"$1,234,567.89Currency with cents
"0%"32%Percentage (value 0.32 → 32%)
"0.0%"32.5%Percentage with one decimal
"0.00"3.14Two decimal places
"0.0"3.1One decimal place
"0.00E+00"3.14E+06Scientific notation
Note

Note: These are standard OOXML/Excel number format strings. Any Excel format string is accepted — the library passes it through verbatim to the XML.

Category-chart options#

OptionTypeDefaultDescription
:groupingString"clustered"Bar/column/area: "clustered" "stacked" "percentstacked"
:smoothBoolfalseLine chart only — bezier curves
:colorsList(palette)Override full palette with a list of hex strings

Scatter options#

OptionTypeDefaultDescription
:markerStyleString"circle""circle" "square" "diamond" "triangle" "x" "star" "dot" "dash" "none"
:markerSizeNumber7Marker size in half-points
:linesBoolfalseConnect points with lines
:smoothBoolfalseBezier curves on lines (requires :lines = true)
:xAxisMinNumberautoForce X axis lower bound
:xAxisMaxNumberautoForce X axis upper bound
:xAxisFormatString"General"Number format for X axis labels
:xAxisTitleString""X axis label
:yAxisTitleString""Y axis label

Bubble options#

OptionTypeDefaultDescription
:bubble3DBoolfalseRender bubbles with 3-D specular shading
:xAxisMinNumberautoForce X axis lower bound
:xAxisMaxNumberautoForce X axis upper bound
:xAxisFormatString"General"Number format for X axis labels
:xAxisTitleString""X axis label
:yAxisTitleString""Y axis label

Code Examples#

Column chart — three series, data labels:

Ring
doc.addColumnChart(
    "Quarterly Revenue vs Costs ($K)",
    ["Q1 2024", "Q2 2024", "Q3 2024", "Q4 2024"],
    [
        [:name = "Revenue",  :values = [320, 410, 380, 490]],
        [:name = "Costs",    :values = [210, 255, 230, 290]],
        [:name = "Profit",   :values = [110, 155, 150, 200]]
    ],
    [:widthCm = 14, :heightCm = 9, :showDataLabels = true, :legendPos = "b"])

Line chart — smooth curves:

Ring
doc.addLineChart(
    "Monthly Website Traffic",
    ["Jan", "Feb", "Mar", "Apr", "May", "Jun"],
    [
        [:name = "2023", :values = [12000, 14500, 13200, 16800, 18000, 17400]],
        [:name = "2024", :values = [15000, 18200, 17500, 21000, 23500, 22800]]
    ],
    [:smooth = true, :legendPos = "r"])

Pie chart — percent labels:

Ring
doc.addPieChart(
    "Product Revenue Share",
    ["Ring", "PWCT", "Supernova", "PWCT2"],
    [[:name = "Revenue ($K)", :values = [450, 280, 160, 110]]],
    [:showDataLabels = true])

Stacked column — :grouping option:

Ring
doc.addColumnChart(
    "Revenue by Product",
    ["Q1 2024", "Q2 2024", "Q3 2024", "Q4 2024"],
    [
        [:name = "Ring",      :values = [120, 155, 140, 180]],
        [:name = "PWCT",      :values = [80,  95,  90,  110]],
        [:name = "Supernova", :values = [60,  75,  70,   90]]
    ],
    [:grouping = "stacked"])

Scatter chart — markers only (note: NULL for categories, :xValues/:yValues in series):

Ring
doc.addScatterChart(
    "Study Hours vs Exam Score",
    [
        [:name = "Cohort A",
         :xValues = [2, 3, 4, 5, 6, 7, 8, 9, 10],
         :yValues = [45, 52, 60, 67, 73, 79, 84, 88, 93]],
        [:name = "Cohort B",
         :xValues = [1, 2, 4, 5, 7, 8, 9, 10, 11],
         :yValues = [38, 48, 55, 63, 70, 75, 81, 86, 90]]
    ],
    [:markerStyle = "circle", :xAxisTitle = "Study Hours", :yAxisTitle = "Score (%)"])

Scatter chart — smooth lines + markers:

Ring
doc.addScatterChart(
    "Algorithm Complexity",
    [
        [:name = "O(n log n)", :xValues = [100, 500, 1000, 5000, 10000],
         :yValues = [0.8, 5.2, 11.5, 68.3, 145.2], :color = "4472C4"],
        [:name = "O(n^2)",     :xValues = [100, 500, 1000, 5000, 10000],
         :yValues = [1.2, 28.5, 112.4, 2802.5, 11210.0], :color = "C00000"]
    ],
    [:lines = true, :smooth = true, :markerStyle = "diamond",
     :xAxisTitle = "Input Size (n)", :yAxisTitle = "Time (ms)"])

Scatter chart — lines only, no markers:

Ring
doc.addScatterChart(
    "Sine vs Cosine Wave",
    [
        [:name = "sin(x)", :xValues = aX, :yValues = aSin, :color = "2E75B6"],
        [:name = "cos(x)", :xValues = aX, :yValues = aCos, :color = "70AD47"]
    ],
    [:lines = true, :smooth = true, :markerStyle = "none"])

Bubble chart — flat shading (each product is its own series for distinct colours):

Ring
doc.addBubbleChart(
    "Product Portfolio — Share / Growth / Revenue",
    [
        [:name = "Ring",      :xValues = [35], :yValues = [22], :sizes = [450], :color = "4472C4"],
        [:name = "PWCT",      :xValues = [28], :yValues = [15], :sizes = [280], :color = "ED7D31"],
        [:name = "Supernova", :xValues = [18], :yValues = [31], :sizes = [160], :color = "70AD47"]
    ],
    [:xAxisTitle = "Market Share (%)", :yAxisTitle = "Growth (%)"])

Bubble chart — 3-D shading, bubble-size labels, multiple points per series:

Ring
doc.addBubbleChart(
    "Research Projects — Team / Duration / Impact",
    [
        [:name = "Project Alpha",
         :xValues = [3, 5, 8, 12], :yValues = [6, 9, 14, 18],
         :sizes = [45, 120, 280, 500], :color = "1F3864"],
        [:name = "Project Beta",
         :xValues = [2, 4, 7, 10], :yValues = [4, 7, 11, 15],
         :sizes = [30, 90, 200, 380], :color = "C00000"]
    ],
    [:bubble3D = true, :showDataLabels = true,
     :xAxisTitle = "Team Size", :yAxisTitle = "Months"])

Column chart — fixed axis bounds and currency format:

Ring
doc.addColumnChart(
    "Regional Revenue vs Target",
    ["North", "South", "East", "West", "Central"],
    [
        [:name = "Actual",  :values = [1250000, 980000, 1420000, 1100000, 870000]],
        [:name = "Target",  :values = [1200000, 1050000, 1350000, 1150000, 950000]]
    ],
    [:yAxisMin = 0, :yAxisMax = 1800000,
     :yAxisFormat = "$#,##0",
     :yAxisTitle = "Revenue (USD)", :xAxisTitle = "Region",
     :showGridlines = false, :legendPos = "b"])

Line chart — percentage format on value axis:

Ring
doc.addLineChart(
    "Gross Margin Trend",
    ["Q1", "Q2", "Q3", "Q4"],
    [
        [:name = "2023", :values = [0.38, 0.41, 0.39, 0.43]],
        [:name = "2024", :values = [0.41, 0.44, 0.42, 0.46]]
    ],
    [:yAxisMin = 0, :yAxisMax = 0.6,
     :yAxisFormat = "0.0%",
     :yAxisTitle = "Gross Margin", :xAxisTitle = "Quarter"])

Scatter chart — fixed bounds with formatted numeric axes:

Ring
doc.addScatterChart(
    "Ad Spend vs Revenue",
    [
        [:name = "2024",
         :xValues = [50000, 100000, 200000, 350000],
         :yValues = [210000, 430000, 870000, 1500000]]
    ],
    [:xAxisMin = 0, :xAxisMax = 400000,
     :yAxisMin = 0, :yAxisMax = 2000000,
     :xAxisFormat = "$#,##0", :yAxisFormat = "$#,##0",
     :xAxisTitle = "Ad Spend (USD)", :yAxisTitle = "Revenue (USD)",
     :markerStyle = "circle", :lines = true, :smooth = true])

Pie and Doughnut: Single Series Only#

Pie and doughnut charts render only the first series. If more than one series is passed, DOCXLib prints a warning to the console and silently discards the extra series. Use a column or bar chart when you need to compare multiple series.

Ring
# WRONG — triggers warning; only "2023" series will appear in the chart
doc.addPieChart("Sales", cats, [
    [:name = "2023", :values = [380, 240, 140, 90]],
    [:name = "2024", :values = [450, 280, 160, 110]]   # ignored
], [])

# CORRECT — grouped column for side-by-side comparison
doc.addColumnChart("Sales 2023 vs 2024", cats, [
    [:name = "2023", :values = [380, 240, 140, 90]],
    [:name = "2024", :values = [450, 280, 160, 110]]
], [:legendPos = "b"])

OOXML Internals#

Each chart adds three components to the DOCX package automatically:

FilePurpose
word/charts/chartN.xmlFull chart definition — data stored inline as XML caches; no spreadsheet needed
word/charts/_rels/chartN.xml.relsChart relationship manifest (no external dependencies)
Drawing reference in document.xml<c:chart r:id="rIdN"/> anchors the chart in the document body

[Content_Types].xml receives one Override entry per chart automatically.

Category-based charts use <c:cat> + <c:val> for series data. Scatter and bubble charts use <c:xVal> + <c:yVal> (and <c:bubbleSize> for bubble) instead — both axes are <c:valAx> rather than <c:catAx> + <c:valAx>.

Note

Compatibility: Charts render in Word 2016+, Microsoft 365, and LibreOffice 7+. The DrawingML chart schema (http://schemas.openxmlformats.org/drawingml/2006/chart) is part of the ECMA-376 standard.

Chart Data Tables#

The :showDataTable = true option renders the chart's source data in a compact bordered table directly beneath the plot area — useful for printed reports where readers need exact values.

Options#

OptionTypeDefaultDescription
:showDataTableBoolfalseRender source data table beneath the chart
:dataTableShowKeysBooltrueInclude colour legend keys in the leftmost column

Supported chart types: column, bar, line, area Not applicable to: pie, doughnut, scatter, bubble

Code Examples#

Column chart with data table and legend keys:

Ring
doc.addColumnChart(
    "Quarterly Revenue",
    ["Q1", "Q2", "Q3", "Q4"],
    [
        [:name = "Ring", :values = [320000, 410000, 380000, 490000]],
        [:name = "PWCT", :values = [210000, 265000, 245000, 305000]]
    ],
    [:yAxisFormat = "$#,##0", :legendPos = "b",
     :showDataTable = true, :dataTableShowKeys = true])

Line chart — data table without colour keys:

Ring
doc.addLineChart(
    "Monthly Active Users",
    ["Jan", "Feb", "Mar", "Apr", "May", "Jun"],
    [[:name = "Web",    :values = [142, 158, 171, 185, 201, 218]],
     [:name = "Mobile", :values = [89,  104, 118, 135, 152, 171]]],
    [:smooth = true, :showDataTable = true, :dataTableShowKeys = false])

Combined with chart style presets:

Ring
doc.setChartDefaults([
    :widthCm       = 14,
    :legendPos     = "b",
    :showDataTable = true,
    :dataTableShowKeys = true,
    :yAxisFormat   = "#,##0"
])

# Every subsequent chart automatically gets a data table
doc.addColumnChart("Revenue", quarters, series, [])
doc.addLineChart("Trend", months, trendSeries, [:smooth = true])

# Remove all chart defaults
doc.clearChartDefaults()
DOCXLib - Word documents for Ring, made with ringdoc.