d3.js throwing Error: Invalid value for <g> attribute transform=“null” on transition()

喜夏-厌秋 提交于 2019-12-05 02:12:41

问题


i'm using d3.v2.js to render pie chart and a dial (in center) to point to the selected component of the pie. The code for dial is as below

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 + ")");
}

I'm calling createDialIndicator() on initial render and updateDialIndicator() to change the dial to point to the component I click. The issue is: d3 is throwing following error in createDialIndicator() on rotate but not in updateDialIndicator(). May I know what would be the issue?

Error: Invalid value for attribute transform="null"


回答1:


The problem is that there's no initial transform attribute set to use as a start for the transition. This is what the error message means. To fix, simply add an initial rotation:

d3.selectAll(".dialGroup")
 .attr("transform", "rotate(0)")
 .transition()
 .duration(1000)        
 .attr("transform", "rotate(" + dialAngle + ")");


来源:https://stackoverflow.com/questions/23870388/d3-js-throwing-error-invalid-value-for-g-attribute-transform-null-on-transi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!