pie_chart = (type) => {
const width = 500
const OUTER = width / 3
const height = width - (width/3)
let INNER = 0
if(type==1)
INNER += OUTER / 3
const labelRadius = (INNER + OUTER) / 2
const SERVING_SIZE = 100
const color = d3.scaleOrdinal(d3.schemeCategory10)
let svg = d3.create("svg")
.attr("height", height)
.attr("width", width)
.attr("viewBox", [-width/2, -height/2, width, height]);
let g = svg.append("g")
const arc = d3.arc().innerRadius(INNER).outerRadius(OUTER)
let arcs = g.selectAll('arc')
.data(pie(data)).enter()
.append('g')
.attr('class', 'arc')
arcs.append('path')
.attr('fill', (d,i)=>color(i))
.attr('d', arc)
arcs.append("text")
.attr('transform', (d) => 'translate(' + arc.centroid(d) + ')')
.text((d,i) => label[i])
.attr('fill', 'white')
let angles_perc = calc_perc(pie(data))
if (d3.sum(angles_perc) == 100)
arcs.append("title")
.text((d,i) => angles_perc[i]+"%");
return svg.node();
}