I have a method in React, drawChart(), which should generate a pie chart SVG. However React is throwing a TypeError of "d is undefined" and highlighting my "svg" line (see below)
const drawChart = () => {
const data = {'protein': 16, 'fat': 36, 'carbs':45} // sample data
const width = 80;
const height = 80;
const colorScale = d3.scaleOrdinal()
.domain(data)
.range(d3.schemeCategory10);
const svg = d3.select("#graph")
.append("svg")
.attr("width", width)
.attr("height", height)
.append("g")
.attr("transform", "translate(" + width / 2 + "," + height / 2 + ")");
const arcs = d3.pie()
.value(d => d.value)(data);
const path = d3.arc()
.innerRadius(0)
.outerRadius(width / 2);
svg // this is getting highlighted in the React error output
.selectAll('.arc')
.data(arcs)
.enter()
.append('path')
.classed('arc', true)
.attr('fill', d => {
if (d.properties) {
colorScale(d.data.key)
}
})
.attr('stroke', 'black')
.attr('d', path);
}