Skip to content

trying to set upper limit custom afterbuildticks #10071

Answered by LeeLenaleee
pgp80 asked this question in Q&A
Discussion options

You must be logged in to vote

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
  }));

},

fiddle: https://jsfiddle.net/Leelenaleee/1odvhk7x/6/

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by pgp80
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants