Skip to content

Skip drawing an axis chart that has no entries - #387

Merged
follesoe merged 1 commit into
mainfrom
fix/empty-entries
Oct 26, 2026
Merged

follesoe merged 1 commit into
mainfrom
fix/empty-entries

Conversation

@follesoe

@follesoe follesoe commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Summary

A line, bar or point chart whose Entries is an empty list (rather than null) threw on every draw. AxisBasedChart.DrawContent only checked Series != null && entries != null, then laid out the chart with entries.GroupBy(x => x.Label).Max(g => g.Count()), and Max throws InvalidOperationException ("Sequence contains no elements") on an empty sequence. The exception escapes the SKCanvasView paint callback, so it takes the app down — seen in a shipping iOS app, where a chart was bound to data that could briefly be empty.

DrawContent now also requires entries.Any(). An empty chart draws its background and nothing else, the same as a chart whose entries were never set.

Verification

Headless draw onto a 300×100 SKBitmap against the Microcharts project:

chart before after
LineChart, 0 entries InvalidOperationException draws
BarChart, 0 entries InvalidOperationException draws
PointChart, 0 entries InvalidOperationException draws
LineChart, 1 entry draws draws

Sources/Microcharts/Microcharts.csproj builds with no warnings.

🤖 Generated with Claude Code

AxisBasedChart.DrawContent only checked that Series and entries were
not null, so a chart given an empty list went on to take the Max of the
grouped entries and threw InvalidOperationException ("Sequence contains
no elements") on every draw. Line, bar and point charts all failed this
way, and the exception escapes the paint callback and crashes the app.

An empty chart now draws its background and nothing else.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@follesoe follesoe added the bug label Oct 26, 2026
@follesoe follesoe self-assigned this Oct 26, 2026
@follesoe
follesoe merged commit b02093a into main Oct 26, 2026
2 checks passed
@follesoe
follesoe deleted the fix/empty-entries branch October 26, 2026 18:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant