为什么使用对数给出8e + 2值?

问题描述 投票:0回答:1

我正在使用chart,并且正在使用type: 'logarithmic',这样传递max value

max: scalesMax.toFixed(2),

但是那给了我8e+2

我该如何解决?

我正在使用chart.js

这是我如何获取每个图表的值,我在另一个图表旁边有一个图表,用于比较2个数据集的每个值

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

function setConfigurationGraph(dataGraphType, labels, data, scalesMax) {
    configAllDateGraph.push({
        dataGraphType: dataGraphType,
        type: 'line',
        data: {
            labels: labels,
            datasets: [{
                fill: true,
                backgroundColor: "rgba(250, 250, 250, 1)",
                data: data,
                borderColor: "#fafafa",
                borderDash: [5, 5],
                backgroundColor: "#fafafa",
                pointBackgroundColor: "#fafafa",
                pointBorderColor: "#fafafa",
                pointHoverBackgroundColor: "#fafafa",
                pointHoverBorderColor: "#fafafa"
            }]
        },
        options: {
            responsive: true,
            title: {
                display: true
            },
            tooltips: {
                mode: 'index',
                intersect: false,
            },
            hover: {
                mode: 'nearest',
                intersect: true
            },
            scales: {
                xAxes: [{
                    display: true,
                    gridLines: {
                        color: "#fafafa"
                    },
                    ticks: {
                        fontColor: "#fafafa"
                    }
                }],

                yAxes: [{
                    display: true,
                    type: 'logarithmic',
                    gridLines: {
                        color: "#fafafa"
                    },
                    ticks: {
                        fontColor: "#fafafa",
                        beginAtZero: true,
                        max: scalesMax.toFixed(2),
                        min: 0
                    }
                }]
            },
            legend: {
                display: false
            }
        }
    });
}
javascript chart.js
1个回答
1
投票

我相信这会自动在JS中发生。您可以使用toFixed()上限为20;您是否尝试过此]

max: scalesMax.toFixed(20)

© www.soinside.com 2019 - 2024. All rights reserved.