我有一个数据集,其中每一行都有一个id和一个name属性。id属性是唯一的键,可以复制name。我希望名称显示在Dimple.js图表的类别轴上。
如果我使用"name“作为chart.addCategoryAxis的参数,则会绘制正确的标签,但是具有重复名称的用户将被分组为单条。如果我使用"id“作为参数,那么条形条将被分隔,但标签不对。
是否有一种“二聚”的方法来实现这一目标,或者我应该这样做:
说明这一点(单击开关按钮查看我的意思):http://jsbin.com/bupamo/4/edit?js,output
发布于 2014-09-11 08:30:49
谢谢你清晰的解释。这实际上并不是酒窝固有的东西,但是您可以通过使用id进行绘图并在事实之后替换它们来实现这一点:
您还需要做一些其他的调整,比如:
// Set the title before drawing
xAxis.title = 'name';
// Draw the axis with id's
chart.draw(0, false);
// Now set the category fields to name so that the tooltips are correct
xAxis.categoryFields = ['name'];
// Select the ID labels and replace the text with names
xAxis.shapes
.selectAll("text")
.text(function (d) {
var i;
for (i = 0; i < initialData.length; i += 1) {
if (initialData[i].id === d) {
return initialData[i].name;
}
}
});http://jsbin.com/lezocu/4/edit?js,output
https://stackoverflow.com/questions/25774821
复制相似问题