fnando / sparkline

Generate SVG sparklines with JavaScript without any external dependency.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error when data are filled with zeros

qtphan734 opened this issue · comments

In case where the data array are filled with all zeros, Expected Number error will occurred:

Error: <path> attribute d: Expected number, "M4 NaN L 4 NaN L 29…"

Base on looking at the source, the Y coord of each datapoint is determined by the max values of datapoints. If data arrays are all 0, then you will run into a divide by zero scenario resulting in the above error.

  // The maximum value. This is used to calculate the Y coord of
  // each sparkline datapoint.
  const max = Math.max(...values);

Have reproduced the error. Can someone recommend a fork that has the patch?