Skip to content

OH: pie.js #3

@sandywij

Description

@sandywij

https://github.com/magabrielaa/CAPP30239_FA22/blob/1d54d3d04a874d421161649c28e07a89a9170afb/week_06/pie.js#L25-L26

Hey Gabriela,
This section might be the reason why your pie chart is not showing.

When you call d3.pie(), you a new pie generator but it is not doing anything with your data.

Example:

const data = [
  {"number":  4, "name": "Locke"},
  {"number":  8, "name": "Reyes"},
  {"number": 15, "name": "Ford"},
  {"number": 16, "name": "Jarrah"},
  {"number": 23, "name": "Shephard"},
  {"number": 42, "name": "Kwon"}
];

const arcs = d3.pie()
    .value(d => d.number)
    (data);

Adding a value accessor

When you add d => d.number, it modifies the generator to look for and use the number value to calculate the angles within the pie chart.

const pieGenerator = d3.pie()
    .value(d => d.number)

Getting calculated angles

const pieChartAngles = pieGenerator(data)

or

const pieChartAngles = d3.pie()
    .value(d => d.number)(data)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions