ecomfe / echarts-stat

Statistics tool for Apache ECharts
593 stars 309 forks source link

精度报错:RangeError: toFixed() digits argument must be between 0 and 20 #21

Open Hishengs opened 5 years ago

Hishengs commented 5 years ago

version: 1.1.1

使用的代码:

const bins = ecStat.histogram(day.listValue);

        const config = {
          backgroundColor: '#fff',
          color: ['#F15A5A', '#9FCFFF', '#FFD96C'],
          tooltip: {
            trigger: 'axis'
          },
          grid: {
            containLabel: true
          },
          xAxis: {
            type: 'category',
            scale: true,
            splitLine: {
              lineStyle: {
                color: '#eee'
              }
            },
            data: bins.bins.map(item => {
              return `[${item.x0}, ${item.x1})`;
            }),
            axisLabel: {
              rotate: 20,
            },
          },
          yAxis: {
            type: 'value',
            splitLine: {
              lineStyle: {
                color: '#eee'
              }
            }
          },
          series: [
            {
              type: 'bar',
              name: '因子分布',
              label: {
                normal: {
                  show: true,
                  position: 'top',
                  /* formatter: function(params) {
                    return params.value[1];
                  } */
                },
              },
              // data: bins.data,
              data: bins.bins.map(item => {
                return item.sample.length;
              }),
              // barWidth: '99.3%',
              barCategoryGap: '0%',
            },
          ]
        };

其中 day.listValue 的值为

[
  "46.1122",
  "79.9441",
  "65.9859",
  "25.3935",
  "42.7866",
  "305.0315",
  "18.1025",
  "33.8013",
  "54.5712",
  "814.8929",
  "49.9332",
  "106.3157",
  "47.7458",
  "244.226",
  "49.0097",
  "29.0577",
  "31.1753",
  "43.3136",
  "58.5335",
  "22.4288",
  "-11.6769",
  "20.6866",
  "331.7812",
  "11.5116",
  "14.6281",
  "30.9462",
  "291.3254",
  "1952.1139",
  "42.5726",
  "51.8977",
  "13.1309",
  "101.5074",
  "67.969",
  "580.0693",
  "39.1682",
  "39.9857",
  "15.4187",
  "19.0435",
  "453.9382",
  "34.3246",
  "21.0266",
  "8.5466",
  "-337.494",
  "74.0159",
  "20.9999",
  "38.1729",
  "14.4369",
  "73.7471",
  "16.1754",
  "18.4142",
  "29.2798",
  "36.5281",
  "44.2856",
  "23.2042",
  "-1055.9283",
  "60.4042",
  "13.3311",
  "143.9589",
  "20.8098",
  "55.519",
  "-6.6047",
  "347.5278",
  "129.5079",
  "37.6373",
  "5016.1411",
  "66.5109",
  "130.0112",
  "-13.2207",
  "76.0309",
  "22.7796",
  "36.9493",
  "-60.8982",
  "43.0935",
  "34.3241",
  "18.7641",
  "-16.9989",
  "56.3742",
  "-14.2415",
  "152.7147",
  "48.0559",
  "69.9903",
  "43.1559",
  "95.5448",
  "67.8536",
  "67.5987",
  "236.68200000000003",
  "40.4911",
  "19.5773",
  "31.5195",
  "27.7471",
  "26.8844",
  "128.9933",
  "50.9519",
  "32.1314",
  "47.5839",
  "31.6497",
  "153.8752",
  "42.7797",
  "36.2301",
  "29.0493",
  "19.4439",
  "32.8508",
  "-26.0843",
  "993.6406",
  "20.2155",
  "42.4152",
  "158.721",
  "76.5177",
  "64.5483",
  "74.1889",
  "20.4185",
  "48.2014",
  "66.1414",
  "22.8513",
  "125.2946",
  "45.5809",
  "89.7309",
  "33.7619",
  "110.0395",
  "38.8518",
  "87.5813",
  "20.3838",
  "45.3373",
  "245.2003",
  "33.7077",
  "45.5985",
  "21.6263",
  "21.2772",
  "16.9991",
  "48.5743",
  "32.7595",
  "84.5881",
  "124.8476",
  "58.4178",
  "157.689",
  "92.9167",
  "70.3227",
  "57.2383",
  "37.1941",
  "67.9477",
  "59.4279",
  "25.6653",
  "37.5302",
  "65.7551",
  "27.281",
  "60.2499",
  "144.5758",
  "677.7747",
  "36.7851",
  "37.5982",
  "172.9186",
  "44.4609",
  "72.5558",
  "-234.8506",
  "46.8691",
  "65.8725",
  "183.3086",
  "52.7152",
  "59.7837",
  "143.5452",
  "68.926",
  "57.8861",
  "36.7907",
  "66.49",
  "49.1127",
  "234.544",
  "79.9554",
  "52.174",
  "-139.5203",
  "-76.9621",
  "84.6753",
  "25.0969",
  "82.3473",
  "26.2366",
  "33.6382",
  "88.6027",
  "43.4883",
  "18.6724",
  "41.1948",
  "44.0906",
  "54.5789",
  "43.4056",
  "67.9087",
  "1701.2148",
  "54.4143",
  "117.9243",
  "41.8927",
  "136.248",
  "16.9029",
  "33.3713",
  "91.4584",
  "23.2714",
  "53.7191",
  "38.2199",
  "39.5026",
  "81.5323",
  "70.4219",
  "76.0257",
  "98.609",
  "88.8738",
  "36.0991",
  "44.7578",
  "91.9082",
  "17.9169",
  "56.0444",
  "47.4194",
  "47.2381",
  "54.7681",
  "44.3932",
  "49.3933",
  "66.2575",
  "58.1567",
  "112.9541",
  "35.4673",
  "85.0974",
  "28.6041",
  "84.7982",
  "30.67",
  "26.8869",
  "59.1792",
  "59.565",
  "39.9466",
  "42.0397",
  "60.7055",
  "37.9327",
  "31.8398",
  "62.5273",
  "69.1902",
  "53.5739",
  "29.2794",
  "42.9863",
  "45.2294",
  "41.9355",
  "71.9677",
  "31.0083",
  "216.8302",
  "65.428",
  "32.6606",
  "39.0246",
  "68.0098",
  "78.6268",
  "406.37699999999998",
  "88.5604",
  "61.7179",
  "74.5056",
  "40.6728",
  "12.4336",
  "60.2621",
  "68.3484",
  "22.3193",
  "26.6332",
  "22.3673",
  "25.6934",
  "13.2255",
  "35.1222",
  "27.5046",
  "-5.6767",
  "14.3282",
  "24.2138",
  "12.9862",
  "31.1639",
  "31.9648",
  "59.3972",
  "21.1512",
  "23.1336",
  "152.0642",
  "23.8739",
  "41.8323",
  "53.3303",
  "-215.9784",
  "35.7411",
  "145.9405",
  "-347.0922",
  "353.6866",
  "269.1379",
  "47.3668",
  "20.8251",
  "-11.7946",
  "176.7098",
  "-110.5078",
  "27.0835",
  "310.2762",
  "-136.8502",
  "35.0555",
  "37.6381",
  "31.4114",
  "15.2714",
  "345.2995",
  "94.9969",
  "-46.7537",
  "108.9767",
  "16.8032",
  "328.1013",
  "15.5718",
  "469.8549",
  "41.2185",
  "-96.3313",
  "105.0974",
  "34.0746",
  "68.1926",
  "-5.9197",
  "18.6305",
  "10.4123",
  "227.8507",
  "56.4311",
  "19.793",
  "31.2876",
  "30.7491",
  "30.2273",
  "-298.2306",
  "9.1886",
  "13.8888",
  "45.7195",
  "23.159000000000004",
  "-236.7455",
  "141.4538",
  "159.1012",
  "27.3736",
  "364.4178",
  "107.2776",
  "21.6099",
  "23.5347",
  "21.9842",
  "-85.7228",
  "617.7026",
  "49.3958",
  "83.6289",
  "17.6152",
  "-119.9347",
  "39.1311",
  "79.347",
  "102.7694",
  "28.7748",
  "23.6301",
  "47.1984",
  "33.8534",
  "232.2258",
  "235.6648",
  "-61.3977",
  "30.2815",
  "22.9648",
  "45.3414",
  "63.111000000000007",
  "82.1559",
  "14.5941",
  "44.2605",
  "24.2673",
  "-467.9343",
  "46.2747",
  "26.34",
  "34.3235",
  "24.6902",
  "28.6183",
  "130.659",
  "162.8182",
  "51.8934",
  "38.3788",
  "36.7753",
  "522.1838",
  "14.5283",
  "34.5246",
  "30.8602",
  "35.4004",
  "27.8597",
  "42.8646",
  "18.2249",
  "15.1134",
  "10.6581",
  "26.6319",
  "73.5008",
  "13.9021",
  "28.9988",
  "24.6413",
  "72.3369",
  "43.1009",
  "14.6119",
  "27.0754",
  "272.0576",
  "321.4032",
  "-40.5621",
  "-57.195",
  "136.1924",
  "507.4119",
  "30.4673",
  "103.7315",
  "-17.136",
  "30.8467",
  "7.7334",
  "37.3364",
  "15.7205",
  "-20.9888",
  "83.75299999999999",
  "111.8565",
  "59.5535",
  "38.9489",
  "36.7761",
  "33.6698",
  "52.2114",
  "-124.5301",
  "61.8157",
  "32.9585",
  "53.687",
  "30.0752",
  "52.2502",
  "65.6443",
  "39.9863",
  "-1158.2663",
  "17.3679",
  "-20.4349",
  "24.6134",
  "36.6528",
  "37.7252",
  "15.4751",
  "-26.5158",
  "93.4245",
  "150.6037",
  "17.5651",
  "44.0352",
  "29.1785",
  "27.8849",
  "32.9195",
  "25.7838",
  "-54.7277",
  "23.2095",
  "38.6302",
  "110.07",
  "43.8521",
  "47.1684",
  "41.4805",
  "21.6672",
  "81.7812",
  "22.6599",
  "25.9397",
  "-247.3548",
  "91.1875",
  "84.1449",
  "65.4708",
  "0.0",
  "0.0",
  "0.0",
  "0.0",
  "0.0",
  "0.0",
  "0.0",
  "0.0",
  "0.0",
  "0.0",
  "0.0",
  "0.0",
  "0.0",
  "0.0",
  "0.0",
  "0.0",
  "0.0",
  "0.0",
  "0.0",
  "0.0",
  "0.0",
  "0.0",
  "0.0",
  "0.0"
]

执行报错:

image

image

wmhh1129 commented 5 years ago

请问有找到解决方法吗?

derricksimpson commented 5 years ago

I get the same issue. Why not Math.abs rather than trying to invert a negative precision that sometimes isn't negative? Thanks!