Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hide {year} from x-axis #705

Closed
alvinwoon opened this issue Jun 9, 2022 · 1 comment
Closed

Hide {year} from x-axis #705

alvinwoon opened this issue Jun 9, 2022 · 1 comment
Labels
question Further information is requested

Comments

@alvinwoon
Copy link

Is there a way to hide the year overflowing from x-axis in the chart?

image

@leeoniya
Copy link
Owner

leeoniya commented Jun 10, 2022

if you dont need the axis tick display to adapt to the zoom level, the easiest way to do it is to simply set axis.values to a static template string, like {MM}/{DD}, you'll also want to reduce axis.size to get rid of the extra padding reserved for year.

if you want to do something more complex and zoom-adaptive, you'll have to provide a full formatting table for axis.values without the \n{YYYY} portions. or you can supply your own function that formats the axis splits (raw tick values) however you want.

maybe helpful discussion: #474

the full table is at the bottom of https://github.com/leeoniya/uPlot/tree/master/docs#axis--grid-opts

internally, it gets assembled here:

uPlot/src/opts.js

Lines 136 to 149 in a885446

// [0]: minimum num secs in the tick incr
// [1]: default tick format
// [2-7]: rollover tick formats
// [8]: mode: 0: replace [1] -> [2-7], 1: concat [1] + [2-7]
const _timeAxisStamps = [
// tick incr default year month day hour min sec mode
[y, yyyy, _, _, _, _, _, _, 1],
[d * 28, "{MMM}", NLyyyy, _, _, _, _, _, 1],
[d, md, NLyyyy, _, _, _, _, _, 1],
[h, "{h}" + aa, NLmdyy, _, NLmd, _, _, _, 1],
[m, hmmaa, NLmdyy, _, NLmd, _, _, _, 1],
[s, ss, NLmdyy + " " + hmmaa, _, NLmd + " " + hmmaa, _, NLhmmaa, _, 1],
[ms, ss + ".{fff}", NLmdyy + " " + hmmaa, _, NLmd + " " + hmmaa, _, NLhmmaa, _, 1],
];

@leeoniya leeoniya added the question Further information is requested label Jun 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants