X scale function in D3.js keeps returning undefined

后端 未结 1 1519
情深已故
情深已故 2020-12-21 01:51

I am new to D3.js and trying to make a bar chart with GDP on Y axis and date on X axis.

I am trying to make a xScale with d3.timeScale() but for some reason the code

相关标签:
1条回答
  • 2020-12-21 02:14

    In D3, both domain and range have to be an array:

    If domain is specified, sets the scale’s domain to the specified array of numbers.

    And also:

    If range is specified, sets the scale’s range to the specified array of values.

    Thus, instead of:

    var xScale = d3.scaleTime()
        .domain([minDate, maxDate])
        .range(0,w);
    

    It should be:

    var xScale = d3.scaleTime()
        .domain([minDate, maxDate])
        .range([0,w]);//an array here
    
    0 讨论(0)
提交回复
热议问题