docx
    Preparing search index...

    Class ChartDataPatch

    Replaces the data of a chart in a template, found by a placeholder in its alt text, such as {{sales}}, keeping its look: its type, title, colours, fonts, labels, axes and legend. Give it as a patch to patchDocument, with the placeholder's key.

    • Each series' name and data are replaced, in the order the series are plotted, and its data is written in the chart's own number formats, such as "0%".
    • New series copy the look of the template's last series, in their own colour, the next of the theme's accents, as ChartRun colours them. Series the new data doesn't have are removed, with any axes only they used.
    • Points past the new data lose their own colours and labels. When each slice of a pie has its own colour, new slices take the next of the theme's accents.
    • The chart's workbook is replaced with one holding the new data, so Word's "Edit Data" opens it.
    • The alt text's description is replaced with a description of the new data.

    The patch checks the data against the chart's type when the document is patched: a pie chart has one series, a scatter or bubble chart's series have points, and a stock chart has prices, with opening prices and volumes if the template's has them. Put the placeholder in the chart's alt text in Word, in "Alt Text" or "Edit Alt Text". A placeholder in the document's text is left as it is.

    await patchDocument({
    outputType: "nodebuffer",
    data: template,
    patches: {
    sales: new ChartDataPatch({
    categories: ["Jan", "Feb", "Mar"],
    series: [{ name: "2025", values: [10, 20, 30] }],
    }),
    },
    });

    Hierarchy (View Summary)

    Index
    type: "drawing" = PatchType.DRAWING
    • Replaces the chart's data, and its workbook, and describes it in its alt text.

      Parameters

      Returns void

      If the drawing isn't a chart, is a type of chart this can't patch, such as a surface chart, or has something that refers to its workbook's cells other than its data, such as labels from cells, or the data isn't for the chart's type, such as two series for a pie chart