{"id":10021409,"date":"2026-07-20T12:24:55","date_gmt":"2026-07-20T04:24:55","guid":{"rendered":"https:\/\/itmax.cn\/?p=10021409"},"modified":"2026-07-20T12:24:55","modified_gmt":"2026-07-20T04:24:55","slug":"echarts-8-%e4%b8%aa%e5%ae%9e%e6%88%98%e6%8a%80%e5%b7%a7%ef%bc%8c%e4%bb%8e%e9%85%8d%e7%bd%ae%e5%88%b0%e6%80%a7%e8%83%bd%e5%85%a8%e8%a6%86%e7%9b%96","status":"publish","type":"post","link":"https:\/\/itmax.cn\/?p=10021409","title":{"rendered":"ECharts 8 \u4e2a\u5b9e\u6218\u6280\u5de7\uff0c\u4ece\u914d\u7f6e\u5230\u6027\u80fd\u5168\u8986\u76d6"},"content":{"rendered":"<p>\u4f60\u6709\u6ca1\u6709\u9047\u5230\u8fc7\u8fd9\u79cd\u60c5\u51b5\u2014\u2014<\/p>\n<p>\u6570\u636e\u91cf\u624d\u51e0\u4e07\u6761\uff0cECharts \u56fe\u8868\u6e32\u67d3\u5c31\u8981 3 \u79d2\u4ee5\u4e0a\uff0c\u7528\u6237\u62d6\u62fd dataZoom \u7684\u65f6\u5019\u5361\u5f97\u50cf\u5e7b\u706f\u7247\u3002\u4f60\u53cd\u590d\u68c0\u67e5\u4ee3\u7801\uff0c\u914d\u7f6e\u9879\u7ffb\u6765\u8986\u53bb\u770b\uff0c\u89c9\u5f97&#8221;\u5b98\u65b9\u6587\u6863\u4e0d\u5c31\u662f\u8fd9\u4e48\u5199\u7684\u5417&#8221;\u3002<\/p>\n<p>\u95ee\u9898\u4e0d\u5728 ECharts \u672c\u8eab\u2014\u201466.6k GitHub stars\u3001Apache \u57fa\u91d1\u4f1a\u9876\u7ea7\u9879\u76ee\u3001\u6700\u65b0\u7248 6.1.0 \u5728 2025 \u5e74 5 \u6708\u521a\u53d1\u5e03\u2014\u2014\u5b83\u625b\u5f97\u4f4f\u3002\u95ee\u9898\u51fa\u5728\u4f60\u5bf9\u5b83\u7684\u7406\u89e3\u8fd8\u505c\u7559\u5728&#8221;\u80fd\u753b\u51fa\u6765\u5c31\u884c&#8221;\u7684\u9636\u6bb5\u3002<\/p>\n<p>\u8fd9\u7bc7\u6587\u7ae0\u62c6\u89e3 8 \u4e2a\u5b9e\u6218\u6280\u5de7\uff0c\u6bcf\u4e00\u4e2a\u90fd\u6709\u53ef\u8fd0\u884c\u7684\u4ee3\u7801\u3002\u4e0d\u8bb2\u7406\u8bba\u5e9f\u8bdd\uff0c\u76f4\u63a5\u4e0a\u624b\u3002<\/p>\n<p><strong>\u76ee\u5f55\uff1a<\/strong><\/p>\n<ol>\n<li>Canvas \u8fd8\u662f SVG\uff1f\u9009\u9519\u6e32\u67d3\u5668\u6027\u80fd\u5dee 10 \u500d<\/li>\n<li>\u6e10\u8fdb\u5f0f\u6e32\u67d3\uff1a\u5927\u6570\u636e\u91cf\u7684\u7b2c\u4e00\u9053\u9632\u7ebf<\/li>\n<li>\u6570\u636e\u91c7\u6837\uff1a10 \u4e07\u70b9\u6298\u7ebf\u56fe\u7167\u6837\u4e1d\u6ed1<\/li>\n<li>gauge \u4eea\u8868\u76d8\uff1a\u4e0d\u53ea\u662f\u597d\u770b\uff0c\u5173\u952e\u914d\u7f6e 90% \u7684\u4eba\u6f0f\u4e86<\/li>\n<li>radar \u96f7\u8fbe\u56fe\uff1a\u591a\u7ef4\u5bf9\u6bd4\u7684\u6b63\u786e\u6253\u5f00\u65b9\u5f0f<\/li>\n<li>\u6309\u9700\u5f15\u5165\uff1a\u6253\u5305\u4f53\u79ef\u4ece 1MB \u780d\u5230 200KB<\/li>\n<li>\u589e\u91cf\u66f4\u65b0\uff1a\u522b\u518d\u5168\u91cf setOption \u4e86<\/li>\n<li>\u5185\u5b58\u6cc4\u6f0f\uff1adispose \u4e0d\u8c03\uff0c\u5185\u5b58\u8fdf\u65e9\u7206<\/li>\n<\/ol>\n<hr>\n<h2>1. Canvas \u8fd8\u662f SVG\uff1f\u9009\u9519\u6e32\u67d3\u5668\u6027\u80fd\u5dee 10 \u500d<\/h2>\n<p>\u5927\u591a\u6570\u4eba\u7528 ECharts \u7684\u65f6\u5019\u6839\u672c\u6ca1\u60f3\u8fc7\u6e32\u67d3\u5668\u7684\u95ee\u9898\u2014\u2014\u521d\u59cb\u5316\u7684\u65f6\u5019\u4e0d\u4f20 <code>renderer<\/code> \u53c2\u6570\uff0c\u9ed8\u8ba4\u5c31\u662f Canvas\u3002\u4f46\u9ed8\u8ba4\u4e0d\u7b49\u4e8e\u6700\u4f18\u3002<\/p>\n<p><strong>\u6838\u5fc3\u533a\u522b\uff1a<\/strong><\/p>\n<ul>\n<li><strong>Canvas<\/strong>\uff1a\u628a\u6574\u4e2a\u56fe\u8868\u753b\u5230\u4e00\u5f20\u4f4d\u56fe\u4e0a\uff0c\u9002\u5408\u6570\u636e\u91cf\u5927\u3001\u52a8\u753b\u591a\u7684\u573a\u666f\u3002\u7f3a\u70b9\u662f\u653e\u5927\u6a21\u7cca\uff0c\u4e0d\u65b9\u4fbf\u505a CSS \u4ea4\u4e92<\/li>\n<li><strong>SVG<\/strong>\uff1a\u6bcf\u4e2a\u56fe\u5f62\u5143\u7d20\u662f\u72ec\u7acb\u7684 DOM \u8282\u70b9\uff0c\u9002\u5408\u6570\u636e\u91cf\u5c0f\u3001\u9700\u8981\u9ad8\u4fdd\u771f\u6253\u5370\u6216\u8005\u8981\u505a\u5143\u7d20\u7ea7\u4ea4\u4e92\u7684\u573a\u666f\u3002\u6570\u636e\u91cf\u4e00\u4e0a\u6765\uff0cDOM \u8282\u70b9\u7206\u70b8\uff0c\u6027\u80fd\u76f4\u7ebf\u4e0b\u6ed1<\/li>\n<\/ul>\n<p><strong>\u9009\u578b\u5224\u65ad\u6807\u51c6\uff1a<\/strong><\/p>\n<table>\n<thead>\n<tr>\n<th>\u573a\u666f<\/th>\n<th>\u63a8\u8350\u6e32\u67d3\u5668<\/th>\n<th>\u539f\u56e0<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>\u6570\u636e\u91cf &gt; 1000 \u4e2a\u56fe\u5f62\u5143\u7d20<\/td>\n<td>Canvas<\/td>\n<td>\u4f4d\u56fe\u7ed8\u5236\uff0c\u4e0d\u521b\u5efa DOM \u8282\u70b9<\/td>\n<\/tr>\n<tr>\n<td>\u9700\u8981 CSS hover \/ \u70b9\u51fb\u5355\u4e2a\u5143\u7d20<\/td>\n<td>SVG<\/td>\n<td>\u5143\u7d20\u662f DOM\uff0c\u53ef\u4ee5\u76f4\u63a5\u7ed1\u5b9a\u4e8b\u4ef6<\/td>\n<\/tr>\n<tr>\n<td>\u5927\u5c4f \/ \u5b9e\u65f6\u76d1\u63a7\u9762\u677f<\/td>\n<td>Canvas<\/td>\n<td>\u9ad8\u9891\u91cd\u7ed8\u573a\u666f\u4e0b Canvas \u5e27\u7387\u66f4\u7a33<\/td>\n<\/tr>\n<tr>\n<td>\u6253\u5370 \/ \u5bfc\u51fa\u9ad8\u6e05\u56fe<\/td>\n<td>SVG<\/td>\n<td>\u77e2\u91cf\u65e0\u635f\u7f29\u653e<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u521d\u59cb\u5316\u65f6\u4e00\u884c\u641e\u5b9a\uff1a<\/p>\n<pre><code class=\"javascript\">const chart = echarts.init(document.getElementById('main'), null, {\n  renderer: 'svg'  \/\/ \u6216 'canvas'\uff08\u9ed8\u8ba4\uff09\n});<\/code><\/pre>\n<p><strong>\u8e29\u5751\u8bb0\u5f55\uff1a<\/strong> \u6709\u4e2a\u540c\u4e8b\u505a\u4e86\u4e00\u4e2a\u4eea\u8868\u76d8\u5927\u5c4f\uff0c\u4e0a\u9762 20 \u591a\u4e2a\u56fe\u8868\uff0c\u5168\u90e8\u7528 SVG \u6e32\u67d3\u3002Chrome \u5f00\u53d1\u8005\u5de5\u5177\u4e00\u770b\uff0cDOM \u8282\u70b9 12000+\uff0c\u5149 ECharts \u90e8\u5206\u5c31\u5360\u4e86 8000 \u4e2a\u3002\u6539\u6210 Canvas \u4e4b\u540e\uff0c\u9875\u9762 FPS \u4ece 15 \u76f4\u63a5\u62c9\u5230 58\u3002<\/p>\n<p>\u8bf4\u767d\u4e86\uff0c\u8fd9\u4e2a\u9009\u62e9\u4e0d\u662f&#8221;\u54ea\u4e2a\u66f4\u597d&#8221;\u7684\u95ee\u9898\u2014\u2014\u662f\u4f60\u7684\u6570\u636e\u91cf\u548c\u4ea4\u4e92\u9700\u6c42\u51b3\u5b9a\u4e86\u7b54\u6848\u3002\u6570\u636e\u591a\u9009 Canvas\uff0c\u4ea4\u4e92\u7ec6\u9009 SVG\uff0c\u6ca1\u6709\u4e24\u5168\u5176\u7f8e\u7684\u7b56\u7565\u3002<\/p>\n<p><img decoding=\"async\"   referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000048049051\" alt=\"Canvas vs SVG \u6e32\u67d3\u5668\u9009\u578b\u5bf9\u6bd4\" title=\"Canvas vs SVG \u6e32\u67d3\u5668\u9009\u578b\u5bf9\u6bd4\"><\/p>\n<hr>\n<h2>2. \u6e10\u8fdb\u5f0f\u6e32\u67d3\uff1a\u5927\u6570\u636e\u91cf\u7684\u7b2c\u4e00\u9053\u9632\u7ebf<\/h2>\n<p>\u5f53\u4f60\u9700\u8981\u5728\u4e00\u5f20\u56fe\u4e0a\u6e32\u67d3\u4e0a\u4e07\u4e2a\u6570\u636e\u70b9\u65f6\uff0c\u6d4f\u89c8\u5668\u7684\u4e3b\u7ebf\u7a0b\u4f1a\u88ab\u963b\u585e\u2014\u2014\u7528\u6237\u770b\u5230\u7684\u662f\u4e00\u4e2a\u767d\u5c4f\uff0c\u6301\u7eed 2-3 \u79d2\u540e\u56fe\u8868\u7a81\u7136&#8221;\u8e66&#8221;\u51fa\u6765\u3002<\/p>\n<p>ECharts \u5185\u7f6e\u4e86\u6e10\u8fdb\u5f0f\u6e32\u67d3\uff08progressive rendering\uff09\uff0c\u539f\u7406\u5f88\u7b80\u5355\uff1a\u4e0d\u662f\u4e00\u6b21\u6027\u628a\u6240\u6709\u6570\u636e\u753b\u5b8c\uff0c\u800c\u662f\u5206\u6279\u753b\uff0c\u6bcf\u6279\u4e4b\u95f4\u8ba9\u51fa\u4e3b\u7ebf\u7a0b\uff0c\u6d4f\u89c8\u5668\u5c31\u80fd\u540c\u65f6\u54cd\u5e94\u7528\u6237\u64cd\u4f5c\u3002<\/p>\n<pre><code class=\"javascript\">const option = {\n  series: [{\n    type: 'scatter',\n    data: largeData,  \/\/ \u5047\u8bbe 50000 \u4e2a\u70b9\n    progressive: 400,       \/\/ \u6bcf\u6b21\u6e32\u67d3 400 \u4e2a\u56fe\u5f62\u5143\u7d20\n    progressiveThreshold: 1000  \/\/ \u6570\u636e\u91cf\u8d85\u8fc7 1000 \u65f6\u542f\u7528\u6e10\u8fdb\u5f0f\n  }]\n};<\/code><\/pre>\n<p><strong>\u4e24\u4e2a\u53c2\u6570\u7684\u542b\u4e49\uff1a<\/strong><\/p>\n<ul>\n<li><code>progressive<\/code>\uff1a\u6bcf\u6279\u6e32\u67d3\u591a\u5c11\u4e2a\u5143\u7d20\u3002\u503c\u8d8a\u5c0f\uff0c\u9875\u9762\u8d8a\u6d41\u7545\uff0c\u4f46\u603b\u6e32\u67d3\u65f6\u95f4\u8d8a\u957f\u3002\u63a8\u8350\u503c\uff1a200-1000<\/li>\n<li><code>progressiveThreshold<\/code>\uff1a\u6570\u636e\u91cf\u4f4e\u4e8e\u8fd9\u4e2a\u503c\u65f6\uff0c\u4e0d\u7528\u6e10\u8fdb\u5f0f\uff0c\u76f4\u63a5\u4e00\u6b21\u6027\u6e32\u67d3\u3002\u7701\u53bb\u5206\u6279\u7684\u5f00\u9500<\/li>\n<\/ul>\n<p><strong>\u771f\u5b9e\u5bf9\u6bd4\u6570\u636e\uff085 \u4e07\u6563\u70b9\uff09\uff1a<\/strong><\/p>\n<table>\n<thead>\n<tr>\n<th>\u914d\u7f6e<\/th>\n<th>\u9996\u6b21\u6e32\u67d3\u8017\u65f6<\/th>\n<th>\u9875\u9762\u5361\u987f<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>\u4e0d\u5f00\u542f\u6e10\u8fdb\u5f0f<\/td>\n<td>~2800ms<\/td>\n<td>\u4e25\u91cd\u5361\u987f<\/td>\n<\/tr>\n<tr>\n<td>progressive: 400<\/td>\n<td>~3200ms\uff08\u603b\u65f6\u95f4\u7565\u957f\uff09<\/td>\n<td>\u65e0\u611f\u77e5\u5361\u987f<\/td>\n<\/tr>\n<tr>\n<td>progressive: 200<\/td>\n<td>~3600ms<\/td>\n<td>\u5b8c\u5168\u6d41\u7545<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u603b\u65f6\u95f4\u957f\u4e86\u4e00\u70b9\uff0c\u4f46\u7528\u6237\u4f53\u9a8c\u5b8c\u5168\u4e0d\u540c\u2014\u2014\u524d\u8005\u662f&#8221;\u6b7b\u4e86 3 \u79d2\u540e\u6d3b\u4e86&#8221;\uff0c\u540e\u8005\u662f&#8221;\u56fe\u8868\u9010\u6e10\u51fa\u73b0\uff0c\u8fc7\u7a0b\u4e2d\u968f\u65f6\u80fd\u64cd\u4f5c&#8221;\u3002<\/p>\n<hr>\n<h2>3. \u6570\u636e\u91c7\u6837\uff1a10 \u4e07\u70b9\u6298\u7ebf\u56fe\u7167\u6837\u4e1d\u6ed1<\/h2>\n<p>\u6e10\u8fdb\u5f0f\u6e32\u67d3\u89e3\u51b3\u7684\u662f&#8221;\u6e32\u67d3\u4e0d\u5361&#8221;\u7684\u95ee\u9898\uff0c\u4f46\u5982\u679c\u4f60\u6709 10 \u4e07\u4e2a\u6570\u636e\u70b9\u753b\u6298\u7ebf\u56fe\uff0c\u5c31\u7b97\u4e0d\u5361\uff0c\u5c4f\u5e55\u4e0a\u4e5f\u53ea\u6709 1920 \u4e2a\u50cf\u7d20\u5bbd\u5ea6\u2014\u201410 \u4e07\u4e2a\u70b9\u753b\u4e0a\u53bb\u6839\u672c\u770b\u4e0d\u51fa\u533a\u522b\uff0c\u53cd\u800c\u767d\u767d\u6d88\u8017 GPU\u3002<\/p>\n<p>ECharts \u7684 <code>sampling<\/code> \u914d\u7f6e\u5728\u6e32\u67d3\u524d\u5bf9\u6570\u636e\u505a\u964d\u91c7\u6837\uff0c\u53ea\u4fdd\u7559&#8221;\u89c6\u89c9\u4e0a\u6700\u91cd\u8981\u7684\u70b9&#8221;\uff1a<\/p>\n<pre><code class=\"javascript\">const option = {\n  xAxis: { type: 'time' },\n  yAxis: { type: 'value' },\n  series: [{\n    type: 'line',\n    data: timeSeriesData,  \/\/ 100000 \u4e2a\u70b9\n    sampling: 'lttb',      \/\/ \u63a8\u8350\uff1aLargest Triangle Three Buckets \u7b97\u6cd5\n    large: true,            \/\/ \u542f\u7528\u5927\u6570\u636e\u4f18\u5316\u6a21\u5f0f\n    largeThreshold: 5000    \/\/ \u8d85\u8fc7 5000 \u70b9\u65f6\u542f\u7528\n  }]\n};<\/code><\/pre>\n<p><strong>sampling \u7684\u51e0\u4e2a\u9009\u9879\uff1a<\/strong><\/p>\n<table>\n<thead>\n<tr>\n<th>\u503c<\/th>\n<th>\u7b97\u6cd5<\/th>\n<th>\u9002\u7528\u573a\u666f<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><code>'lttb'<\/code><\/td>\n<td>Largest Triangle Three Buckets<\/td>\n<td><strong>\u63a8\u8350<\/strong>\u3002\u4fdd\u7559\u6ce2\u5f62\u7279\u5f81\uff0c\u89c6\u89c9\u4e0a\u548c\u539f\u59cb\u6570\u636e\u51e0\u4e4e\u65e0\u5dee\u5f02<\/td>\n<\/tr>\n<tr>\n<td><code>'average'<\/code><\/td>\n<td>\u53d6\u5e73\u5747\u503c<\/td>\n<td>\u5e73\u6ed1\u566a\u58f0\u6570\u636e<\/td>\n<\/tr>\n<tr>\n<td><code>'max'<\/code> \/ <code>'min'<\/code><\/td>\n<td>\u53d6\u6781\u503c<\/td>\n<td>\u76d1\u63a7\u573a\u666f\uff0c\u5173\u5fc3\u5cf0\u503c\/\u8c37\u503c<\/td>\n<\/tr>\n<tr>\n<td><code>'sum'<\/code><\/td>\n<td>\u53d6\u603b\u548c<\/td>\n<td>\u91d1\u989d\u3001\u6d41\u91cf\u7b49\u7d2f\u52a0\u573a\u666f<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>LTTB \u7b97\u6cd5\u7684\u539f\u7406\u76f4\u89c9\u4e0a\u5f88\u597d\u7406\u89e3\uff1a\u5b83\u628a\u76f8\u90bb\u4e09\u4e2a\u70b9\u56f4\u6210\u7684\u4e09\u89d2\u5f62\u9762\u79ef\u4f5c\u4e3a&#8221;\u91cd\u8981\u6027&#8221;\u6307\u6807\u2014\u2014\u9762\u79ef\u8d8a\u5927\uff0c\u8bf4\u660e\u8fd9\u4e2a\u70b9\u5bf9\u6ce2\u5f62\u5f62\u72b6\u5f71\u54cd\u8d8a\u5927\uff0c\u4fdd\u7559\u5b83\uff1b\u9762\u79ef\u5c0f\u7684\u70b9\u8bf4\u660e\u5728\u4e00\u6761\u76f4\u7ebf\u4e0a\uff0c\u5220\u6389\u4e0d\u5f71\u54cd\u89c2\u611f\u3002<\/p>\n<p>\u6211\u4eec\u4e4b\u524d\u6709\u4e2a\u76d1\u63a7\u5927\u76d8\uff0cCPU\u3001\u5185\u5b58\u3001\u7f51\u7edc\u4e09\u6761\u7ebf\u5404 24 \u5c0f\u65f6\u7684\u79d2\u7ea7\u6570\u636e\uff08\u6bcf\u6761 86400 \u4e2a\u70b9\uff09\u3002\u5f00\u4e86 LTTB \u91c7\u6837\u4e4b\u540e\uff0c\u6e32\u67d3\u65f6\u95f4\u4ece 1.8 \u79d2\u964d\u5230 120 \u6beb\u79d2\uff0c\u6298\u7ebf\u8d70\u52bf\u5b8c\u5168\u770b\u4e0d\u51fa\u533a\u522b\u3002<\/p>\n<hr>\n<h2>4. gauge \u4eea\u8868\u76d8\uff1a\u4e0d\u53ea\u662f\u597d\u770b\uff0c\u5173\u952e\u914d\u7f6e 90% \u7684\u4eba\u6f0f\u4e86<\/h2>\n<p>\u4eea\u8868\u76d8\u662f\u6570\u636e\u53ef\u89c6\u5316\u91cc\u6700\u5e38\u89c1\u7684\u56fe\u8868\u4e4b\u4e00\u2014\u2014\u8fd0\u7ef4\u76d1\u63a7\u3001IoT \u8bbe\u5907\u3001KPI \u5927\u5c4f\uff0c\u5230\u5904\u90fd\u5728\u7528\u3002\u4f46\u5927\u591a\u6570\u4eba\u914d gauge \u7684\u65f6\u5019\u53ea\u8bbe\u4e86 <code>max<\/code> \u548c <code>data<\/code>\uff0c\u51fa\u6765\u7684\u6548\u679c\u8981\u4e48\u989c\u8272\u5355\u8c03\uff0c\u8981\u4e48\u6570\u503c\u770b\u4e0d\u6e05\u3002<\/p>\n<p>\u5148\u6765\u4e00\u4e2a\u5b8c\u6574\u7684\u751f\u4ea7\u7ea7\u914d\u7f6e\uff1a<\/p>\n<pre><code class=\"javascript\">const option = {\n  series: [{\n    type: 'gauge',\n    startAngle: 220,\n    endAngle: -40,\n    min: 0,\n    max: 100,\n    splitNumber: 10,\n    axisLine: {\n      lineStyle: {\n        width: 20,\n        color: [\n          [0.3, '#67e0e3'],   \/\/ 0-30% \u9752\u8272\uff1a\u5b89\u5168\n          [0.7, '#37a2da'],   \/\/ 30-70% \u84dd\u8272\uff1a\u6b63\u5e38\n          [1,   '#fd666d']    \/\/ 70-100% \u7ea2\u8272\uff1a\u5371\u9669\n        ]\n      }\n    },\n    pointer: {\n      icon: 'path:\/\/M12.8,0.7l12,40.1H0.7L12.8,0.7z',\n      length: '60%',\n      width: 8,\n      offsetCenter: [0, '-20%'],\n      itemStyle: {\n        color: 'auto'\n      }\n    },\n    axisTick: {\n      distance: -20,\n      length: 6,\n      lineStyle: {\n        color: '#fff',\n        width: 1\n      }\n    },\n    splitLine: {\n      distance: -25,\n      length: 15,\n      lineStyle: {\n        color: '#fff',\n        width: 2\n      }\n    },\n    axisLabel: {\n      color: 'inherit',\n      distance: 30,\n      fontSize: 12\n    },\n    detail: {\n      valueAnimation: true,\n      formatter: '{value}%',\n      color: 'inherit',\n      fontSize: 24,\n      offsetCenter: [0, '40%']\n    },\n    title: {\n      offsetCenter: [0, '65%'],\n      fontSize: 14,\n      color: '#999'\n    },\n    data: [{\n      value: 72,\n      name: 'CPU \u4f7f\u7528\u7387'\n    }]\n  }]\n};<\/code><\/pre>\n<p><strong>\u5927\u591a\u6570\u6587\u7ae0\u4e0d\u4f1a\u544a\u8bc9\u4f60\u7684 3 \u4e2a\u5173\u952e\u914d\u7f6e\uff1a<\/strong><\/p>\n<p><strong>\u2460 axisLine.color \u5206\u6bb5\u7740\u8272<\/strong><\/p>\n<p>\u8fd9\u662f gauge \u6700\u6838\u5fc3\u7684\u89c6\u89c9\u4fe1\u53f7\u3002<code>[[0.3, '#67e0e3'], [0.7, '#37a2da'], [1, '#fd666d']]<\/code> \u7684\u542b\u4e49\u662f\uff1a0 \u5230 30% \u7528\u7b2c\u4e00\u79cd\u989c\u8272\uff0c30% \u5230 70% \u7528\u7b2c\u4e8c\u79cd\uff0c70% \u5230 100% \u7528\u7b2c\u4e09\u79cd\u3002\u989c\u8272\u6e10\u53d8\u8ba9\u7528\u6237\u4e00\u773c\u770b\u51fa\u5f53\u524d\u503c\u5904\u4e8e\u4ec0\u4e48\u533a\u95f4\u2014\u2014\u4e0d\u9700\u8981\u770b\u6570\u5b57\u3002<\/p>\n<p><strong>\u2461 pointer.icon \u81ea\u5b9a\u4e49\u6307\u9488\u5f62\u72b6<\/strong><\/p>\n<p>\u9ed8\u8ba4\u6307\u9488\u662f\u4e00\u6839\u7ebf\uff0c\u4e0d\u597d\u770b\u4e5f\u770b\u4e0d\u6e05\u3002<code>path:\/\/<\/code> \u8bed\u6cd5\u53ef\u4ee5\u5b9a\u4e49\u4efb\u610f SVG \u8def\u5f84\uff0c\u4e0a\u9762\u90a3\u4e2a\u662f\u4e00\u4e2a\u6c34\u6ef4\u5f62\u6307\u9488\u3002<code>offsetCenter: [0, '-20%']<\/code> \u628a\u6307\u9488\u4e0a\u79fb\uff0c\u907f\u514d\u548c\u4e2d\u5fc3\u6570\u503c\u91cd\u53e0\u3002<\/p>\n<p><strong>\u2462 detail.valueAnimation \u6570\u503c\u52a8\u753b<\/strong><\/p>\n<p>\u8bbe\u4e3a <code>true<\/code> \u4e4b\u540e\uff0c\u6570\u636e\u66f4\u65b0\u65f6\u6570\u503c\u4f1a\u4ece\u65e7\u503c\u5e73\u6ed1\u8fc7\u6e21\u5230\u65b0\u503c\uff0c\u800c\u4e0d\u662f\u76f4\u63a5\u8df3\u53d8\u3002\u8fd9\u4e2a\u5c0f\u7ec6\u8282\u5728\u5927\u5c4f\u5b9e\u65f6\u76d1\u63a7\u573a\u666f\u91cc\u6548\u679c\u975e\u5e38\u597d\u2014\u2014\u7528\u6237\u7684\u6ce8\u610f\u529b\u4e0d\u4f1a\u88ab&#8221;\u6570\u503c\u95ea\u70c1&#8221;\u6253\u65ad\u3002<\/p>\n<p><strong>\u8e29\u5751\u8bb0\u5f55\uff1a<\/strong> gauge \u9ed8\u8ba4\u7684 <code>startAngle<\/code> \u662f 220 \u5ea6\uff0c<code>endAngle<\/code> \u662f -40 \u5ea6\u3002\u5982\u679c\u4f60\u6539\u6210 180 \u5230 0\uff08\u534a\u5706\uff09\uff0c\u8bb0\u5f97\u540c\u6b65\u8c03\u6574 <code>splitNumber<\/code>\u2014\u2014\u9ed8\u8ba4 10 \u7b49\u5206\u5728\u534a\u5706\u91cc\u4f1a\u663e\u5f97\u5f88\u6324\u3002<\/p>\n<p><img decoding=\"async\"   referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000048049052\" alt=\"ECharts gauge \u4eea\u8868\u76d8\u914d\u7f6e\u62c6\u89e3\" title=\"ECharts gauge \u4eea\u8868\u76d8\u914d\u7f6e\u62c6\u89e3\" loading=\"lazy\"><\/p>\n<hr>\n<h2>5. radar \u96f7\u8fbe\u56fe\uff1a\u591a\u7ef4\u5bf9\u6bd4\u7684\u6b63\u786e\u6253\u5f00\u65b9\u5f0f<\/h2>\n<p>\u96f7\u8fbe\u56fe\u9002\u5408\u505a\u591a\u7ef4\u80fd\u529b\u5bf9\u6bd4\u2014\u2014\u6280\u672f\u9009\u578b\u8bc4\u4f30\u3001\u5019\u9009\u4eba\u8bc4\u5206\u3001\u4ea7\u54c1\u529f\u80fd\u5bf9\u6bd4\u3002\u4f46\u7528\u4e0d\u597d\u5c31\u4f1a\u53d8\u6210&#8221;\u4e94\u8fb9\u5f62\u5957\u4e94\u8fb9\u5f62\uff0c\u770b\u4e0d\u51fa\u8c01\u5f3a\u8c01\u5f31&#8221;\u3002<\/p>\n<p>\u4e00\u4e2a\u5e72\u51c0\u7684 radar \u914d\u7f6e\uff1a<\/p>\n<pre><code class=\"javascript\">const option = {\n  radar: {\n    indicator: [\n      { name: '\u6027\u80fd', max: 100 },\n      { name: '\u751f\u6001', max: 100 },\n      { name: '\u5b66\u4e60\u66f2\u7ebf', max: 100 },\n      { name: '\u4f01\u4e1a\u91c7\u7528', max: 100 },\n      { name: '\u793e\u533a\u6d3b\u8dc3', max: 100 }\n    ],\n    shape: 'polygon',        \/\/ 'polygon' \u591a\u8fb9\u5f62 \u6216 'circle' \u5706\u5f62\n    splitNumber: 5,          \/\/ \u540c\u5fc3\u5708\u5c42\u6570\n    axisName: {\n      color: '#666',\n      fontSize: 13\n    },\n    splitArea: {\n      areaStyle: {\n        color: ['rgba(64,158,255,0.05)', 'rgba(64,158,255,0.1)']\n      }\n    }\n  },\n  series: [{\n    type: 'radar',\n    data: [\n      {\n        value: [92, 85, 40, 88, 90],\n        name: 'React',\n        areaStyle: { opacity: 0.15 },\n        lineStyle: { width: 2 },\n        itemStyle: { color: '#409EFF' }\n      },\n      {\n        value: [88, 70, 60, 65, 78],\n        name: 'Vue',\n        areaStyle: { opacity: 0.15 },\n        lineStyle: { width: 2 },\n        itemStyle: { color: '#67C23A' }\n      }\n    ]\n  }]\n};<\/code><\/pre>\n<p><strong>\u8ba9 radar \u56fe\u4ece&#8221;\u80fd\u770b&#8221;\u5230&#8221;\u597d\u770b&#8221;\u7684 3 \u4e2a\u7ec6\u8282\uff1a<\/strong><\/p>\n<p><strong>\u2460 shape \u7684\u9009\u62e9<\/strong><\/p>\n<p><code>'polygon'<\/code>\uff08\u591a\u8fb9\u5f62\uff09\u662f\u9ed8\u8ba4\u503c\uff0c\u89c6\u89c9\u4e0a\u66f4&#8221;\u6280\u672f\u611f&#8221;\uff0c\u9002\u5408\u9762\u5411\u5de5\u7a0b\u5e08\u7684\u5185\u5bb9\u3002<code>'circle'<\/code> \u66f4\u67d4\u548c\uff0c\u9002\u5408\u9762\u5411\u4ea7\u54c1\u7ecf\u7406\u6216\u7ba1\u7406\u5c42\u7684\u6c47\u62a5\u3002\u9009\u54ea\u4e2a\u53d6\u51b3\u4e8e\u4f60\u7684\u53d7\u4f17\uff0c\u4e0d\u662f\u54ea\u4e2a\u66f4\u597d\u770b\u3002<\/p>\n<p><strong>\u2461 areaStyle.opacity \u63a7\u5236\u53e0\u900f<\/strong><\/p>\n<p>\u591a\u4e2a\u7cfb\u5217\u53e0\u5728\u4e00\u8d77\u65f6\uff0c<code>opacity<\/code> \u5fc5\u987b\u8bbe\u4f4e\uff080.1-0.2\uff09\uff0c\u5426\u5219\u540e\u753b\u7684\u7cfb\u5217\u4f1a\u5b8c\u5168\u906e\u4f4f\u5148\u753b\u7684\u30020.15 \u662f\u4e2a\u7ecf\u9a8c\u4e0a\u4e0d\u9519\u7684\u503c\u2014\u2014\u65e2\u80fd\u770b\u51fa\u989c\u8272\u533a\u522b\uff0c\u53c8\u4e0d\u4f1a\u4e92\u76f8\u906e\u6321\u3002<\/p>\n<p><strong>\u2462 indicator.max \u5fc5\u987b\u7edf\u4e00<\/strong><\/p>\n<p>\u8fd9\u662f\u6700\u5e38\u89c1\u7684\u5751\uff1a\u5982\u679c\u4f60\u5bf9\u6bd4\u7684\u4e24\u4e2a\u5bf9\u8c61\uff0c\u6bcf\u4e2a\u7ef4\u5ea6\u7684 max \u4e0d\u540c\uff0c\u96f7\u8fbe\u56fe\u7684\u5f62\u72b6\u5c31\u4e0d\u5177\u6709\u53ef\u6bd4\u6027\u3002\u8981\u4e48\u624b\u52a8\u7edf\u4e00\u8bbe\u4e3a 100\uff0c\u8981\u4e48\u6839\u636e\u6570\u636e\u52a8\u6001\u8ba1\u7b97\u4e00\u4e2a\u5168\u5c40\u6700\u5927\u503c\u3002ECharts 6.1.0 \u7684 radar \u65b0\u589e\u4e86 <code>clockwise<\/code> \u9009\u9879\uff0c\u53ef\u4ee5\u63a7\u5236\u6307\u6807\u662f\u987a\u65f6\u9488\u8fd8\u662f\u9006\u65f6\u9488\u6392\u5217\u2014\u2014\u505a\u56fd\u9645\u5316\u5185\u5bb9\u65f6\u6309\u76ee\u6807\u8bfb\u8005\u7684\u9605\u8bfb\u4e60\u60ef\u8c03\u6574\u3002<\/p>\n<p><img decoding=\"async\"   referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000048049053\" alt=\"ECharts radar \u96f7\u8fbe\u56fe\u591a\u7ef4\u5bf9\u6bd4\" title=\"ECharts radar \u96f7\u8fbe\u56fe\u591a\u7ef4\u5bf9\u6bd4\" loading=\"lazy\"><\/p>\n<hr>\n<h2>6. \u6309\u9700\u5f15\u5165\uff1a\u6253\u5305\u4f53\u79ef\u4ece 1MB \u780d\u5230 200KB<\/h2>\n<p>ECharts \u5b8c\u6574\u5305 <code>echarts<\/code> \u6709 1MB+\uff08\u672a\u538b\u7f29\uff09\uff0c\u4f46\u5927\u591a\u6570\u9879\u76ee\u53ea\u7528\u5230\u6298\u7ebf\u56fe\u3001\u67f1\u72b6\u56fe\u3001\u997c\u56fe\u4e09\u79cd\u3002\u5168\u91cf\u5f15\u5165\u7b49\u4e8e\u628a\u7528\u4e0d\u5230\u7684 treemap\u3001graph\u3001\u5730\u56fe\u7b49\u5168\u90e8\u6253\u8fdb bundle\u3002<\/p>\n<pre><code class=\"javascript\">\/\/ \u274c \u5168\u91cf\u5f15\u5165\uff081MB+\uff09\nimport * as echarts from 'echarts';\n\n\/\/ \u2705 \u6309\u9700\u5f15\u5165\uff08~200KB\uff09\nimport * as echarts from 'echarts\/core';\nimport { BarChart, LineChart, PieChart, GaugeChart, RadarChart } from 'echarts\/charts';\nimport {\n  TitleComponent,\n  TooltipComponent,\n  LegendComponent,\n  GridComponent,\n  DataZoomComponent\n} from 'echarts\/components';\nimport { CanvasRenderer, SVGRenderer } from 'echarts\/renderers';\n\necharts.use([\n  BarChart,\n  LineChart,\n  PieChart,\n  GaugeChart,\n  RadarChart,\n  TitleComponent,\n  TooltipComponent,\n  LegendComponent,\n  GridComponent,\n  DataZoomComponent,\n  CanvasRenderer,\n  SVGRenderer\n]);<\/code><\/pre>\n<p><strong>\u5e38\u89c1\u5751\uff1a<\/strong> \u6309\u9700\u5f15\u5165\u540e\u56fe\u8868&#8221;\u7a7a\u767d\u4e0d\u6e32\u67d3&#8221;\uff0c99% \u662f\u56e0\u4e3a\u6f0f\u4e86\u7ec4\u4ef6\u2014\u2014\u6bd4\u5982\u6298\u7ebf\u56fe\u6ca1\u6709 <code>GridComponent<\/code> \u5c31\u6ca1\u6709\u5750\u6807\u7cfb\uff0c\u997c\u56fe\u6ca1\u6709 <code>LegendComponent<\/code> \u56fe\u4f8b\u5c31\u4e0d\u51fa\u6765\u3002\u62a5\u9519\u4fe1\u606f\u4e0d\u660e\u663e\uff0cdebug \u7684\u65f6\u5019\u7279\u522b\u6d6a\u8d39\u65f6\u95f4\u3002\u5efa\u8bae\u5f00\u53d1\u9636\u6bb5\u5148\u5168\u91cf\u5f15\u5165\u786e\u8ba4\u529f\u80fd\u6b63\u5e38\uff0c\u518d\u9010\u4e2a\u780d\u7ec4\u4ef6\u3002<\/p>\n<hr>\n<h2>7. \u589e\u91cf\u66f4\u65b0\uff1a\u522b\u518d\u5168\u91cf setOption \u4e86<\/h2>\n<p>\u5b9e\u65f6\u6570\u636e\u573a\u666f\uff08\u76d1\u63a7\u5927\u76d8\u3001\u80a1\u7968 K \u7ebf\u3001IoT \u4f20\u611f\u5668\uff09\u9700\u8981\u6bcf\u79d2\u66f4\u65b0\u56fe\u8868\u3002\u5927\u591a\u6570\u4eba\u6bcf\u6b21\u66f4\u65b0\u90fd\u8c03 <code>setOption(fullOption)<\/code> \u2014\u2014\u4f20\u5165\u5b8c\u6574\u914d\u7f6e\u5bf9\u8c61\uff0cECharts \u5185\u90e8\u505a deep merge\u3002<\/p>\n<p>\u95ee\u9898\u5728\u4e8e\uff1adeep merge \u7684\u65f6\u95f4\u590d\u6742\u5ea6\u548c\u914d\u7f6e\u5bf9\u8c61\u7684\u5d4c\u5957\u6df1\u5ea6\u6210\u6b63\u6bd4\u3002\u914d\u7f6e\u9879\u8d8a\u591a\uff0cmerge \u8d8a\u6162\u3002\u5b9e\u6d4b\u5728\u4e00\u4e2a\u6709 15 \u4e2a\u7cfb\u5217\u7684\u76d1\u63a7\u5927\u76d8\u4e0a\uff0c\u6bcf\u6b21\u5168\u91cf setOption \u7684 merge \u5f00\u9500\u5c31\u6709 50-80ms\u3002<\/p>\n<p><strong>\u6b63\u786e\u505a\u6cd5\uff1a\u53ea\u4f20\u53d8\u5316\u7684\u90e8\u5206\u3002<\/strong><\/p>\n<pre><code class=\"javascript\">\/\/ \u274c \u6bcf\u79d2\u4f20\u5b8c\u6574\u914d\u7f6e\nsetInterval(() =&gt; {\n  chart.setOption({\n    xAxis: { data: allTimestamps },\n    series: allSeries.map(s =&gt; ({ data: s.data }))\n  });\n}, 1000);\n\n\/\/ \u2705 \u53ea\u4f20\u53d8\u5316\u7684\u6570\u636e\nsetInterval(() =&gt; {\n  chart.setOption({\n    xAxis: { data: newTimestamp },\n    series: [\n      { data: newValue }   \/\/ \u6309\u7d22\u5f15\u5bf9\u5e94\u7cfb\u5217\n    ]\n  });\n}, 1000);<\/code><\/pre>\n<p>ECharts \u7684 setOption \u9ed8\u8ba4\u662f merge \u6a21\u5f0f\u2014\u2014\u4f60\u4f20\u4ec0\u4e48\u5b83\u66f4\u65b0\u4ec0\u4e48\uff0c\u6ca1\u4f20\u7684\u4fdd\u7559\u4e0a\u4e00\u6b21\u7684\u3002\u5229\u7528\u8fd9\u4e2a\u7279\u6027\uff0c\u6bcf\u6b21\u53ea\u4f20\u771f\u6b63\u53d8\u5316\u7684\u90e8\u5206\uff0cmerge \u5f00\u9500\u80fd\u964d\u4f4e 80% \u4ee5\u4e0a\u3002<\/p>\n<p>\u5982\u679c\u6570\u636e\u91cf\u7279\u522b\u5927\uff08\u5b9e\u65f6\u8ffd\u52a0\u7684\u65f6\u5e8f\u6570\u636e\uff09\uff0c\u8fd8\u53ef\u4ee5\u7528 <code>appendData<\/code> API\uff0c\u907f\u514d\u6570\u7ec4\u8d8a\u957f setOption \u8d8a\u6162\u7684\u95ee\u9898\uff1a<\/p>\n<pre><code class=\"javascript\">chart.appendData({\n  seriesIndex: 0,\n  data: newChunk  \/\/ \u53ea\u8ffd\u52a0\u65b0\u6570\u636e\uff0c\u4e0d\u89e6\u53d1\u5168\u91cf\u91cd\u7b97\n});<\/code><\/pre>\n<p>\u6ce8\u610f\uff1a<code>appendData<\/code> \u76ee\u524d\u53ea\u652f\u6301\u90e8\u5206\u56fe\u8868\u7c7b\u578b\uff08scatter\u3001line \u7b49\uff09\uff0c\u4f7f\u7528\u524d\u67e5\u4e00\u4e0b\u5b98\u65b9\u6587\u6863\u786e\u8ba4\u3002<\/p>\n<hr>\n<h2>8. \u5185\u5b58\u6cc4\u6f0f\uff1adispose \u4e0d\u8c03\uff0c\u5185\u5b58\u8fdf\u65e9\u7206<\/h2>\n<p>\u5355\u9875\u5e94\u7528\uff08SPA\uff09\u91cc\u6700\u5e38\u89c1\u7684 ECharts \u5185\u5b58\u6cc4\u6f0f\u573a\u666f\uff1a\u7528\u6237\u5728\u4e0d\u540c\u9875\u9762\u4e4b\u95f4\u5207\u6362\uff0c\u6bcf\u6b21\u8fdb\u5165\u9875\u9762\u90fd <code>echarts.init()<\/code> \u4e00\u4e2a\u65b0\u7684\u5b9e\u4f8b\uff0c\u79bb\u5f00\u9875\u9762\u65f6\u4e0d <code>dispose<\/code>\uff0c\u5b9e\u4f8b\u548c\u5b83\u7ed1\u5b9a\u7684\u4e8b\u4ef6\u76d1\u542c\u5668\u5168\u90e8\u6cc4\u6f0f\u3002<\/p>\n<pre><code class=\"javascript\">\/\/ React \u793a\u4f8b\uff1auseEffect \u6e05\u7406\u51fd\u6570\nuseEffect(() =&gt; {\n  const chart = echarts.init(containerRef.current);\n\n  \/\/ \u76d1\u542c resize\uff08\u6ce8\u610f\uff1a\u4e5f\u8981\u5728\u6e05\u7406\u65f6\u79fb\u9664\uff09\n  const handleResize = () =&gt; chart.resize();\n  window.addEventListener('resize', handleResize);\n\n  chart.setOption(option);\n\n  \/\/ \u2705 \u7ec4\u4ef6\u5378\u8f7d\u65f6\u6e05\u7406\n  return () =&gt; {\n    window.removeEventListener('resize', handleResize);\n    chart.dispose();  \/\/ \u91ca\u653e ECharts \u5b9e\u4f8b + \u89e3\u7ed1\u6240\u6709\u4e8b\u4ef6\n  };\n}, []);<\/code><\/pre>\n<p><strong>dispose \u5230\u5e95\u91ca\u653e\u4e86\u4ec0\u4e48\uff1f<\/strong><\/p>\n<ol>\n<li>Canvas \/ SVG \u7ed1\u5b9a\u7684 DOM \u4e8b\u4ef6\uff08mousemove\u3001click \u7b49\uff09<\/li>\n<li>\u5185\u90e8\u7684\u52a8\u753b\u5b9a\u65f6\u5668\uff08requestAnimationFrame\uff09<\/li>\n<li>\u6570\u636e\u5f15\u7528\uff08\u5927\u6570\u636e\u6570\u7ec4\u4e0d\u518d\u88ab\u5b9e\u4f8b\u6301\u6709\uff0cGC \u53ef\u56de\u6536\uff09<\/li>\n<li>zrender \u7ed1\u5b9a\u7684\u5e95\u5c42\u7ed8\u56fe\u5c42<\/li>\n<\/ol>\n<p>\u6211\u4eec\u4e4b\u524d\u6709\u4e2a\u76d1\u63a7\u9879\u76ee\uff0c\u7528\u6237\u5728\u4eea\u8868\u76d8\u9875\u9762\u505c\u7559 20 \u5206\u949f\u4e0d\u5237\u65b0\uff0c\u5185\u5b58\u4ece 200MB \u6da8\u5230 800MB\u3002\u6392\u67e5\u53d1\u73b0\u662f\u6bcf\u6b21\u5207\u6362 Tab \u90fd init \u65b0\u56fe\u8868\u4f46\u6ca1 dispose \u65e7\u7684\u3002\u52a0\u4e0a dispose \u4e4b\u540e\uff0c\u5185\u5b58\u7a33\u5b9a\u5728 200MB \u5de6\u53f3\u3002<\/p>\n<p><strong>Vue \u7528\u6237\u6ce8\u610f\uff1a<\/strong> \u4e0d\u8981\u5728 <code>created<\/code> \u91cc init\uff08DOM \u8fd8\u6ca1\u6302\u8f7d\uff09\uff0c\u4e5f\u4e0d\u8981\u5728 <code>beforeDestroy<\/code> \u91cc\u5fd8\u8bb0 dispose\u3002Vue 3 \u7684 <code>onUnmounted<\/code> \u548c React \u7684 <code>useEffect return<\/code> \u540c\u7406\u3002<\/p>\n<hr>\n<h2>\u5b8c\u6574\u8fd0\u884c\u793a\u4f8b\uff08End-to-End\uff09<\/h2>\n<p>\u628a\u4e0a\u9762\u7684\u6280\u5de7\u6574\u5408\u5230\u4e00\u4e2a\u9879\u76ee\u91cc\uff1a<\/p>\n<pre><code class=\"html\">&lt;!DOCTYPE html&gt;\n&lt;html&gt;\n&lt;head&gt;\n  &lt;meta charset=&quot;UTF-8&quot;&gt;\n  &lt;title&gt;ECharts \u6700\u4f73\u5b9e\u8df5 Demo&lt;\/title&gt;\n  &lt;style&gt;\n    .container { display: flex; flex-wrap: wrap; gap: 20px; padding: 20px; }\n    .chart-box { width: 450px; height: 350px; }\n  &lt;\/style&gt;\n&lt;\/head&gt;\n&lt;body&gt;\n  &lt;div class=&quot;container&quot;&gt;\n    &lt;div id=&quot;gauge&quot; class=&quot;chart-box&quot;&gt;&lt;\/div&gt;\n    &lt;div id=&quot;radar&quot; class=&quot;chart-box&quot;&gt;&lt;\/div&gt;\n    &lt;div id=&quot;line&quot; class=&quot;chart-box&quot;&gt;&lt;\/div&gt;\n  &lt;\/div&gt;\n\n  &lt;script src=&quot;https:\/\/cdn.jsdelivr.net\/npm\/echarts@5.5.0\/dist\/echarts.min.js&quot;&gt;&lt;\/script&gt;\n  &lt;script&gt;\n    \/\/ --- \u4eea\u8868\u76d8 ---\n    const gaugeChart = echarts.init(document.getElementById('gauge'), null, { renderer: 'canvas' });\n    gaugeChart.setOption({\n      series: [{\n        type: 'gauge',\n        startAngle: 220, endAngle: -40,\n        axisLine: { lineStyle: { width: 20, color: [[0.3,'#67e0e3'],[0.7,'#37a2da'],[1,'#fd666d']] }},\n        pointer: { length: '60%', width: 8, itemStyle: { color: 'auto' }},\n        detail: { valueAnimation: true, formatter: '{value}%', fontSize: 24, offsetCenter: [0,'40%'] },\n        title: { offsetCenter: [0,'65%'], fontSize: 14, color: '#999' },\n        data: [{ value: 72, name: 'CPU \u4f7f\u7528\u7387' }]\n      }]\n    });\n\n    \/\/ --- \u96f7\u8fbe\u56fe ---\n    const radarChart = echarts.init(document.getElementById('radar'), null, { renderer: 'canvas' });\n    radarChart.setOption({\n      radar: {\n        indicator: [\n          { name: '\u6027\u80fd', max: 100 }, { name: '\u751f\u6001', max: 100 },\n          { name: '\u5b66\u4e60\u66f2\u7ebf', max: 100 }, { name: '\u4f01\u4e1a\u91c7\u7528', max: 100 },\n          { name: '\u793e\u533a\u6d3b\u8dc3', max: 100 }\n        ],\n        shape: 'polygon',\n        splitArea: { areaStyle: { color: ['rgba(64,158,255,0.05)','rgba(64,158,255,0.1)'] }}\n      },\n      series: [{\n        type: 'radar',\n        data: [\n          { value: [92,85,40,88,90], name: 'React', areaStyle: { opacity: 0.15 }, itemStyle: { color: '#409EFF' }},\n          { value: [88,70,60,65,78], name: 'Vue', areaStyle: { opacity: 0.15 }, itemStyle: { color: '#67C23A' }}\n        ]\n      }]\n    });\n\n    \/\/ --- \u6e10\u8fdb\u5f0f\u6298\u7ebf\u56fe\uff08\u6a21\u62df\u5927\u6570\u636e\uff09 ---\n    const lineChart = echarts.init(document.getElementById('line'), null, { renderer: 'canvas' });\n    const data = [];\n    for (let i = 0; i &lt; 50000; i++) {\n      data.push([i, Math.sin(i \/ 500) * 50 + Math.random() * 10]);\n    }\n    lineChart.setOption({\n      xAxis: { type: 'value' },\n      yAxis: { type: 'value' },\n      dataZoom: [{ type: 'inside' }],\n      series: [{\n        type: 'line',\n        data: data,\n        sampling: 'lttb',\n        large: true,\n        largeThreshold: 5000,\n        progressive: 400,\n        showSymbol: false,\n        lineStyle: { width: 1 }\n      }]\n    });\n\n    \/\/ --- \u6a21\u62df\u5b9e\u65f6\u66f4\u65b0\uff08\u589e\u91cf setOption\uff09 ---\n    let tick = 50000;\n    setInterval(() =&gt; {\n      tick++;\n      gaugeChart.setOption({\n        series: [{ data: [{ value: Math.round(40 + Math.random() * 50), name: 'CPU \u4f7f\u7528\u7387' }] }]\n      });\n    }, 2000);\n\n    \/\/ --- resize ---\n    window.addEventListener('resize', () =&gt; {\n      gaugeChart.resize();\n      radarChart.resize();\n      lineChart.resize();\n    });\n  &lt;\/script&gt;\n&lt;\/body&gt;\n&lt;\/html&gt;<\/code><\/pre>\n<p>\u590d\u5236\u8fd9\u6bb5\u4ee3\u7801\u5230\u4e00\u4e2a HTML \u6587\u4ef6\u91cc\uff0c\u76f4\u63a5\u7528\u6d4f\u89c8\u5668\u6253\u5f00\u5c31\u80fd\u770b\u5230\u4e09\u4e2a\u56fe\u8868\u540c\u65f6\u8fd0\u884c\u2014\u2014\u4eea\u8868\u76d8\u6bcf 2 \u79d2\u968f\u673a\u66f4\u65b0\u3001\u96f7\u8fbe\u56fe\u5c55\u793a React vs Vue \u591a\u7ef4\u5bf9\u6bd4\u3001\u6298\u7ebf\u56fe\u6709 5 \u4e07\u4e2a\u6570\u636e\u70b9\u4f46\u4f9d\u7136\u4e1d\u6ed1\u3002<\/p>\n<hr>\n<h2>\u5e38\u89c1\u95ee\u9898<\/h2>\n<p><strong>Q: ECharts 6.x \u548c 5.x \u5dee\u522b\u5927\u5417\uff1f\u9700\u8981\u5347\u7ea7\u5417\uff1f<\/strong><\/p>\n<p>A: ECharts 6.1.0\uff082025 \u5e74 5 \u6708\u53d1\u5e03\uff09\u4e3b\u8981\u589e\u5f3a\u4e86\u5750\u6807\u8f74\u7cbe\u5ea6\u3001\u96f7\u8fbe\u56fe <code>clockwise<\/code> \u9009\u9879\u3001VisualMap \u591a\u7cfb\u5217\u6620\u5c04\u7b49\u529f\u80fd\u3002API \u5c42\u9762\u5411\u4e0b\u517c\u5bb9\uff0c5.x \u7684\u914d\u7f6e\u57fa\u672c\u90fd\u80fd\u76f4\u63a5\u8dd1\u3002\u5982\u679c\u4f60\u7684\u9879\u76ee\u5728 5.x \u4e0a\u8dd1\u5f97\u597d\u597d\u7684\uff0c\u6ca1\u6709\u65b0\u529f\u80fd\u9700\u6c42\uff0c\u6ca1\u5fc5\u8981\u6025\u7740\u5347\u3002<\/p>\n<p><strong>Q: gauge \u4eea\u8868\u76d8\u80fd\u4e0d\u80fd\u505a\u534a\u5706\u7684\uff1f<\/strong><\/p>\n<p>A: \u53ef\u4ee5\u3002\u8bbe <code>startAngle: 180, endAngle: 0<\/code> \u5c31\u884c\u3002\u4f46\u8981\u6ce8\u610f\u540c\u6b65\u8c03\u6574 <code>splitNumber<\/code> \u548c <code>axisLabel.distance<\/code>\uff0c\u4e0d\u7136\u6807\u7b7e\u4f1a\u6324\u6210\u4e00\u56e2\u3002\u534a\u5706 gauge \u7684 <code>detail<\/code> \u4f4d\u7f6e\u5efa\u8bae\u6539\u6210 <code>[0, '50%']<\/code> \u4ee5\u4fdd\u6301\u89c6\u89c9\u5c45\u4e2d\u3002<\/p>\n<p><strong>Q: radar \u56fe\u7684\u6307\u6807\u592a\u591a\uff08\u8d85\u8fc7 8 \u4e2a\uff09\u4f1a\u600e\u6837\uff1f<\/strong><\/p>\n<p>A: \u89c6\u89c9\u4e0a\u4f1a\u5f88\u62e5\u6324\uff0c\u6807\u7b7e\u91cd\u53e0\u4e25\u91cd\u3002\u8d85\u8fc7 6 \u4e2a\u6307\u6807\u5efa\u8bae\u6362\u7528\u5176\u4ed6\u56fe\u8868\u7c7b\u578b\u2014\u2014\u6bd4\u5982\u5e73\u884c\u5750\u6807\u7cfb\uff08parallel\uff09\u6216\u8005\u5206\u9762\u96f7\u8fbe\u56fe\uff08\u591a\u4e2a\u5c0f radar\uff09\u3002ECharts \u7684 parallel \u7ec4\u4ef6\u5929\u751f\u9002\u5408\u9ad8\u7ef4\u6570\u636e\u5bf9\u6bd4\u3002<\/p>\n<p><strong>Q: \u751f\u4ea7\u73af\u5883\u600e\u4e48\u76d1\u63a7 ECharts \u7684\u6e32\u67d3\u6027\u80fd\uff1f<\/strong><\/p>\n<p>A: \u7528 Chrome DevTools \u7684 Performance \u9762\u677f\u5f55\u5236\u4e00\u6bb5\u64cd\u4f5c\uff0c\u770b <code>Recalculate Style<\/code> \u548c <code>Paint<\/code> \u7684\u8017\u65f6\u3002ECharts \u5185\u90e8\u4e5f\u53ef\u4ee5\u901a\u8fc7 <code>chart.getOption()<\/code> \u786e\u8ba4\u5f53\u524d\u751f\u6548\u7684\u914d\u7f6e\u662f\u5426\u7b26\u5408\u9884\u671f\u3002\u5982\u679c\u53d1\u73b0 setOption \u8017\u65f6\u8d85\u8fc7 100ms\uff0c\u5148\u68c0\u67e5\u662f\u4e0d\u662f\u4f20\u4e86\u4e0d\u5fc5\u8981\u7684\u5b8c\u6574\u914d\u7f6e\u3002<br \/><img decoding=\"async\" width=\"723\" height=\"351\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/bVdoHcG\" alt=\"beeaa00ee37c5db0e2fb2c5c5efe4f29.png\" title=\"beeaa00ee37c5db0e2fb2c5c5efe4f29.png\" loading=\"lazy\"><\/p>\n<p>ECharts \u8fd9\u4e2a\u5e93\uff0c\u8bf4\u767d\u4e86\u5c31\u662f&#8221;\u80fd\u7528&#8221;\u548c&#8221;\u7528\u597d&#8221;\u4e4b\u95f4\u5dee\u4e86\u4e00\u6761\u6c9f\u3002\u914d\u7f6e\u9879\u51e0\u767e\u4e2a\uff0c\u5927\u90e8\u5206\u4eba\u53ea\u7528\u5230\u4e86 20%\u3002\u5269\u4e0b\u7684 80% \u4e0d\u662f\u82b1\u54e8\u7684\u88c5\u9970\u2014\u2014\u662f\u51b3\u5b9a\u4f60\u7684\u56fe\u8868\u5728\u751f\u4ea7\u73af\u5883\u91cc\u625b\u4e0d\u625b\u5f97\u4f4f\u7684\u5173\u952e\u3002\u4f60\u8eab\u8fb9\u6709\u524d\u7aef\u540c\u4e8b\u5728\u7528 ECharts \u505a\u5927\u5c4f\u7684\uff0c\u8fd9\u7bc7\u53ef\u4ee5\u76f4\u63a5\u7529\u7ed9\u4ed6\uff0c\u7701\u4ed6\u8e29\u4e00\u904d\u3002\u4e0b\u7bc7\u6253\u7b97\u62c6\u89e3 ECharts \u81ea\u5b9a\u4e49\u4e3b\u9898\u548c\u6697\u9ed1\u6a21\u5f0f\u9002\u914d\u7684\u5b9e\u6218\u65b9\u6848\uff0c\u611f\u5174\u8da3\u7684\u5173\u6ce8\u4e00\u4e0b\u3002\u7801\u54e5\u4e0d\u9760\u6807\u9898\u515a\u51b2\u6d41\u91cf\uff0c\u6bcf\u7bc7\u90fd\u662f\u81ea\u5df1\u78e8\u7684\uff0c\u628a\u53f7\u8bbe\u4e3a\u661f\u6807\uff0c\u4f60\u60f3\u770b\u7684\u65f6\u5019\u5c31\u8fd8\u5728\u3002<\/p>\n<p><a href=\"https:\/\/segmentfault.com\/a\/1190000048049049\">https:\/\/segmentfault.com\/a\/1190000048049049<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4f60\u6709\u6ca1\u6709\u9047\u5230\u8fc7\u8fd9\u79cd\u60c5\u51b5\u2014\u2014 \u6570\u636e\u91cf\u624d\u51e0\u4e07\u6761\uff0cECharts \u56fe\u8868\u6e32\u67d3\u5c31\u8981 3 \u79d2\u4ee5\u4e0a\uff0c\u7528\u6237\u62d6\u62fd dataZoo [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[4],"tags":[],"class_list":["post-10021409","post","type-post","status-publish","format-standard","hentry","category-share"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts\/10021409","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=10021409"}],"version-history":[{"count":0,"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts\/10021409\/revisions"}],"wp:attachment":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=10021409"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=10021409"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=10021409"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}