【问题标题】:Drawing problems with canvas画布的绘图问题
【发布时间】:2017-03-22 20:22:39
【问题描述】:

我在从$(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 对象的数据结构

【问题讨论】:

    标签: javascript jquery html canvas


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2013-09-17
      • 1970-01-01
      • 1970-01-01
      • 2011-02-08
      • 2013-08-20
      • 1970-01-01
      • 2011-09-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多