Skip to content

Add TestForIssue481 demo - multiple histogram x-axis alignment#969

Merged
timmolter merged 1 commit into
developfrom
timmolter/issue-481-histogram-xaxis
Jun 9, 2026
Merged

Add TestForIssue481 demo - multiple histogram x-axis alignment#969
timmolter merged 1 commit into
developfrom
timmolter/issue-481-histogram-xaxis

Conversation

@timmolter

Copy link
Copy Markdown
Member

Issue #481 reported that combining two Histogram instances with non-overlapping data ranges onto the same CategoryChart produces an incorrect x-axis. This is not a bug in the library - it is a usage pattern that requires explicit configuration.

Root cause: Histogram(data, numBins) auto-detects its own min/max from its data. When two histograms have different ranges they generate disjoint bin-center lists, and CategoryChart (which uses x-axis values as categorical labels) cannot reconcile them automatically.

Fix / correct usage: supply the same shared global [min, max] to every Histogram using the explicit-range constructor:

double globalMin = -2.5;
double globalMax = 2.5;
int numBins = 5;

Histogram h1 = new Histogram(Arrays.asList(0, 1, 2),   numBins, globalMin, globalMax);
Histogram h2 = new Histogram(Arrays.asList(-2, -1, 0), numBins, globalMin, globalMax);

chart.addSeries("series A", h1.getxAxisData(), h1.getyAxisData());
chart.addSeries("series B", h2.getxAxisData(), h2.getyAxisData());

Note: to get bin centers at exact integer values, extend the range by half a bin on each side of the data extent (binSize = 1 -> extend by 0.5, giving [-2.5, 2.5] for data spanning [-2, 2]).

TestForIssue481.java opens two charts side-by-side: one reproducing the broken behavior and one showing the correct shared-range approach. Issue #481 has been closed with this explanation.

Documents the correct usage of Histogram(data, numBins, min, max) with
a shared global range when combining multiple histograms on one chart.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@timmolter timmolter merged commit d9df4b0 into develop Jun 9, 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.

1 participant