D3中的排序条形图不起作用
Sorting bar chart in D3 not working
我在D3中创建了一个条形图,选择单选按钮后会显示条形图,我想按升序或降序排序。当点击按钮时,它不是排序,所以我不知道出了什么问题,但如果有任何帮助,我们将不胜感激:
http://jsfiddle.net/m4s5m5je/2/【添加排序前】
在我按下排序按钮后,条形图不会显示,排序按钮也不会显示:
http://jsfiddle.net/m4s5m5je/3/
var sort_btn = document.getElementById('sort')
sort_btn.on("click", function(){
var self = d3.select(this);
var ascending = function(a,b){
return a.value - b.value;
};
var descending = function(a,b){
return b.value - a.value;
}
var state = +self.attr("state");
var txt = "Sort data: ";
if(state === 0){
data.sort(ascending);
state = 1;
txt += "descending";
} else if(state === 1){
data.sort(descending);
state = 0;
txt += "ascending";
}
self.attr("state", state);
self.html(txt);
您错过了结束括号})
并将sort_btn实现移出plot.call
为了使排序工作正常,您应该修复更多的位置。
更新的fiddle
plot.call(chart, {
data: data,
axis:{
x: xAxis,
y: yAxis
},
gridlines: yGridlines
});
var sort_btn = document.getElementById('sort')
sort_btn.on("click", function(){
var self = d3.select(this);
var ascending = function(a,b){
return a.value - b.value;
};
var descending = function(a,b){
return b.value - a.value;
}
var state = +self.attr("state");
var txt = "Sort data: ";
if(state === 0){
data.sort(ascending);
state = 1;
txt += "descending";
} else if(state === 1){
data.sort(descending);
state = 0;
txt += "ascending";
}
self.attr("state", state);
self.html(txt);
});
相关文章:
- d3.js组条形图不起作用
- 为什么d3.js饼图转换不起作用
- jQuery Animate 在创建图库滑块时不起作用
- 图层删除(图像);在 Kinetic.js 中不起作用
- D3中的排序条形图不起作用
- 谷歌运动图不起作用
- 堆积条形图到分组条形图过渡不起作用
- 通过 json 更新的 Canvasjs 柱形图不起作用
- 三.js立方体摄像机环境图不起作用
- D3JS - 我的折线图不起作用,并抛出错误
- 角度图不起作用
- 莫里斯折线图不起作用
- 热图不起作用
- D3 条形图示例在本地不起作用
- 为什么我的第一个截图有效,而我的第二个截图不起作用
- D3js响应堆叠条形图-其他主题解决方案不起作用
- 堆叠条形图's悬停不起作用
- 通过JS更新jqplot饼图不起作用
- D3 堆积条形图在支流中有效,但在其他地方不起作用
- 锁定在 setSelection() 上的代码图不起作用