Tick labels are packed too dense when there are many equally spaced samples

Open
#731 0 comments 1 reaction 0 assignees View on GitHub

Maintainers usually reply within 4 days

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
44/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
java

Research direction

Start at the X-axis tick-generation path and the mentioned willLabelsFitInTickSpaceHint function, then reproduce the issue with several hundred equally spaced samples and compare it with the dummy-sample case. Done means X-axis grid lines and labels are spaced reasonably for dense equally spaced data, while existing Y-axis behavior and custom label formatting remain intact.

Written by the indexing model from the issue text.

Description

Aesthetics

Hi,

I use XYChart for real time plotting. Data series usually has several hundred samples. My samples are always equally spaced on X-axis.

The grid lines (and thus tick labels) are packed too dense. Please take a look at the picture below:

image

By adding just one dummy sample which is not equally spaced I get more reasonable ticks locations. See the picture below:

image

I tried to use xAxisTickMarkSpacingHint property but it doesn't have any impact on X-axis ticks, but it works well for Y-axis ticks.

I also tried to use setCustomXAxisTickLabelsFormatter to add some space around values, like this:

chart.setCustomXAxisTickLabelsFormatter {
    String.format("   %.2f   ", it)
}

however trailing spaces are truncated at some point so it doesn't help at all, unless, I add some dummy charater after spaces

chart.setCustomXAxisTickLabelsFormatter {
    String.format("   %.2f   X", it)
}

image

I am not familiar with the XChart source code but I believe this problem can be solved/mitigated by increasing required ratio between tickSpacingHint and largestLabelWidth in function willLabelsFitInTickSpaceHint:

image

Not truncating trailing spaces would be also a nice workaround for this problem

Thanks in advance

Dominant language
Java
Stars
1.6k
Forks
400
Avg merge
3d 9h
Merged PRs (30d)
7

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from knowm/XChart

All issues in knowm/XChart

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.