{"id":27438,"date":"2024-11-24T10:29:43","date_gmt":"2024-11-24T02:29:43","guid":{"rendered":"https:\/\/fwq.ai\/blog\/27438\/"},"modified":"2024-11-24T10:29:43","modified_gmt":"2024-11-24T02:29:43","slug":"d3-js-%e5%90%91-svg-%e5%ae%b9%e5%99%a8%e6%b7%bb%e5%8a%a0%e8%b7%af%e5%be%84%e5%90%8e%ef%bc%8c%e4%b8%ba%e4%bb%80%e4%b9%88%e8%b7%af%e5%be%84%e6%97%a0%e6%b3%95%e6%ad%a3%e7%a1%ae%e6%98%be%e7%a4%ba%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/27438\/","title":{"rendered":"d3.js \u5411 SVG \u5bb9\u5668\u6dfb\u52a0\u8def\u5f84\u540e\uff0c\u4e3a\u4ec0\u4e48\u8def\u5f84\u65e0\u6cd5\u6b63\u786e\u663e\u793a\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173124510350519.jpg\" class=\"aligncenter\" title=\"d3.js \u5411 SVG \u5bb9\u5668\u6dfb\u52a0\u8def\u5f84\u540e\uff0c\u4e3a\u4ec0\u4e48\u8def\u5f84\u65e0\u6cd5\u6b63\u786e\u663e\u793a\uff1f\u63d2\u56fe\" alt=\"d3.js \u5411 SVG \u5bb9\u5668\u6dfb\u52a0\u8def\u5f84\u540e\uff0c\u4e3a\u4ec0\u4e48\u8def\u5f84\u65e0\u6cd5\u6b63\u786e\u663e\u793a\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>d3.js \u5411 svg \u5bb9\u5668\u6dfb\u52a0\u8def\u5f84\u540e\u65e0\u6cd5\u6b63\u786e\u663e\u793a\u7684\u89e3\u51b3\u65b9\u6cd5<\/strong><\/p>\n<p>\u5728\u4f7f\u7528 d3.js \u5c06\u8def\u5f84\u5143\u7d20\u6dfb\u52a0\u5230 SVG \u5bb9\u5668\u65f6\uff0c\u5982\u679c\u8def\u5f84\u65e0\u6cd5\u6b63\u786e\u663e\u793a\uff0c\u53ef\u80fd\u662f\u4ee5\u4e0b\u539f\u56e0\u9020\u6210\u7684\uff1a<\/p>\n<p>\u53c2\u8003\u4ee3\u7801\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>\u89e3\u51b3\u65b9\u6cd5\uff1a<\/p>\n<p>\u60a8\u63d0\u5230\u7684\u60c5\u51b5\u53ef\u80fd\u662f\u7531 SVG \u7684 <strong>viewBox<\/strong> \u8bbe\u7f6e\u4e0d\u5f53\u9020\u6210\u7684\u3002\u5c1d\u8bd5\u660e\u786e\u8bbe\u7f6e SVG \u5bb9\u5668\u7684\u9ad8\u5ea6\u548c\u5bbd\u5ea6\uff0c\u800c\u4e0d\u662f\u4f7f\u7528\u767e\u5206\u6bd4\uff08\u4f8b\u5982 100%\uff09\u3002\u5177\u4f53\u5982\u4e0b\uff1a<\/p>\n<pre>svgContainer.setAttribute(\"width\", \"400\");\nsvgContainer.setAttribute(\"height\", \"300\");<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8fd9\u4e3a SVG \u8bbe\u7f6e\u4e86\u5177\u4f53\u7684\u5927\u5c0f\uff0c\u5e76\u786e\u4fdd\u8def\u5f84\u5143\u7d20\u7684\u5750\u6807\u4e0e\u5bb9\u5668\u8fb9\u754c\u5bf9\u9f50\u3002<\/p>\n<p>\u66f4\u65b0\u540e\u7684\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre>function createPath(){\n  var svgContainer = $(\"#svg_container\").get(0)\n  svgContainer.setAttribute(\"width\", \"400\");\n  svgContainer.setAttribute(\"height\", \"300\");\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>\u901a\u8fc7\u5c06 SVG \u7684 viewBox \u8bbe\u7f6e\u4e3a\u5177\u4f53\u7684\u5927\u5c0f\uff0c\u53ef\u4ee5\u786e\u4fdd\u8def\u5f84\u5143\u7d20\u4e0e SVG \u5bb9\u5668\u6b63\u786e\u5bf9\u9f50\uff0c\u4ece\u800c\u6b63\u786e\u663e\u793a\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fd3.js \u5411 SVG \u5bb9\u5668\u6dfb\u52a0\u8def\u5f84\u540e\uff0c\u8def\u5f84\u65e0\u6cd5\u6b63\u786e\u663e\u793a\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 \u5411 svg \u5bb9\u5668\u6dfb\u52a0\u8def\u5f84\u540e\u65e0\u6cd5\u6b63\u786e\u663e\u793a\u7684\u89e3\u51b3\u65b9\u6cd5 \u5728\u4f7f\u7528 d3.js \u5c06\u8def\u5f84\u5143\u7d20\u6dfb\u52a0\u5230 SVG \u5bb9\u5668\u65f6\uff0c\u5982\u679c\u8def\u5f84\u65e0\u6cd5\u6b63\u786e\u663e\u793a\uff0c\u53ef\u80fd\u662f\u4ee5\u4e0b\u539f\u56e0\u9020\u6210\u7684\uff1a \u53c2\u8003\u4ee3\u7801\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 \u89e3\u51b3\u65b9\u6cd5\uff1a \u60a8\u63d0\u5230\u7684\u60c5\u51b5\u53ef\u80fd\u662f\u7531 SVG \u7684 viewBox \u8bbe\u7f6e\u4e0d\u5f53\u9020\u6210\u7684\u3002\u5c1d\u8bd5\u660e\u786e\u8bbe\u7f6e SVG \u5bb9\u5668\u7684\u9ad8\u5ea6\u548c\u5bbd\u5ea6\uff0c\u800c\u4e0d\u662f\u4f7f\u7528\u767e\u5206\u6bd4\uff08\u4f8b\u5982 100%\uff09\u3002\u5177\u4f53\u5982\u4e0b\uff1a svgContainer.setAttribute(&#8220;width&#8221;, &#8220;400&#8221;); svgContainer.setAttribute(&#8220;height&#8221;, &#8220;300&#8221;); \u767b\u5f55\u540e\u590d\u5236 \u8fd9\u4e3a SVG \u8bbe\u7f6e\u4e86\u5177\u4f53\u7684\u5927\u5c0f\uff0c\u5e76\u786e\u4fdd\u8def\u5f84\u5143\u7d20\u7684\u5750\u6807\u4e0e\u5bb9\u5668\u8fb9\u754c\u5bf9\u9f50\u3002 \u66f4\u65b0\u540e\u7684\u4ee3\u7801\u5982\u4e0b\uff1a function createPath(){ var svgContainer = $(&#8220;#svg_container&#8221;).get(0) svgContainer.setAttribute(&#8220;width&#8221;, [&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-27438","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/27438","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=27438"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/27438\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=27438"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=27438"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=27438"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}