{"id":27769,"date":"2024-11-24T15:25:51","date_gmt":"2024-11-24T07:25:51","guid":{"rendered":"https:\/\/fwq.ai\/blog\/27769\/"},"modified":"2024-11-24T15:25:51","modified_gmt":"2024-11-24T07:25:51","slug":"d3-js-%e4%b8%ad-path-%e5%85%83%e7%b4%a0%e6%97%a0%e6%b3%95%e6%ad%a3%e7%a1%ae%e6%98%be%e7%a4%ba%ef%bc%8c%e8%af%a5%e6%80%8e%e4%b9%88%e5%8a%9e%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/27769\/","title":{"rendered":"d3.js \u4e2d Path \u5143\u7d20\u65e0\u6cd5\u6b63\u786e\u663e\u793a\uff0c\u8be5\u600e\u4e48\u529e\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173131438317082.jpg\" class=\"aligncenter\" title=\"d3.js \u4e2d Path \u5143\u7d20\u65e0\u6cd5\u6b63\u786e\u663e\u793a\uff0c\u8be5\u600e\u4e48\u529e\uff1f\u63d2\u56fe\" alt=\"d3.js \u4e2d Path \u5143\u7d20\u65e0\u6cd5\u6b63\u786e\u663e\u793a\uff0c\u8be5\u600e\u4e48\u529e\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>d3.js \u6dfb\u52a0 path \u5143\u7d20\u65e0\u6cd5\u6b63\u786e\u663e\u793a\u7684\u89e3\u51b3\u65b9\u6cd5<\/strong><\/p>\n<p>\u5f53\u4f60\u4f7f\u7528 d3.js \u5411 SVG \u5bb9\u5668\u6dfb\u52a0 path \u5143\u7d20\u65f6\uff0c\u9047\u5230\u65e0\u6cd5\u6b63\u786e\u663e\u793a\u7684\u95ee\u9898\uff0c\u53ef\u80fd\u662f\u4ee5\u4e0b\u539f\u56e0\u9020\u6210\u7684\uff1a<\/p>\n<p><strong>SVG viewBox \u8bbe\u7f6e<\/strong><\/p>\n<p>\u68c0\u67e5 SVG \u5143\u7d20\u7684 viewBox \u5c5e\u6027\u3002100% \u7684 viewBox \u503c\u53ef\u80fd\u4e0d\u4f1a\u751f\u6548\uff0c\u5bfc\u81f4 path \u5143\u7d20\u4e0d\u80fd\u6b63\u786e\u7f29\u653e\u3002\u5c1d\u8bd5\u5c06 viewBox \u66f4\u6539\u4e3a\u5177\u4f53\u7684\u5bbd\u5ea6\u548c\u9ad8\u5ea6\u503c\uff0c\u4f8b\u5982\uff1a<\/p>\n<pre>svg.attr(\"viewBox\", \"0 0 250 300\");<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u786e\u4fdd viewBox \u7684\u503c\u4e0e SVG \u5bb9\u5668\u7684\u5b9e\u9645\u5c3a\u5bf8\u5339\u914d\u3002<\/p>\n<p>\u6b64\u5916\uff0c\u8fd8\u6709\u5176\u4ed6\u53ef\u80fd\u7684\u56e0\u7d20\uff1a<\/p>\n<p><strong>\u5750\u6807\u7cfb\u548c\u5355\u4f4d<\/strong><\/p>\n<p>\u786e\u4fdd path \u7684 d \u5c5e\u6027\u503c\u4f7f\u7528\u6b63\u786e\u7684\u5750\u6807\u7cfb\u548c\u5355\u4f4d\u3002\u4f8b\u5982\uff0cM 50 245 \u8868\u793a\u4ece (50, 245) \u70b9\u5f00\u59cb\u7684\u8def\u5f84\u3002<\/p>\n<p><strong>\u8def\u5f84\u8bed\u6cd5<\/strong><\/p>\n<p>\u68c0\u67e5 path \u7684 d \u5c5e\u6027\u8bed\u6cd5\u662f\u5426\u6b63\u786e\u3002\u8bed\u6cd5\u5e94\u8be5\u9075\u5faa W3C SVG \u8def\u5f84\u89c4\u8303\u3002<\/p>\n<p><strong>DOM \u6811<\/strong><\/p>\n<p>\u9a8c\u8bc1 path \u5143\u7d20\u662f\u5426\u5df2\u6b63\u786e\u6dfb\u52a0\u5230 SVG \u5bb9\u5668\u4e2d\u3002\u53ef\u4ee5\u4f7f\u7528 JavaScript \u7684 parentNode \u6216 appendChild \u65b9\u6cd5\u68c0\u67e5\u662f\u5426\u5b58\u5728\u7236 SVG \u5143\u7d20\u3002<\/p>\n<p><strong>\u6837\u5f0f<\/strong><\/p>\n<p>\u786e\u4fdd path \u5143\u7d20\u5177\u6709\u9002\u5f53\u7684\u6837\u5f0f\uff0c\u5305\u62ec stroke \u3001 fill \u548c stroke-width \u3002\u8fd9\u5c06\u4f7f path \u5143\u7d20\u53ef\u89c1\u3002<\/p>\n<p>\u6309\u7167\u8fd9\u4e9b\u6b65\u9aa4\uff0c\u901a\u5e38\u53ef\u4ee5\u89e3\u51b3 d3.js \u4e2d path \u5143\u7d20\u65e0\u6cd5\u6b63\u786e\u663e\u793a\u7684\u95ee\u9898\u3002\u5982\u679c\u95ee\u9898\u4ecd\u7136\u5b58\u5728\uff0c\u5efa\u8bae\u63d0\u4f9b\u66f4\u5177\u4f53\u7684\u9519\u8bef\u4fe1\u606f\u6216\u4ee3\u7801\u793a\u4f8b\u4ee5\u8fdb\u884c\u8fdb\u4e00\u6b65\u6545\u969c\u6392\u9664\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fd3.js \u4e2d Path \u5143\u7d20\u65e0\u6cd5\u6b63\u786e\u663e\u793a\uff0c\u8be5\u600e\u4e48\u529e\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>d3.js \u6dfb\u52a0 path \u5143\u7d20\u65e0\u6cd5\u6b63\u786e\u663e\u793a\u7684\u89e3\u51b3\u65b9\u6cd5 \u5f53\u4f60\u4f7f\u7528 d3.js \u5411 SVG \u5bb9\u5668\u6dfb\u52a0 path \u5143\u7d20\u65f6\uff0c\u9047\u5230\u65e0\u6cd5\u6b63\u786e\u663e\u793a\u7684\u95ee\u9898\uff0c\u53ef\u80fd\u662f\u4ee5\u4e0b\u539f\u56e0\u9020\u6210\u7684\uff1a SVG viewBox \u8bbe\u7f6e \u68c0\u67e5 SVG \u5143\u7d20\u7684 viewBox \u5c5e\u6027\u3002100% \u7684 viewBox \u503c\u53ef\u80fd\u4e0d\u4f1a\u751f\u6548\uff0c\u5bfc\u81f4 path \u5143\u7d20\u4e0d\u80fd\u6b63\u786e\u7f29\u653e\u3002\u5c1d\u8bd5\u5c06 viewBox \u66f4\u6539\u4e3a\u5177\u4f53\u7684\u5bbd\u5ea6\u548c\u9ad8\u5ea6\u503c\uff0c\u4f8b\u5982\uff1a svg.attr(&#8220;viewBox&#8221;, &#8220;0 0 250 300&#8221;); \u767b\u5f55\u540e\u590d\u5236 \u786e\u4fdd viewBox \u7684\u503c\u4e0e SVG \u5bb9\u5668\u7684\u5b9e\u9645\u5c3a\u5bf8\u5339\u914d\u3002 \u6b64\u5916\uff0c\u8fd8\u6709\u5176\u4ed6\u53ef\u80fd\u7684\u56e0\u7d20\uff1a \u5750\u6807\u7cfb\u548c\u5355\u4f4d \u786e\u4fdd path \u7684 d \u5c5e\u6027\u503c\u4f7f\u7528\u6b63\u786e\u7684\u5750\u6807\u7cfb\u548c\u5355\u4f4d\u3002\u4f8b\u5982\uff0cM 50 245 \u8868\u793a\u4ece (50, 245) \u70b9\u5f00\u59cb\u7684\u8def\u5f84\u3002 \u8def\u5f84\u8bed\u6cd5 \u68c0\u67e5 path \u7684 d [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-27769","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/27769","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=27769"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/27769\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=27769"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=27769"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=27769"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}