-
Notifications
You must be signed in to change notification settings - Fork 11.9k
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
Using stepSize
and maxTicksLimit
together doesn't work.
#2539
Comments
@gitaarik to filter the labels, you could change the callback function that generates the tick strings. For every other label just return an empty string. If you return |
Ok thanks, that is a way to solve my problem: Though I think it would be nicer if the options would work together. But it does the job for now. |
Unfortunately setting You see the yAxis goes to 19. Without the I like this behaviour better because it's easier to read when it goes in steps of 5 up to 20, instead of steps of 4 up to 19. So if the |
I would love to see minStepSize implemented, I'm working with small numbers occasionally and seeing my dataset show 0.5 when that's not even a possible value (for the y-axis) is a bit odd... Example: I can't have half a person show up to an event. I may have events in which only ~20 people show up and if I log when they arrive and when they leave I can see halfsies. If I now work with numbers of in the triple digits I don't get this, however, using Large dataset: http://i.imgur.com/5yEXd7r.png |
I think we can add a |
@etimberg I think that would simplify what I'm (and I'm sure others) are trying to achieve, which is integer-only ticks. |
@etimberg So do you think it's easy to implement? Would like to give it a try. |
@gitaarik I think it could be easy to implement. If you'd like to try, i"d say to go for it. Feel free to drop any questions here or on Slack |
I recently ran into this issue as well as #3092. The solution I found is to create a custom formatter. This gives you much finer control over which labels are rendered. In my experience, often the only way to tweak charts effectively is to have very fine control.
|
Thanks georgeu2000, using the callback enabled me to filter out fractions using `ticks: {
}` This achieved the minStepSize = 1 that I required |
If it may help, I ran into a similar problem, that is I wanted to have in my charts:
I somehow accepted the output given by using chart options as follows: ticks: {
beginAtZero: true, // minimum value will be 0.,
stepSize: 1,
maxTicksLimit: 11
} The problem is that in this way, ticks are grouped in a weird way (e.g. 0, 6, 12, 18, 24, 30, 36, 42, 48, 55) rather than 0, 5, 10, 15, or 0, 10, 20, etc. |
@micheledallatorre , if you modify the callback in my example to only show the tick when the value is divisible by 5 you can achieve what you are after |
@chris-wood-dynmark thanks a lot, I'll try that. I'll try if I can achieve this anyway, thanks for your piece of advice! UPDATE: callback: function( tick, index, ticks ){
if( tick % 5 == 0)
return tick;
return null;
} |
I'm trying to gather requirements so that we can implement this. Based on my reading of the comments, it sounds like the following features are requested
|
In my case I wanted 10 ticks but when I had values that were less than 10 I did not require fractional ticks. i.e a max value of 5 in the chart would have 5 ticks, a max value of 600 would have 10 ticks. Would the proposed solution support that? It is not a fixed number of ticks every time it's the maximum number of ticks that the maxPointValue/minStepSize allows capped at the maxTicksLimit. |
@chris-wood-dynmark I think that would be supported with the I wrote that we should support it for both |
@etimberg would your proposed solution take into account also the generation of the tick values? For example, I had (see comments above) these values Thanks! |
@micheledallatorre yes, that should be fixed. Instead of using I haven't investigated too far with that specific case yet, but with maxTicks of 11, there should be 11 values. I'm not sure why they're 6 apart either. AFAIK the auto generate algorithm should never pick 6 🤔 it only works in 1,2,5,10,... |
@etimberg exactly, I'm not sure about which setting would take priority either, but we can investigate that afterwards. Regarding the ticks value, I can give you other examples, e.g. |
@etimberg |
@hexx870206helen you can't pass a variable or function to |
Is |
Until this is implemented, I am using this code to enforce a minimum step size. options: {
scales: {
xAxes: [{
type: 'linear',
position: 'bottom',
min: 0, // My use case requires starting at zero
beginAtZero: true,
ticks: {
callback: function(value, index, values) {
// Make sure a tick is not a fractional value
if (Math.floor(value) === value) {
return value;
}
}
}
}]
}
} |
Thanks @engelby. Unfortunately, this doesn't suit my use case because the ticks become unevenly spaced out along the axis. It may be because my In case it helps anyone, this is the solution I found for my case. I'm using vue-chartjs.
Essentially, I'm checking in the y-axis callback if there are too many ticks (more than 11), or if the step size is smaller than the one specified by my Now that I review it, the |
Hi, example: suppose we need to show 10 ticks or scale labels on x-axis. Is it possible? Thanks a regards |
I want to have a chart with a minimal
stepSize
of1
, basically I don't want the steps to have decimals like 0.5 or something. I can setstepSize
to1
, but then it will show a label for each step regardless ofmaxTicksLimit
.You can see the problem here:
http://codepen.io/anon/pen/pyBPME
If you disable the
stepSize
option, the labels are fine, but if you then disable "dataset 1" and it only shows "dataset 2", it will have steps like 0.5 and 1.5 which I don't want.Am I missing configuration or is this an issue?
Many thanks!
The text was updated successfully, but these errors were encountered: