Rest Api data fetching error while using chartjs

👍:0

  1. If you want to inherit a new custom method to the instances of an object, you need to define them in the prototype, so instead of Date.formatMMDDYYYY = () => {...} use this Date.prototype.formatMMDDYYYY = function{...}, we can’t use arrow functions because then we won’t get the right values for this. Also you could have used instead a normal function that received a Date and call it whenever you need it, this way was more easy and safe.
  2. Small error about the order in the format string the method is returning, instead of this.getDate() + 1 + "/" + this.getMonth() +... it should be this.getMonth() + 1 + "/" + this.getDate() +...
  3. You are trying to get the data from results, but data is not there it’s in results.data, so the cycle should be results.data.forEach(packet => {...}

Fixed code here: https://codesandbox.io/s/p3q2pz2l8x

Leave a comment