用画布绘制问题

时间:2017-03-22 09:31:34

标签: javascript jquery html5 canvas

我在一个从$(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对象

的数据结构

1 个答案:

答案 0 :(得分:0)

抱歉,我发现问题是thtat el2.percent是一个字符串,而canvasjs需要一个数字。