{"id":27447,"date":"2024-11-24T15:29:04","date_gmt":"2024-11-24T07:29:04","guid":{"rendered":"https:\/\/fwq.ai\/blog\/27447\/"},"modified":"2024-11-24T15:29:04","modified_gmt":"2024-11-24T07:29:04","slug":"%e4%bd%bf%e7%94%a8-d3-js-%e5%9c%a8-svg-%e4%b8%ad%e6%b7%bb%e5%8a%a0%e8%b7%af%e5%be%84%e4%b8%ba%e4%bd%95%e4%bc%9a%e6%98%be%e7%a4%ba%e5%bc%82%e5%b8%b8%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/27447\/","title":{"rendered":"\u4f7f\u7528 d3.js \u5728 SVG \u4e2d\u6dfb\u52a0\u8def\u5f84\u4e3a\u4f55\u4f1a\u663e\u793a\u5f02\u5e38\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173124578088421.jpg\" class=\"aligncenter\" title=\"\u4f7f\u7528 d3.js \u5728 SVG \u4e2d\u6dfb\u52a0\u8def\u5f84\u4e3a\u4f55\u4f1a\u663e\u793a\u5f02\u5e38\uff1f\u63d2\u56fe\" alt=\"\u4f7f\u7528 d3.js \u5728 SVG \u4e2d\u6dfb\u52a0\u8def\u5f84\u4e3a\u4f55\u4f1a\u663e\u793a\u5f02\u5e38\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>d3.js \u6dfb\u52a0\u8def\u5f84\u5230 svg \u5bb9\u5668\u4e2d\u663e\u793a\u5f02\u5e38\u7684\u539f\u56e0<\/strong><\/p>\n<p>\u5728\u4f7f\u7528 d3.js \u5411 SVG \u5bb9\u5668\u4e2d\u6dfb\u52a0\u8def\u5f84\u5143\u7d20\u65f6\uff0c\u5982\u679c\u51fa\u73b0\u8def\u5f84\u65e0\u6cd5\u6b63\u786e\u663e\u793a\u7684\u60c5\u51b5\uff0c\u53ef\u80fd\u6709\u4ee5\u4e0b\u539f\u56e0\uff1a<\/p>\n<p>\u4ee3\u7801\u793a\u4f8b\uff1a<\/p>\n<pre>function createPath(){\n  var svgContainer = $(\"#svg_container\").get(0)\n  var svg = d3.select(svgContainer);\n  svg.append(\"path\")\n      .attr(\"d\",'M 50 245 L 150 245')\n      .attr(\"stroke\",\"black\")\n}<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p><strong>\u95ee\u9898\u539f\u56e0\uff1aSVG \u89c6\u53e3\uff08viewBox\uff09\u8bbe\u7f6e\u4e0d\u5f53<\/strong><\/p>\n<p>SVG \u89c6\u53e3\u5c5e\u6027\u5b9a\u4e49\u4e86 SVG \u5185\u5bb9\u7684\u663e\u793a\u533a\u57df\u3002\u5982\u679c\u60a8\u5c06\u89c6\u53e3\u8bbe\u7f6e\u4e3a 100%\uff0c\u5219\u5b83\u53ef\u80fd\u65e0\u6cd5\u6b63\u786e\u663e\u793a\u8def\u5f84\u3002\u8fd9\u662f\u56e0\u4e3a 100% \u76f8\u5bf9\u4e8e SVG \u5bb9\u5668\u7684\u7236\u5143\u7d20\u5927\u5c0f\uff0c\u800c\u5bb9\u5668\u672c\u8eab\u53ef\u80fd\u6ca1\u6709\u7279\u5b9a\u7684\u9ad8\u5ea6\u6216\u5bbd\u5ea6\u3002<\/p>\n<p><strong>\u89e3\u51b3\u65b9\u6cd5\uff1a<\/strong><\/p>\n<p>\u5c06\u89c6\u53e3\u8bbe\u7f6e\u4e3a\u5177\u4f53\u7684\u9ad8\u5ea6\u548c\u5bbd\u5ea6\u3002\u4f8b\u5982\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u4ee3\u7801\u8bbe\u7f6e\u89c6\u53e3\uff1a<\/p>\n<pre>svg.attr(\"viewBox\", \"0 0 200 500\");<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u5176\u4e2d 200 \u548c 500 \u662f SVG \u5185\u5bb9\u7684\u5bbd\u5ea6\u548c\u9ad8\u5ea6\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u4f7f\u7528 d3.js \u5728 SVG \u4e2d\u6dfb\u52a0\u8def\u5f84\u4e3a\u4f55\u4f1a\u663e\u793a\u5f02\u5e38\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\u8def\u5f84\u5230 svg \u5bb9\u5668\u4e2d\u663e\u793a\u5f02\u5e38\u7684\u539f\u56e0 \u5728\u4f7f\u7528 d3.js \u5411 SVG \u5bb9\u5668\u4e2d\u6dfb\u52a0\u8def\u5f84\u5143\u7d20\u65f6\uff0c\u5982\u679c\u51fa\u73b0\u8def\u5f84\u65e0\u6cd5\u6b63\u786e\u663e\u793a\u7684\u60c5\u51b5\uff0c\u53ef\u80fd\u6709\u4ee5\u4e0b\u539f\u56e0\uff1a \u4ee3\u7801\u793a\u4f8b\uff1a function createPath(){ var svgContainer = $(&#8220;#svg_container&#8221;).get(0) var svg = d3.select(svgContainer); svg.append(&#8220;path&#8221;) .attr(&#8220;d&#8221;,&#8217;M 50 245 L 150 245&#8242;) .attr(&#8220;stroke&#8221;,&#8221;black&#8221;) } \u767b\u5f55\u540e\u590d\u5236 \u95ee\u9898\u539f\u56e0\uff1aSVG \u89c6\u53e3\uff08viewBox\uff09\u8bbe\u7f6e\u4e0d\u5f53 SVG \u89c6\u53e3\u5c5e\u6027\u5b9a\u4e49\u4e86 SVG \u5185\u5bb9\u7684\u663e\u793a\u533a\u57df\u3002\u5982\u679c\u60a8\u5c06\u89c6\u53e3\u8bbe\u7f6e\u4e3a 100%\uff0c\u5219\u5b83\u53ef\u80fd\u65e0\u6cd5\u6b63\u786e\u663e\u793a\u8def\u5f84\u3002\u8fd9\u662f\u56e0\u4e3a 100% \u76f8\u5bf9\u4e8e SVG \u5bb9\u5668\u7684\u7236\u5143\u7d20\u5927\u5c0f\uff0c\u800c\u5bb9\u5668\u672c\u8eab\u53ef\u80fd\u6ca1\u6709\u7279\u5b9a\u7684\u9ad8\u5ea6\u6216\u5bbd\u5ea6\u3002 \u89e3\u51b3\u65b9\u6cd5\uff1a \u5c06\u89c6\u53e3\u8bbe\u7f6e\u4e3a\u5177\u4f53\u7684\u9ad8\u5ea6\u548c\u5bbd\u5ea6\u3002\u4f8b\u5982\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u4ee3\u7801\u8bbe\u7f6e\u89c6\u53e3\uff1a svg.attr(&#8220;viewBox&#8221;, &#8220;0 0 200 500&#8221;); \u767b\u5f55\u540e\u590d\u5236 \u5176\u4e2d 200 \u548c 500 \u662f SVG [&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-27447","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/27447","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=27447"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/27447\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=27447"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=27447"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=27447"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}