1

The charts works fine, but the total varies and it gets filled quickly, see

enter image description here

I need to be able to add + % to the max

I tried:

var scalesMaxTotalCasesTrend =(Math.max(...customConfirmed) * 1.1 ).toFixed(0);
var scalesMaxTotalPositiveTrend = (Math.max(...totPositivi) * 1.1 ).toFixed(0);
var scalesMaxIsolationTrend = (Math.max(...totIsolamento) * 1.1 ).toFixed(0);  
var scalesMaxHospitalizationTrend = (Math.max(...totRicoverati) * 1.1 ).toFixed(0);
var scalesMaxHospitalizationWithSymptomsTrend = (Math.max(...totRicoveratiConSintomi) * 1.1 ).toFixed(0);
var scalesMaxIntensiveCareTrend = (Math.max(...totTerapiaIntensiva) * 1.1 ).toFixed(0);

But I get

Uncaught TypeError: t.toFixed is not a function

How can I add a % when i do:

ticks: {
    beginAtZero: true,
    suggestedMin: 0,
    max: scalesMax + 50000
}

This is the log I get:

var scalesMaxTotalCasesTrend = Math.max(...customConfirmed);
console.log(scalesMaxTotalCasesTrend);
35788

Tried adding:

max: scalesMax * 1.1

But still not a solution, the chart needs to have more space on the Y axis

rob.m
  • 9,843
  • 19
  • 73
  • 162
  • 1
    @terrymorse I could say parseint( but i don't think that's the issue, question asks something else – rob.m Apr 20 '20 at 18:28
  • 1
    I'm fairly certain your error is caused by setting a number to a string. The TypeError you're seeing is thrown in the function that formats linear numeric ticks. The offending parameter is `tickValue`, the first parameter, which is clearly not a number (and almost definitely a string). The error line: `tickString = tickValue.toFixed(numDecimal);` – terrymorse Apr 20 '20 at 18:42
  • 1
    @terrymorse it's not an error I am getting, it is the max value which is reached and so it gets filled in the chart. I need to add a % to the max – rob.m Apr 20 '20 at 18:54
  • @terrymorse that error is not related to partIn(, guess what I tried parseInt( and it doesn't work. I am asking how to add a % and when I try I get that error. – rob.m Apr 20 '20 at 19:27

1 Answers1

0

Does this work:

const MAX_MULTIPLIER = 1.1;
scalesMax = Math.round(scalesMax * MAX_MULTIPLIER);

  ...

ticks: {
    beginAtZero: true,
    suggestedMin: 0,
    max: scalesMax + 50000
}

terrymorse
  • 6,771
  • 1
  • 21
  • 27
  • that's incomplete tho, where is the actual value like confirmed? – rob.m Apr 20 '20 at 19:39
  • the issue is that the Y axes, gets to the top if you see the image, while there should be some space to see the wave, but because we are setting 2 charts to the same max count, one might reach the top. SO I wanted to add some %, adding + 50000 ad I do and you do too, won't work, because what if they are more than 50k? – rob.m Apr 20 '20 at 20:55
  • tried adding max: scalesMax * 1.10 but still not a solution – rob.m Apr 20 '20 at 20:58
  • so max: scalesMax, min: 0 without suggestedMin: 0 ? – rob.m Apr 20 '20 at 21:12
  • yea just tried but I get the same, removed * 1.1 ).toFixed(0); and just gave max: scalesMax, min: 0 but yet, the chart gets to the top of Y – rob.m Apr 20 '20 at 21:13
  • yea tried but what if we have 200000? data is dynamic so we can't just set it, looking at https://www.chartjs.org/docs/latest/axes/cartesian/linear.html#axis-range-settings but I don't get it – rob.m Apr 20 '20 at 21:19
  • also looking at this but it's not clear (to me at least) https://stackoverflow.com/questions/44887677/chart-js-setting-max-y-axis-value-and-keeping-steps-correct – rob.m Apr 20 '20 at 21:19
  • they do work of course but who knows what is the max? Maybe 100 or a million, is dynamic – rob.m Apr 20 '20 at 21:24
  • If the literals work, then `max: some_expression` must work. – terrymorse Apr 20 '20 at 21:26
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/212112/discussion-between-rob-m-and-terrymorse). – rob.m Apr 20 '20 at 21:26