Skip to content

Add Chart.setSize so a chart can be resized before export - #1036

Merged
timmolter merged 1 commit into
developfrom
issue-807-chart-set-size
Oct 7, 2026
Merged

timmolter merged 1 commit into
developfrom
issue-807-chart-set-size

Conversation

@timmolter

Copy link
Copy Markdown
Member

Summary

Adds a public, fluent setSize(int width, int height) to Chart. Until now a chart's dimensions could only be set via the builder, so a chart constructed by code outside the caller's control (the case in #807) could not be exported at a chosen size. The existing setWidth/setHeight are protected and stay that way.

chart.setSize(1920, 1080);
ChartEncoder.saveChart(chart, "./MyChart", "png");

Every exporter (BitmapEncoder, VectorGraphicsEncoder, PdfboxGraphicsEncoder) already reads getWidth()/getHeight() from the chart, so no encoder changes are needed and all formats pick up the new size. Non-positive dimensions throw IllegalArgumentException.

This is an alternative to #1034, which adds width/height overloads to ChartEncoder. A single setter on the chart covers the same use case with less API surface, makes the size change explicit rather than a side effect of exporting, and also helps anyone who wants to resize a chart before handing it to a Swing panel.

Changes

  • Chart.setSize(int, int) returning this
  • ChartSizeTest: chaining, validation, PNG dimensions, SVG viewBox, PDF page size, pie and category charts
  • TestForIssue807 demo
  • README note under Exporting Charts

Test plan

  • mvn -pl xchart test: 180 tests, 0 failures
  • xchart-demo compiles

Fixes #807

🤖 Generated with Claude Code

A chart's width and height could only be set through the builder, so a
chart constructed by code the caller does not control could not be
exported at a chosen size. setSize is a public fluent setter that updates
both dimensions, which every exporter already reads from the chart.

Fixes #807

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@timmolter
timmolter merged commit dc03647 into develop Oct 7, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

setting the size (dimensions) of the image when saving

1 participant