Uncaught TypeError: xScale.rangeBand is not a function in d3.js

前端 未结 1 1159
予麋鹿
予麋鹿 2021-02-13 17:48

Trying to generate bar chart by following Vegibit\'s tutorial in my fiddle.

The d3.min.js reference works good.

However when I try to implement down

相关标签:
1条回答
  • 2021-02-13 18:27

    Here is your fiddle, updated to D3 version 4.x: https://jsfiddle.net/jnxh140f/

    Main changes:

    For using objects with styles and attrs (not style and attr), you have to reference D3-selection-multi:

    <script src="https://d3js.org/d3-selection-multi.v1.min.js"></script>
    

    For the scales:

    var yScale = d3.scaleLinear()
        .domain([0, d3.max(chartdata)])
        .range([0, height])
    
    var xScale = d3.scaleBand()
        .domain(d3.range(0, chartdata.length))
        .range([0, width])
    

    For the width:

    .attr('width', xScale.bandwidth())
    

    For the axes:

    var vAxis = d3.axisLeft(verticalGuideScale)
        .ticks(10)
    
    var hAxis = d3.axisBottom(xScale)
        .ticks(chartdata.size)
    

    For the easing:

    .ease(d3.easeElastic)
    

    Plus other small changes (check the code).

    0 讨论(0)
提交回复
热议问题