{"id":53640,"date":"2024-12-03T13:46:52","date_gmt":"2024-12-03T05:46:52","guid":{"rendered":"https:\/\/fwq.ai\/blog\/53640\/"},"modified":"2024-12-03T13:46:52","modified_gmt":"2024-12-03T05:46:52","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-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/53640\/","title":{"rendered":"d3.js \u4e2d Path \u5143\u7d20\u65e0\u6cd5\u6b63\u786e\u663e\u793a\uff0c\u8be5\u600e\u4e48\u529e\uff1f"},"content":{"rendered":"<p><b><\/b>     <\/p>\n<h1>d3.js \u4e2d Path \u5143\u7d20\u65e0\u6cd5\u6b63\u786e\u663e\u793a\uff0c\u8be5\u600e\u4e48\u529e\uff1f <\/h1>\n<p>\u7f16\u7a0b\u5e76\u4e0d\u662f\u4e00\u4e2a\u673a\u68b0\u6027\u7684\u5de5\u4f5c\uff0c\u800c\u662f\u9700\u8981\u6709\u601d\u8003\uff0c\u6709\u521b\u65b0\u7684\u5de5\u4f5c\uff0c\u8bed\u6cd5\u662f\u56fa\u5b9a\u7684\uff0c\u4f46\u89e3\u51b3\u95ee\u9898\u7684\u601d\u8def\u5219\u662f\u4f9d\u9760\u4eba\u7684\u601d\u7ef4\uff0c\u8fd9\u5c31\u9700\u8981\u6211\u4eec\u575a\u6301\u5b66\u4e60\u548c\u66f4\u65b0\u81ea\u5df1\u7684\u77e5\u8bc6\u3002\u4eca\u5929\u7c73\u4e91\u5c31\u6574\u7406\u5206\u4eab\u300ad3.js \u4e2d Path \u5143\u7d20\u65e0\u6cd5\u6b63\u786e\u663e\u793a\uff0c\u8be5\u600e\u4e48\u529e\uff1f \u300b\uff0c\u6587\u7ae0\u8bb2\u89e3\u7684\u77e5\u8bc6\u70b9\u4e3b\u8981\u5305\u62ec\uff0c\u5982\u679c\u4f60\u5bf9\u6587\u7ae0\u65b9\u9762\u7684\u77e5\u8bc6\u70b9\u611f\u5174\u8da3\uff0c\u5c31\u4e0d\u8981\u9519\u8fc7\u7c73\u4e91\uff0c\u5728\u8fd9\u53ef\u4ee5\u5bf9\u5927\u5bb6\u7684\u77e5\u8bc6\u79ef\u7d2f\u6709\u6240\u5e2e\u52a9\uff0c\u52a9\u529b\u5f00\u53d1\u80fd\u529b\u7684\u63d0\u5347\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241203\/1733187289674e56d9ee7fb.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>\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>\u672c\u7bc7\u5173\u4e8e\u300ad3.js \u4e2d Path \u5143\u7d20\u65e0\u6cd5\u6b63\u786e\u663e\u793a\uff0c\u8be5\u600e\u4e48\u529e\uff1f \u300b\u7684\u4ecb\u7ecd\u5c31\u5230\u6b64\u7ed3\u675f\u5566\uff0c\u4f46\u662f\u5b66\u65e0\u6b62\u5883\uff0c\u60f3\u8981\u4e86\u89e3\u5b66\u4e60\u66f4\u591a\u5173\u4e8e\u6587\u7ae0\u7684\u76f8\u5173\u77e5\u8bc6\uff0c\u8bf7\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\uff01<\/p>\n<dl>\n<dt><\/dt>\n<dd>\n   \u5728 JavaScript \u5bf9\u8c61\u4e2d\u5206\u914d\u548c\u68c0\u7d22\u503c\u7684\u65b9\u6cd5\n <\/dd>\n<\/dl>\n","protected":false},"excerpt":{"rendered":"<p>d3.js \u4e2d Path \u5143\u7d20\u65e0\u6cd5\u6b63\u786e\u663e\u793a\uff0c\u8be5\u600e\u4e48\u529e\uff1f \u7f16\u7a0b\u5e76\u4e0d\u662f\u4e00\u4e2a\u673a\u68b0\u6027\u7684\u5de5\u4f5c\uff0c\u800c\u662f\u9700\u8981\u6709\u601d\u8003\uff0c\u6709\u521b\u65b0\u7684\u5de5\u4f5c\uff0c\u8bed\u6cd5\u662f\u56fa\u5b9a\u7684\uff0c\u4f46\u89e3\u51b3\u95ee\u9898\u7684\u601d\u8def\u5219\u662f\u4f9d\u9760\u4eba\u7684\u601d\u7ef4\uff0c\u8fd9\u5c31\u9700\u8981\u6211\u4eec\u575a\u6301\u5b66\u4e60\u548c\u66f4\u65b0\u81ea\u5df1\u7684\u77e5\u8bc6\u3002\u4eca\u5929\u7c73\u4e91\u5c31\u6574\u7406\u5206\u4eab\u300ad3.js \u4e2d Path \u5143\u7d20\u65e0\u6cd5\u6b63\u786e\u663e\u793a\uff0c\u8be5\u600e\u4e48\u529e\uff1f \u300b\uff0c\u6587\u7ae0\u8bb2\u89e3\u7684\u77e5\u8bc6\u70b9\u4e3b\u8981\u5305\u62ec\uff0c\u5982\u679c\u4f60\u5bf9\u6587\u7ae0\u65b9\u9762\u7684\u77e5\u8bc6\u70b9\u611f\u5174\u8da3\uff0c\u5c31\u4e0d\u8981\u9519\u8fc7\u7c73\u4e91\uff0c\u5728\u8fd9\u53ef\u4ee5\u5bf9\u5927\u5bb6\u7684\u77e5\u8bc6\u79ef\u7d2f\u6709\u6240\u5e2e\u52a9\uff0c\u52a9\u529b\u5f00\u53d1\u80fd\u529b\u7684\u63d0\u5347\u3002 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;); \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 [&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-53640","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/53640","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=53640"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/53640\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=53640"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=53640"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=53640"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}