qax-os/excelize · error

unsupported chart type %d

Error message

unsupported chart type %d

What it means

Excelize throws this when a ChartType value passed to AddChart/AddChartSheet is not among the chart types the library can generate, or when a parsed chart XML contains a type the writer cannot map back. getChartOptions rejects the chartType during option building.

Source

Thrown at errors.go:405

	return fmt.Errorf("row %d has already been written", row)
}

// newStreamSetRowOrderError defined the error message on calling the SetRow
// function before the order function.
func newStreamSetRowOrderError(name string) error {
	return fmt.Errorf("must call the %s function before the SetRow function", name)
}

// newUnknownFilterTokenError defined the error message on receiving a unknown
// filter operator token.
func newUnknownFilterTokenError(token string) error {
	return fmt.Errorf("unknown operator: %s", token)
}

// newUnsupportedChartType defined the error message on receiving the chart
// type are unsupported.
func newUnsupportedChartType(chartType ChartType) error {
	return fmt.Errorf("unsupported chart type %d", chartType)
}

// newUnsupportedPivotCacheSourceType defined the error message on receiving the
// source type of pivot table cache.
func newUnsupportedPivotCacheSourceType(sourceType string) error {
	return fmt.Errorf("unsupported pivot table cache source type: %s", sourceType)
}

// newUnzipSizeLimitError defined the error message on unzip size exceeds the
// limit.
func newUnzipSizeLimitError(unzipSizeLimit int64) error {
	return fmt.Errorf("unzip size exceeds the %d bytes limit", unzipSizeLimit)
}

// newViewIdxError defined the error message on receiving a invalid sheet view
// index.
func newViewIdxError(viewIndex int) error {
	return fmt.Errorf("view index %d out of range", viewIndex)

View on GitHub (pinned to f2483381fb)

Solutions

  1. Use one of the exported excelize chart constants (e.g. excelize.Col, excelize.Line, excelize.Pie3D) instead of raw integers.
  2. Check your excelize version (go list -m github.com/xuri/excelize/v2) and update so the desired chart constant exists.
  3. Verify the Chart.Type field is not left at its zero value after constructing the struct with named fields only.
  4. If the error comes from a loaded file, replace or remove the unsupported chart before re-saving.

Example fix

// before
err := f.AddChart("Sheet1", "A1", &excelize.Chart{Type: 9999})
// after
err := f.AddChart("Sheet1", "A1", &excelize.Chart{Type: excelize.Col})
Defensive patterns

Strategy: type-guard

Validate before calling

var knownChartTypes = map[excelize.ChartType]bool{
    excelize.Area: true, excelize.AreaStacked: true,
    excelize.Bar: true, excelize.Col: true,
    excelize.Line: true, excelize.Pie: true, excelize.Pie3D: true,
    excelize.Doughnut: true, excelize.Radar: true,
    excelize.Scatter: true, excelize.Surface3D: true,
}
func isKnownChartType(t excelize.ChartType) bool { return knownChartTypes[t] }

Type guard

func chartTypeGuard(t excelize.ChartType) (excelize.ChartType, bool) {
    if isKnownChartType(t) {
        return t, true
    }
    return excelize.Col, false // default fallback
}

Try / catch

if err := f.AddChart(sheet, cell, chart); err != nil {
    if strings.Contains(err.Error(), "unsupported chart type") {
        log.Printf("chart type %d unsupported; falling back to column chart", chart.Type)
        chart.Type = excelize.Col
        return f.AddChart(sheet, cell, chart)
    }
    return err
}

Prevention

When it happens

Trigger: Calling f.AddChart(sheet, cell, &excelize.Chart{Type: someChartType}) or f.AddChartSheet with an invalid, zero, or out-of-range ChartType constant; or loading a workbook whose chart XML uses an unsupported chart type and re-saving it.

Common situations: Hand-casting an int to ChartType; upgrading/downgrading excelize so a chart constant moved or was removed; copying Chart structs between library versions; reading third-party XLSX files with exotic chart kinds.

Related errors


AI-assisted analysis of qax-os/excelize@f2483381fb (2026-09-02). Data as JSON: /api/errors/931a67443c8585b9. Report an issue: GitHub.