Javascript D3-未捕获类型错误:未能执行';getComputedStyle';在';窗口';:参数1的类型不是';元素';

Javascript D3-未捕获类型错误:未能执行';getComputedStyle';在';窗口';:参数1的类型不是';元素';,javascript,jquery,d3.js,Javascript,Jquery,D3.js,我猜错误来自第2行 var margin = {top: 5, right: 50, bottom: 25, left: 50}, width = parseInt(d3.select('#sdtochart1').style('width'), 10)-margin.left - margin.right, w = parseInt(d3.select('#sdtochart1').style('width'), 10),

我猜错误来自第2行

var margin = {top: 5, right: 50, bottom: 25, left: 50},
            width = parseInt(d3.select('#sdtochart1').style('width'), 10)-margin.left - margin.right,
            w = parseInt(d3.select('#sdtochart1').style('width'), 10),
            h = 220,
         //   height = (width/4.5) - margin.top - margin.bottom;
               height = 220 - margin.top - margin.bottom;


        var x0 = d3.scale.ordinal().rangeRoundBands([0, width], .1);
        var x1 = d3.scale.ordinal();
        var y = d3.scale.linear().range([height, 0]);
        var y1 = d3.scale.linear().domain([0, 350]).range([height, 0]);
        var color = d3.scale.ordinal().range(["#6dbceb","#f46952","#6e8cd7", "#6b486b", "#a05d56", "#d0743c", "#ff8c00"]);
        var xAxis = d3.svg.axis().scale(x0).orient("bottom");
        var yAxis = d3.svg.axis()
            .scale(y)
            .orient("left")
            .ticks(5)
            .tickSize(-width, 0, 0)
            .tickFormat(function(d) { return d + "%"; });
        // RIGHT AXIS
        var yAxisRight = d3.svg.axis().scale(y1).ticks(6).orient("right");
        var div = d3.select("body").append("div")   
        .attr("class", "tooltip")               
        .style("opacity", 0);
        var svg = d3.select("#sdtochart1").append("svg")
            .attr("id", "eqChartId")
            .attr("width", width + margin.left + margin.right)
            .attr("height", height + margin.top + margin.bottom)
            .attr('viewBox','0 0 '+w +' '+h )
            .attr('preserveAspectRatio','xMidYMid meet')
            .append("g")
            .attr("transform", "translate(" + margin.left + "," + margin.top + ")");
错误

未捕获类型错误:未能在“窗口”上执行“getComputedStyle”: 参数1不是“元素”类型d3.v3.min.js:3


这个div
d3中是否有width属性。select('sdtochart1')。style('width')
我已经为svg添加了宽度。你说我为svg添加了宽度是很奇怪的,因为
d3。select('sdtochart1')。append('svg')
这里我看到你正在创建一个svg。我确信
sdtochart1
是一个div,它的宽度应该小于course。我真傻,在我看来,我将宽度定义为#chart1,但将其命名为#sdtochart1,因此出现了这个问题。
width = parseInt(d3.select('#sdtochart1').style('width'), 10)-margin.left - margin.right