D3-未捕获的TypeError:无法执行' getComputedStyle' on' Window':参数1不是'元素'

时间:2016-02-02 05:01:47

标签: javascript jquery d3.js

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

错误来自 line:2 ,我猜。

width = parseInt(d3.select('#sdtochart1').style('width'), 10)-margin.left - margin.right

错误

  

未捕获的TypeError:无法执行' getComputedStyle' on' Window':   参数1不是'元素'的类型。 - d3.v3.min.js:3

0 个答案:

没有答案