我正在尝试使用一组非常基本的数据绘制人力车条形图,由于某种原因,当我创建自己的系列数组(颜色:字符串,数据:[{}] 和名称:字符串)时,我收到此错误:
错误:属性 width="NaN" 的值无效
如果我查看为图表的每个条形创建的元素,它们确实具有 width=NaN:
var json = '@Html.Raw(Json.Encode(Model))';
var array = $.parseJSON(json);
var dataArray = [];
var palette = new Rickshaw.Color.Palette({ scheme: 'classic9' });
for (var i = 0; i < array.length; i++) {
dataArray.push(
{
color: palette.color(),
data: [{x: i, y: array[i].Value}],
name: array[i].Key
});
}
console.log(dataArray);
var graph = new Rickshaw.Graph({
element: document.querySelector("#chart"),
renderer: 'bar',
width: 420,
height: 280,
series: dataArray
});
graph.render();
<rect x="0" y="208.95816646947355" width="NaN" height="71.04183353052643" transform="matrix(1,0,0,1,0,0)" fill="#2f254a"></rect>
<rect x="0" y="168.32890323029957" width="NaN" height="40.6333259065763" transform="matrix(1,0,0,1,0,0)" fill="#491d37"></rect>
<rect x="0" y="133.60905003661946" width="NaN" height="34.71985319368011" transform="matrix(1,0,0,1,0,0)" fill="#7c2626"></rect>
谢谢。