gpt4 book ai didi

javascript - Chart.js maxBarThickness 选项不起作用

转载 作者:行者123 更新时间:2023-12-01 01:50:59 25 4
gpt4 key购买 nike

我一直在尝试为条形图设置一个阈值,因为当我只有一个条形图时,它会变得非常大,这是不可取的。

这里是我尝试设置条形大小限制的地方,但没有结果。

function carregarBarraDatasMensais() {
$.get("/monitoria/capitalizacao/aderente/faturas/pendentes/pormes/dashboardservico", function (model){

$("#cnvBarDataMes").html("");
$("#cnvBarDataMes").html("<canvas id='cnvDataMes'></canvas>");

var ctx = $("#cnvDataMes");

var datas = Object.keys(model);

var dataErro = [];
var dataProcessada = [];
var dataProcessadaAtrasada = [];
var dataNaoProcessada = [];
var dataNaoProcessadaAtrasada = [];

for (var i = 0; i < datas.length; i++){
var erro = model[datas[i]]["ERRO_PROCESSAMENTO"];
dataErro[i] = erro == undefined ? 0 : erro.length;
}

for (var i = 0; i < datas.length; i++){
var processado = model[datas[i]]["PROCESSADA"];
dataProcessada[i] = processado == undefined ? 0 : processado.length;
}

for (var i = 0; i < datas.length; i++){
var processadoAtrasado = model[datas[i]]["PROCESSADA_ATRASADA"];
dataProcessadaAtrasada[i] = processadoAtrasado == undefined ? 0 : processadoAtrasado.length;
}

for (var i = 0; i < datas.length; i++){
var naoProcessado = model[datas[i]]["NAO_PROCESSADA"];
dataNaoProcessada[i] = naoProcessado == undefined ? 0 : naoProcessado.length;
}

for (var i = 0; i < datas.length; i++){
var naoProcessadoAtrasado = model[datas[i]]["NAO_PROCESSADA_ATRASADA"];
dataNaoProcessadaAtrasada[i] = naoProcessadoAtrasado == undefined ? 0 : naoProcessadoAtrasado.length;
}

var myBarChart = new Chart(ctx, {
type: 'bar',
data: {
labels: datas,
datasets: [{
label: "Erro no processamento",
backgroundColor: colors["ERRO_PROCESSAMENTO"].hexa,
data: dataErro
}, {
label: "Arquivo processado atrasado",
backgroundColor: colors["PROCESSADA_ATRASADA"].hexa,
data: dataProcessadaAtrasada
}, {
label: "Arquivo processado sem atraso",
backgroundColor: colors["PROCESSADA"].hexa,
data: dataProcessada
}, {
label: "Arquivo não processado, atrasado",
backgroundColor: colors["NAO_PROCESSADA_ATRASADA"].hexa,
data: dataNaoProcessadaAtrasada
}, {
label: "Arquivo não processado, sem atraso",
backgroundColor: colors["NAO_PROCESSADA"].hexa,
data: dataNaoProcessada
}]

},
options: {
tooltips: {
mode: 'index'
},
scales: {
xAxes: [{
maxBarThickness: 100,
ticks: {
beginAtZero: true,
}
}],
yAxes: [{
stacked: true,
ticks: {
}
}]
},
maintainAspectRatio: false
}

})
});

}

编写 barThickness: 100 可以,但这会将每个条形设置为该大小,无论条形数量有多少(当条形很多时会导致问题)

编辑:我想我找到了问题的第一部分,此选项似乎不适用于 stacked: true,但删除它(stacked: true >) 在这种情况下,对我来说不是一个选择

最佳答案

答案很简单,我没有使用最新版本的 Chart.js。当我将 html 上的导入行更改为 <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.2/Chart.min.js"></script> 后它工作得很好。

关于javascript - Chart.js maxBarThickness 选项不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51527003/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com