# Pie Chart with only 5 datasets/arrays (Noob)

**URL:** <https://discourse.processing.org/t/pie-chart-with-only-5-datasets-arrays-noob/13464>\
**Category:** Beginners\
**Created:** [August 19, 2019, 2:28am UTC](https://discourse.processing.org/t/pie-chart-with-only-5-datasets-arrays-noob/13464 "2019-08-19T02:28:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![harlo1](https://avatars.discourse-cdn.com/v4/letter/h/ce73a5/32.png) [@harlo1](https://discourse.processing.org/u/harlo1)\
**Post date:** [August 19, 2019, 2:28am UTC](https://discourse.processing.org/t/pie-chart-with-only-5-datasets-arrays-noob/13464/1 "2019-08-19T02:28:31Z")

</div>

I’m just getting started (noob) - I’m confused about using the pie chart to represent data - I converted data into 360 degrees but it still doesn’t seem to be working. Any advice?

Here’s the code for reference:

```auto
let angles = [72, 90, 108, 18, 72];
function setup() {
  createCanvas(720, 400);
  noStroke();
  noLoop(); // Run once and stop
}

function draw() {
  background(100);
  pieChart(300, angles);
}

function pieChart(diameter, data) {
  let lastAngle = 0;
  for (let i = 0; i < data.length; i++) {
    let gray = map(i, 0, data.length, 0, 255);
    fill(gray);
    arc(
      width / 2,
      height / 2,
      diameter,
      diameter,
      lastAngle,
      lastAngle + radians(angles[i])
    );
    lastAngle += radians(angles[i]);
  }
}

```

When I added another array of even 1 in the lets angle it started to work but I have no idea how to make it work with only 5 datasets.

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [August 19, 2019, 4:44am UTC](https://discourse.processing.org/t/pie-chart-with-only-5-datasets-arrays-noob/13464/2 "2019-08-19T04:44:42Z")

</div>

-a- your code is not posted / formatted as code, please use the  
`</> code tag`  
to repair above.

-b- you make a function and hand down the pointer to ‘angles’ with ‘data’  
so inside the function should not be used the variable ‘angles’, only ‘data’

-c- with some math to distribute the circle 2 \* PI acc. the count and values from the data  
it looks better:  
[https://editor.p5js.org/kll/sketches/E98-K2NVL](https://editor.p5js.org/kll/sketches/E98-K2NVL)

---

<div class="post-metadata">

**Author:** ![harlo1](https://avatars.discourse-cdn.com/v4/letter/h/ce73a5/32.png) [@harlo1](https://discourse.processing.org/u/harlo1)\
**Post date:** [August 19, 2019, 5:24am UTC](https://discourse.processing.org/t/pie-chart-with-only-5-datasets-arrays-noob/13464/3 "2019-08-19T05:24:17Z")

</div>

Oh wow I am dumb - looks like it was working all along. Massive thank you for the response, that was useful too.
