我試圖以編程方式創建餅圖,希望將其轉化爲React組件以重用。基本上我需要一個可點擊的餅圖,點擊時每個餅圖都會展開成一個整體餅圖。我試圖按照this tutorial製作餅圖並在底部,我有一塊JS,我試圖測試出來。我最終得到了Uncaught Reference Error: $$ is not defined.
下面是錯誤消息的屏幕截圖。
我的理解是,這是不是jQuery的和簡直是香草JS。我不確定這是否屬實。我通過CDN導入了jQuery,但仍然收到相同的錯誤。我讀了這個SO post,我想$$
只是一種變量名稱符號。
這是我在index.html
的代碼,沒有什麼突破性的。
<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>
什麼原因導致錯誤?我誤解了嗎?我跟隨的教程是過時/錯誤的嗎?謝謝!
定義了「$$」的位置? – Rayon
請編輯您的問題,並提供您的代碼als文本 - 不是一個圖像。 – Steve