What is the difference D3 datum vs. data?

前端 未结 4 1131
广开言路
广开言路 2020-12-04 05:21

Can someone please explain the difference between datum() and data() in D3.js? I see both being used and I am not sure why you should choose one over the other?

4条回答
  •  猫巷女王i
    2020-12-04 05:43

    Here are some good links:

    • Good discussion on D3 "data()": Understanding how D3.js binds data to nodes

    • D3 for Mere Mortals

    • Mike Bostock's D3 Wiki

    Per the latter:

    # selection.data([values[, key]])

    Joins the specified array of data with the current selection. The specified values is an array of data values, such as an array of numbers or objects, or a function that returns an array of values.

    ...

    # selection.datum([value])

    Gets or sets the bound data for each selected element. Unlike the selection.data method, this method does not compute a join (and thus does not compute enter and exit selections).

提交回复
热议问题