1
我在$(document).ready
調用的函數中有此代碼。問題在於,在我的網頁中,您看到了軸,但酒吧並未顯示。我不知道是什麼問題:畫布的繪圖問題
var chart = new CanvasJS.Chart("chartContainer", {
axisY: {
title: "percent",
gridThickness: 0
},
legend: {
visible: false,
},
toolTip: {
enabled: false,
},
animationEnabled: true,
data: [],
});
var data = [];
percentGraph.forEach(function(el, i) {
var objeto1 = {
type: "stackedBar100",
showInLegend: false,
name: el.code,
dataPoints: []
}
el.percents.forEach(function(el2, j) {
if (i === j) {
var objeto2 = {
y: el2.percent,
label: el2.name,
color: colores[el2.code]
}
} else {
var objeto2 = {
y: el2.percent,
label: el2.name,
color: 'white'
}
}
objeto1.dataPoints.push(objeto2);
});
data.push(objeto1);
});
chart.options.data = data;
chart.render();
與console.log(chart.options.data)
我有這樣的結果:
dataPoints: Array[4]
0: Object
color: "white"
label: "Direccion "
x: 0
y: "10"
__proto__: Object
1: Object
color: "white"
label: "Talento"
x: 1
y: "60"
__proto__: Object
2: Object
color: "white"
label: "Ingenieria"
x: 2
y: "15"
__proto__: Object
3: Object
color: "rgb(45,204,205)"
label: "Ingenieria"
x: 3
y: "15"
__proto__: Object
length: 4
__proto__: Array[0]
name: "04"
showInLegend: false
type: "stackedBar100"
這是每個chart.options.data
對象的數據晶格結構