moodle/moodle · error

Chart renderer must implement

Error message

Chart renderer must implement 

What it means

Thrown by Settings::setChartRenderer() when the supplied class name does not implement the IRenderer interface. The method's contract (@param class-string<IRenderer>) is checked at runtime because PHP cannot enforce it natively; passing any fully-qualified class name that is not a valid chart renderer (typically anything other than PhpOffice\PhpSpreadsheet\Chart\Renderer\JpGraph or a custom implementation of IRenderer) triggers it. The truncated message in the source continues with the expected interface name.

Solutions

  1. Pass a class implementing PhpOffice\PhpSpreadsheet\Chart\Renderer\IRenderer, e.g. \PhpOffice\PhpSpreadsheet\Chart\Renderer\JpGraph or ...\Renderer\LibreOffice
  2. Verify with class_exists() and is_a($cls, IRenderer::class, true) before calling
  3. Check the class's fully-qualified namespace against your installed package version
  4. Write a custom renderer implementing IRenderer if you need a different backend

Example fix

// before
Settings::setChartRenderer('JpGraph'); // not FQCN / wrong interface
// after
if (is_a(\PhpOffice\PhpSpreadsheet\Chart\Renderer\JpGraph::class, IRenderer::class, true)) {
    Settings::setChartRenderer(\PhpOffice\PhpSpreadsheet\Chart\Renderer\JpGraph::class);
}
Defensive patterns

Strategy: validation

Validate before calling

$cls = '\\PhpOffice\\PhpSpreadsheet\\Chart\\Renderer\\JpGraph';
if (!class_exists($cls) || !is_a($cls, IRenderer::class, true)) {
    throw new InvalidArgumentException('$cls must implement IRenderer');
}
Settings::setChartRenderer($cls);

Type guard

function isValidRenderer(string $cls): bool {
    return class_exists($cls) && is_a($cls, \PhpOffice\PhpSpreadsheet\Chart\Renderer\IRenderer::class, true);
}

Try / catch

try {
    Settings::setChartRenderer($config['chartRenderer']);
} catch (\PhpOffice\PhpSpreadsheet\Exception $e) {
    // fall back to default renderer or log config error
}

Prevention

When it happens

Trigger: Calling Settings::setChartRenderer('Some\Class') where the class exists but doesn't implement IRenderer, or where the string is a typo/nonexistent class (is_a with a missing class returns false).

Common situations: Configuring JpGraph or Graphs renderer with a mistyped namespace; switching to a custom renderer that doesn't implement IRenderer; copy-pasted config from an older PhpSpreadsheet version with renamed renderer classes.

Understand the failure class

Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.

Related errors


AI-assisted analysis of moodle/moodle@48ea8c3322 (2026-09-14). Data as JSON: /api/errors/294c34a8a3599d01. Report an issue: GitHub.

Appendix: source

Thrown at public/lib/phpspreadsheet/phpspreadsheet/src/PhpSpreadsheet/Settings.php:62

        return Calculation::getInstance()->setLocale($locale);
    }

    public static function getLocale(): string
    {
        return Calculation::getInstance()->getLocale();
    }

    /**
     * Identify to PhpSpreadsheet the external library to use for rendering charts.
     *
     * @param class-string<IRenderer> $rendererClassName Class name of the chart renderer
     *    eg: PhpOffice\PhpSpreadsheet\Chart\Renderer\JpGraph
     */
    public static function setChartRenderer(string $rendererClassName): void
    {
        // We want phpstan to validate caller, but still need this test
        if (!is_a($rendererClassName, IRenderer::class, true)) { //* @phpstan-ignore-line
            throw new Exception('Chart renderer must implement ' . IRenderer::class);
        }

        self::$chartRenderer = $rendererClassName;
    }

    public static function unsetChartRenderer(): void
    {
        self::$chartRenderer = null;
    }

    /**
     * Return the Chart Rendering Library that PhpSpreadsheet is currently configured to use.
     *
     * @return null|class-string<IRenderer> Class name of the chart renderer
     *    eg: PhpOffice\PhpSpreadsheet\Chart\Renderer\JpGraph
     */
    public static function getChartRenderer(): ?string
    {

View on GitHub (pinned to 48ea8c3322)