trying to set upper limit custom afterbuildticks #10071
-
I have a chart where I have custom afterbuildticks (basically converting seconds to h:m at certain increments) https://jsfiddle.net/muLr23c0/ The thing I'm trying to do is prevent the chart from going past whatever the upper end of data is, so right now I have a custom tick for 4hr and the example above ends at 3hrs I tried a couple of things with an if statement, which fixed the upper limit but added a bunch of odd ticks in between. Just curious on how to take something like the following scale.ticks = [1, 15, 60, 300, 600, 1800, 2400, 3600, 5400, 7200, 9000, 14400].map(value => ({value})); Hope this makes sense! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
You can filter your array first so it doesnt contain the big value thats not in your dataset. To find this value you can loop through your datasets like so: afterBuildTicks(scale) {
// Manually specify the ticks you want
i = scale.ticks;
const max = scale.chart.data.datasets.reduce((acc, curr) => {
const max = Math.max(...curr.data.map(e => e.x));
if (max > acc) {
acc = max;
}
return acc;
}, Number.MIN_SAFE_INTEGER);
scale.ticks = [1, 15, 60, 300, 600, 1800, 2400, 3600, 5400, 7200, 9000, 14400].filter(e => e < max).map(value => ({
value
}));
}, |
Beta Was this translation helpful? Give feedback.
You can filter your array first so it doesnt contain the big value thats not in your dataset. To find this value you can loop through your datasets like so:
fiddle: https://jsfiddle.net/Leelenaleee/1odvhk7x/6/