【发布时间】:2017-01-14 00:22:35
【问题描述】:
D3 用于在angular2 组件中生成svg。如何从 svg 事件 mousemove 更新组件中的属性 x 和 y?
export class AxisComponent implements OnInit {
x:number;
y:number;
ngOnInit() {
var svgWidth=400;
var svgHeight=400;
var margin = {top:25, right:25, bottom:50, left:50};
var width = svgWidth - margin.left - margin.right;
var height = svgHeight - margin.top - margin.bottom;
var svg = d3.select('#container').append('svg')
.attr('width', svgWidth)
.attr('height',svgHeight)
.style('border', '2px solid');
svg.on("mousemove", function(){
var xy = d3.mouse(this);
this.x = xy[0];
this.y = xy[0];
});
}
从mousemove事件访问时出错:
【问题讨论】: