Angularjs 如何更改MouseOver-angular-nvd3上的描述栏颜色
我想创建一个图表,用于查看和日期。所以我使用angular-nvd3插件。图表显示得很好。所有描述栏元素的颜色都相同。我需要更改moseover事件中特定条的颜色。我尝试了以下方法Angularjs 如何更改MouseOver-angular-nvd3上的描述栏颜色,angularjs,d3.js,nvd3.js,angular-nvd3,Angularjs,D3.js,Nvd3.js,Angular Nvd3,我想创建一个图表,用于查看和日期。所以我使用angular-nvd3插件。图表显示得很好。所有描述栏元素的颜色都相同。我需要更改moseover事件中特定条的颜色。我尝试了以下方法 (1) d3.select(this).atrr('rect').style('fill':'red'); (2) $scope.options.chart[e.index].color = "#222"; 但他们中没有一个人在工作。有没有办法做到这一点 $scope.options = { chart: {
(1) d3.select(this).atrr('rect').style('fill':'red');
(2) $scope.options.chart[e.index].color = "#222";
但他们中没有一个人在工作。有没有办法做到这一点
$scope.options = {
chart: {
type: 'discreteBarChart',
height: 450,
x: function(d){return d.label;},
y: function(d){return d.value;},
showValues: false,
transitionDuration: 500,
xAxis: {
axisLabel: 'Month'
},
yAxis: {
axisLabel: 'Views',
axisLabelDistance: 10,
tickFormat: function (d) {
return d3.format('k')(d);
}
},
color: ['#59ade8'],
dispatch: {
tooltipShow: function(e){ },
tooltipHide: function(e){},
beforeUpdate: function(e){}
},
discretebar: {
dispatch: {
//chartClick: function(e) {console.log("! chart Click !")},
elementClick: function(e) {
selected_element = e;
setVisibility();
},
elementMouseout: function(e) {},
elementMouseover: function(e) {
d3.select(e).color = '#222'
}
}
}
}
}
$scope.data = [{
values: [{
"label" : "10" ,
"value" : 50
},{
"label" : "11" ,
"value" : 20
},{
"label" : "13" ,
"value" : 60
},{
"label" : "14" ,
"value" : 90
},{
"label" : "15" ,
"value" : 40
},{
"label" : "16" ,
"value" : 50
},{
"label" : "17" ,
"value" : 30
}]
}];
我使用$scope.apply()函数解决了这个问题。这让我很开心。我通过改变每个条的颜色
$scope.$apply(function(){
$scope.data[0].values[e.index].color = '#59ade8';
});
我使用$scope.apply()函数解决了这个问题。这让我很开心。我通过改变每个条的颜色
$scope.$apply(function(){
$scope.data[0].values[e.index].color = '#59ade8';
});
我从未使用过angular,但纯D3代码如下:
D3.选择(this).style('fill','red')
。感谢您的回复。但它给出了一个错误:“d3.min.js:1:uncaughttypeerror:cannotreadproperty'setProperty'undefined”我从未使用过angular,但纯d3代码是:d3.select(this).style('fill','red')
。感谢您的回复。但它给出了一个错误:“d3.min.js:1:UncaughtTypeError:无法读取未定义的属性'setProperty'”