我正在使用 d3.v2.js 来渲染饼图和一个拨号(位于中间)以指向饼图的选定组件。拨号代码如下
function createDialIndicator(dialerData, subComponentId, subComponentsCount, group){
var offsetAngle = (360/subComponentsCount)/2;
var dialAngle = ((360/subComponentsCount)*(parseInt(subComponentId.charAt(subComponentId.length-1))))-offsetAngle;
var dialGroup = group.append("g")
.attr("class","dialGroup");
dialGroup.append("path")
.attr("class","dial")
.attr("d",dialerData)
.attr("fill","gold");
d3.selectAll(".dialGroup")
.transition()
.duration(1000)
.attr("transform", "rotate(" + dialAngle + ")");
}
function updateDialIndicator(subComponentId, subComponentsCount){
var offsetAngle = (360/subComponentsCount)/2;
var dialAngle = ((360/subComponentsCount)*(parseInt(subComponentId.charAt(subComponentId.length-1))))-offsetAngle;
d3.selectAll(".dialGroup")
.transition()
.duration(1000)
.attr("transform", "rotate(" + dialAngle + ")");
}
我在初始渲染和updateDialIndicator()上调用createDialIndicator()来将刻度盘更改为指向我单击的组件。 问题是: d3在旋转时在createDialIndicator()中抛出以下错误,但在updateDialIndicator()中没有。我可以知道会出现什么问题吗?
错误:属性变换的值无效=“null”
答案 0 :(得分:8)
问题在于没有设置初始transform
属性作为转换的开始。这是错误消息的含义。要修复,只需添加初始旋转:
d3.selectAll(".dialGroup")
.attr("transform", "rotate(0)")
.transition()
.duration(1000)
.attr("transform", "rotate(" + dialAngle + ")");