docx
    Preparing search index...

    Class ChartRun

    Represents a chart in a WordprocessingML document: a column, bar, line, area, pie, doughnut, pie of pie, bar of pie, radar, scatter, bubble or stock chart, drawn by Word from its data in the document's theme, as a chart made with Word's Insert Chart is. A column, line or area chart's series can each be drawn another way, as Word's "Combo" charts are.

    The chart is a part of its own (word/charts/chart1.xml), with its data in an embedded workbook, so Word's "Edit Data" opens it in Excel. It sits inline with text unless floating is set, and goes in a paragraph, including in a table, header, footer or footnote. Without a description in its altText, the chart is described for screen readers from its data.

    Reference: http://officeopenxml.com/drwOverview.php

    new Paragraph({
    children: [
    new ChartRun({
    type: "column",
    title: "Sales",
    categories: ["Jan", "Feb", "Mar"],
    series: [
    { name: "2024", values: [10, 20, 30] },
    { name: "2025", values: [15, 25, null] },
    ],
    }),
    ],
    });

    Hierarchy (View Summary)

    Index
    • Parameters

      Returns ChartRun

      If there are no series or categories, a value isn't a finite number or null, a series has more values than there are categories or an option the way it is drawn doesn't have, a pie chart has more than one series or a pie or doughnut chart a negative value, a scatter or bubble point isn't finite numbers, a data label position isn't one the chart's type has, a trendline can't be fitted to its series' values, a stock chart's high is below its low, a hidden legend entry isn't one of the legend's, or an option is out of its range

    • get writtenAs(): readonly BaseXmlComponent[] | undefined
      Internal

      The components written in this one's place, one after another, when it can't be written as a single element, such as a run with another run in its children. Undefined when it is written as itself.

      Returns readonly BaseXmlComponent[] | undefined

    • Prepares this component and its children for XML serialization.

      This method is called by the Formatter to convert the component tree into an object structure compatible with the xml library (https://www.npmjs.com/package/xml). It recursively processes all children and handles special cases like attribute-only elements and empty elements.

      The method can be overridden by subclasses to customize XML representation or execute side effects during serialization (e.g., creating relationships).

      Parameters

      • context: IContext

        The serialization context containing document state

      Returns IXmlableObject | undefined

      The XML-serializable object, or undefined to exclude from output

      // Override to add custom serialization logic
      prepForXml(context: IContext): IXmlableObject | undefined {
      // Custom logic here
      return super.prepForXml(context);
      }