-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
y-axis is short #671
Comments
Just set the maxValue property to your highest value |
@marnett-git Thanks for the reply. axisLeft = {{
maxValue: 301,
tickSize: 5,
tickPadding: 5,
tickRotation: 0
}} This, unfortunately, did not work. And even if it did, it wouldn't solve the bigger problem: I am going to use this chart with some dynamic data. I'd like nivo to figure out the axis for itself. I noticed that even on the website (https://nivo.rocks/bar) this problem exists. |
hi @pmsoltani , did you find a solution ? I get the same problem sometimes with my charts even if I set some margin |
You can set the |
@wyze yeah I already have that in place .. |
ok by actually setting minValue and maxValue it fixes my problem ! |
@RilRil so sorry for the late reply. No, I didn't find a way to solve the issue. I decided to keep an eye on the Nivo but switch to another library for my current project. |
Hi guys, Even the graphs on Google Analytics and other chat libraries do the same they give some room after the max value generated by your data. |
hi.. can you please share your code. I tried with adding |
@prashant-jump360 to calculate the maxValue, i used
|
@amihalopoulos I added the following code to give a small buffer or breathing room to the Y-axis on a yScale={{
type: "linear",
min: 0,
max: this.getMaxValue(array),
stacked: true,
reverse: false,
}} Where the |
I would love to have a prop á la import { tickStep } from 'd3-array';
const ticks = 6;
const step = tickStep(minVal, maxVal, ticks - 2);
min = minVal - step;
max = maxVal + step;
return (
<Line
yScale={{ type: 'linear', stacked: false, min, max }}
axisLeft={{
tickValues: ticks,
}}
/>
); I briefly looked into adding it to scales, but those functions don't currently receive the number of ticks, which is required for this approach to work and I am much too unfamiliar with the codebase to try and add it atm. |
@CaptainT33mo I have a similar problem with the graph data extending beyond the range of the Y axis What did you do for your getMaxValue function? I am using a workaround by passing the highest message count (rounded up to nearest 10) separately and using that as the yScale max value, which works but is not ideal |
Hi @Ollymid , This is the exact code I uses as a hack to get the max value of the Y-axis. getMaxValue = preppedData => {
const maxArray = preppedData.map(data =>
data.data.reduce((max, p) => (p.y > max ? p.y : max), data.data[0].y)
);
let padding;
if (maxArray[0] <= 10) {
padding = 10;
} else if (maxArray[0] > 10 && maxArray[0] <= 1000) {
padding = 100;
} else {
padding = 1000;
}
return (
Math.ceil(
maxArray.reduce((max, p) => (p > max ? p : max), maxArray[0]) / padding
) * padding
);
}; Maybe you can optimize the code as per your need |
Thanks @CaptainT33mo - appreciate it 🙌 |
This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. We are sorry that we haven't been able to prioritize it yet. If you have any new additional information, please include it with your comment! |
This issue is still an issue - I used CaptainT33mo's solution to as a way to circumvent the problem in my project, but it'd be nice to not have to manually round up the highest value for the graph to fit the data properly |
I also have this exact same issue, i want You can see the line thickness is smaller when it touches the "max" because it's being cut off. Why wouldn't I will go with the solutions proposed above, but it really should be incorporated into |
I adapted CaptainT33mo function to my charts, maybe it will be useful to someone:
|
+1 on this implementation, I think this would be the cleanest solution |
Similar issues occur in the Stream chart. These could be considered for future features. Thank you! 🙏 |
This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. We are sorry that we haven't been able to prioritize it yet. If you have any new additional information, please include it with your comment! |
Bump - because as far as I'm aware it is still affecting people |
Hi, how can you set min and max y scale values so that the data is "zoomed in" instead of having y axis scaled from 0 to your max y value. I tried to set a min value in the yscale but in this simple example scaling the y axis does not seem to work... <Bar |
This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. We are sorry that we haven't been able to prioritize it yet. If you have any new additional information, please include it with your comment! |
Bump I've been using a workaround where I track the max values in my data for different modes (grouped/stacked for Bar, stacked/not stacked for Line), then if the Y-Axis max is set to It's been working pretty well, but I recently upgraded past So, for now, I'll probably just update the workaround to track each individual series max value and step up or down to the next highest/lowest when toggling series, but it would be great if As always, thank you so much for this library. It has been wonderful to work with. |
Hey @nleapai, how are you tracking each series' max value upon toggle? I can't figure out how to "grab" the visible lines to generate the max/min numbers. I agree that the "auto" property should have some padding, both for max and min on the y-axis. |
Hey @wiznotwiz, in my case, I wasn't grabbing those values upon toggle or grabbing them from the chart itself. Short version: I was tracking it beforehand/managing it in wrapper components. Long version: I was dealing with time series data from an API that needed to be formatted first, so while that preprocess was iterating over the data, I just kept track of the highest values for each series then passed that info along to a component wrapping the Line chart. That component would then be responsible for determining which max to use based on which series were toggled (through its own state, not grabbing it from the internal BUT, I actually abandoned all this "series max tracking for padding" stuff because it got real hairy once I turned on Line Stacking. Without stacking, just use the largest value from the pool of active series. With stacking, now everything is cumulative and there's no accurate/consistent way to determine the max without just tracking the value of every individual slice. Then you factor in toggling and it was just way too much effort for some padding. So I've just accepted no padding for now. |
I am currently precalculating maxvalue and using |
This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. We are sorry that we haven't been able to prioritize it yet. If you have any new additional information, please include it with your comment! |
Closing this issue after a prolonged period of inactivity. If this issue is still present in the latest release, please create a new issue with up-to-date information. Thank you! |
The cleanest solution I found for the const yScale = useMemo(
() =>
!data.length
? { min: 0, max: 800 }
: {
min: 0,
max: Math.max(...data.map((x) => x.y)) * 1.2,
},
[data],
); yScale={{
type: 'linear',
...yScale,
}} |
First of all, thanks for the library. Keep up the good work!
Describe/explain the bug
The y-axis is shorter than the tallest bar
To Reproduce
Expected behavior
The biggest number is 190, but y-axis only goes up to 180. It should include 200 as well.
Screenshots
Desktop (please complete the following information):
The text was updated successfully, but these errors were encountered: