{"id":3403,"date":"2024-11-10T08:50:47","date_gmt":"2024-11-10T00:50:47","guid":{"rendered":"https:\/\/fwq.ai\/blog\/3403\/"},"modified":"2024-11-10T08:50:47","modified_gmt":"2024-11-10T00:50:47","slug":"js-echarts-%e5%a6%82%e4%bd%95%e8%bf%9e%e6%8e%a5js","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/3403\/","title":{"rendered":"js echarts \u5982\u4f55\u8fde\u63a5js"},"content":{"rendered":"<blockquote><p>\n  \u5c06 echarts \u8fde\u63a5\u5230 javascript \u9700\u8981\u516d\u4e2a\u6b65\u9aa4\uff1a\u4e0b\u8f7d echarts \u5e93\u5bfc\u5165 echarts \u5e93\u521b\u5efa\u4e00\u4e2a echarts \u5b9e\u4f8b\u8bbe\u7f6e\u9009\u9879\u52a0\u8f7d\u9009\u9879\u54cd\u5e94\u4e8b\u4ef6\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202411\/08\/2024110811394061161.jpg\" class=\"aligncenter\" title=\"js echarts \u5982\u4f55\u8fde\u63a5js\u63d2\u56fe\" alt=\"js echarts \u5982\u4f55\u8fde\u63a5js\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u5c06 ECharts \u8fde\u63a5\u5230 JavaScript<\/strong><\/p>\n<p>ECharts \u662f\u4e00\u4e2a\u5f3a\u5927\u7684 JavaScript \u53ef\u89c6\u5316\u5e93\uff0c\u53ef\u4ee5\u5e2e\u52a9\u4f60\u521b\u5efa\u4ea4\u4e92\u5f0f\u56fe\u8868\u548c\u6570\u636e\u53ef\u89c6\u5316\u3002\u8fde\u63a5 ECharts \u5230 JavaScript \u53ea\u9700\u8981\u51e0\u6b65\u3002<\/p>\n<p><strong>1. \u4e0b\u8f7d ECharts \u5e93<\/strong><\/p>\n<p>\u4ece ECharts \u5b98\u7f51\u4e0b\u8f7d\u6700\u65b0\u7684 ECharts \u5e93\u3002\u4f60\u53ef\u4ee5\u5728 ECharts \u7f51\u7ad9\u4e0a\u627e\u5230\u4e0b\u8f7d\u94fe\u63a5\u3002<\/p>\n<p><strong>2. \u5bfc\u5165 ECharts \u5e93<\/strong><\/p>\n<p>\u5c06 ECharts \u5e93\u5bfc\u5165\u4f60\u7684 JavaScript \u4ee3\u7801\u3002\u4f60\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u65b9\u5f0f\u6765\u505a\u5230\u8fd9\u4e00\u70b9\uff1a<\/p>\n<pre>&lt;script src=\"path\/to\/echarts.min.js\"&gt;&lt;\/script&gt;<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p><strong>3. \u521b\u5efa\u4e00\u4e2a ECharts \u5b9e\u4f8b<\/strong><\/p>\n<p>\u8981\u521b\u5efa ECharts \u5b9e\u4f8b\uff0c\u4f60\u9700\u8981\u521b\u5efa\u4e00\u4e2a div \u5143\u7d20\uff0c\u5e76\u6307\u5b9a\u5176 id\u3002\u7136\u540e\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528 echarts.init() \u65b9\u6cd5\u6765\u521b\u5efa ECharts \u5b9e\u4f8b\u3002<\/p>\n<pre>var myChart = echarts.init(document.getElementById('myChart'));<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p><strong>4. \u8bbe\u7f6e\u9009\u9879<\/strong><\/p>\n<p>\u63a5\u4e0b\u6765\uff0c\u4f60\u9700\u8981\u8bbe\u7f6e ECharts \u5b9e\u4f8b\u7684\u9009\u9879\u3002\u9009\u9879\u7528\u4e8e\u5b9a\u4e49\u56fe\u8868\u7c7b\u578b\u3001\u6570\u636e\u3001\u6837\u5f0f\u548c\u4ea4\u4e92\u884c\u4e3a\u3002<\/p>\n<pre>var option = {\n  \/\/ \u56fe\u8868\u7c7b\u578b\n  series: [{\n    type: 'bar',\n    data: [1, 2, 3]\n  }]\n};<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p><strong>5. \u52a0\u8f7d\u9009\u9879<\/strong><\/p>\n<p>\u5c06\u9009\u9879\u52a0\u8f7d\u5230 ECharts \u5b9e\u4f8b\u4e2d\uff0c\u4ee5\u6e32\u67d3\u56fe\u8868\u3002<\/p>\n<pre>myChart.setOption(option);<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p><strong>6. \u54cd\u5e94\u4e8b\u4ef6<\/strong><\/p>\n<p>ECharts \u5b9e\u4f8b\u652f\u6301\u591a\u79cd\u4e8b\u4ef6\uff0c\u4f8b\u5982\u5355\u51fb\u3001\u60ac\u505c\u548c\u7f29\u653e\u3002\u4f60\u53ef\u4ee5\u4f7f\u7528 on() \u65b9\u6cd5\u6765\u4e3a\u8fd9\u4e9b\u4e8b\u4ef6\u6dfb\u52a0\u76d1\u542c\u5668\u3002<\/p>\n<pre>myChart.on('click', function(params) {\n  console.log(params);\n});<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u901a\u8fc7\u9075\u5faa\u8fd9\u4e9b\u6b65\u9aa4\uff0c\u4f60\u53ef\u4ee5\u8f7b\u677e\u5730\u5c06 ECharts \u8fde\u63a5\u5230 JavaScript \u5e76\u521b\u5efa\u4ea4\u4e92\u5f0f\u6570\u636e\u53ef\u89c6\u5316\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fjs echarts \u5982\u4f55\u8fde\u63a5js\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>\u5c06 echarts \u8fde\u63a5\u5230 javascript \u9700\u8981\u516d\u4e2a\u6b65\u9aa4\uff1a\u4e0b\u8f7d echarts \u5e93\u5bfc\u5165 echarts \u5e93\u521b\u5efa\u4e00\u4e2a echarts \u5b9e\u4f8b\u8bbe\u7f6e\u9009\u9879\u52a0\u8f7d\u9009\u9879\u54cd\u5e94\u4e8b\u4ef6 \u5982\u4f55\u5c06 ECharts \u8fde\u63a5\u5230 JavaScript ECharts \u662f\u4e00\u4e2a\u5f3a\u5927\u7684 JavaScript \u53ef\u89c6\u5316\u5e93\uff0c\u53ef\u4ee5\u5e2e\u52a9\u4f60\u521b\u5efa\u4ea4\u4e92\u5f0f\u56fe\u8868\u548c\u6570\u636e\u53ef\u89c6\u5316\u3002\u8fde\u63a5 ECharts \u5230 JavaScript \u53ea\u9700\u8981\u51e0\u6b65\u3002 1. \u4e0b\u8f7d ECharts \u5e93 \u4ece ECharts \u5b98\u7f51\u4e0b\u8f7d\u6700\u65b0\u7684 ECharts \u5e93\u3002\u4f60\u53ef\u4ee5\u5728 ECharts \u7f51\u7ad9\u4e0a\u627e\u5230\u4e0b\u8f7d\u94fe\u63a5\u3002 2. \u5bfc\u5165 ECharts \u5e93 \u5c06 ECharts \u5e93\u5bfc\u5165\u4f60\u7684 JavaScript \u4ee3\u7801\u3002\u4f60\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u65b9\u5f0f\u6765\u505a\u5230\u8fd9\u4e00\u70b9\uff1a &lt;script src=&#8221;path\/to\/echarts.min.js&#8221;&gt;&lt;\/script&gt; \u767b\u5f55\u540e\u590d\u5236 3. \u521b\u5efa\u4e00\u4e2a ECharts \u5b9e\u4f8b \u8981\u521b\u5efa ECharts \u5b9e\u4f8b\uff0c\u4f60\u9700\u8981\u521b\u5efa\u4e00\u4e2a div \u5143\u7d20\uff0c\u5e76\u6307\u5b9a\u5176 [&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-3403","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/3403","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=3403"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/3403\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=3403"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=3403"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=3403"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}