I'm trying to programmatically create a pie chart in hopes of turning it into a React Component to reuse. Basically I need a pie chart that is clickable and each slice expands into a whole pie when clicked. I'm trying to follow this tutorial to making pie charts and at the bottom, I have a piece of JS that I tried to test out. I ended up getting Uncaught Reference Error: $$ is not defined.
Here's a screenshot of error message.
My understanding is that this is not jQuery and is simply Vanilla JS. I'm not sure if this is true. I imported jQuery via a CDN and still got the same error. I read this SO post and I'm thinking $$
is simply a kind of variable name notation.
This is the code I have in index.html
, nothing groundbreaking.
<body>
<div class="pie">20%</div>
<div class="pie">60%</div>
<script src="https://code.jquery.com/jquery-2.2.4.js" integrity="sha256-iT6Q9iMJYuQiMWNd9lDyBUStIq/8PuOW33aOqmvFpqI=" crossorigin="anonymous"></script>
<script type="text/javascript">
$$('.pie').forEach(function(pie) {
var p = parseFloat(pie.textContent);
var NS = "http://www.w3.org/2000/svg";
var svg = document.createElementNS(NS, "svg");
var circle = document.createElementNS(NS, "circle");
var title = document.createElementNS(NS, "title");
circle.setAttribute("r", 16);
circle.setAttribute("cx", 16);
circle.setAttribute("cy", 16);
circle.setAttribute("stroke-dasharray", p + " 100");
svg.setAttribute("viewBox", "0 0 32 32");
title.textContent = pie.textContent;
pie.textContent = '';
svg.appendChild(title);
svg.appendChild(circle);
pie.appendChild(svg);
});
</script>
</body>
What's causing the error? Am I misunderstanding? Is the tutorial I'm following outdated/wrong? Thank you!