| <?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom"><generator uri="http://jekyllrb.com" version="3.4.0">Jekyll</generator><link href="http://echarts.baidu.com/blog/feed.xml" rel="self" type="application/atom+xml" /><link href="http://echarts.baidu.com/blog/" rel="alternate" type="text/html" /><updated>2017-06-14T15:17:26+08:00</updated><id>http://echarts.baidu.com/blog/</id><author><name>{"dingding"=>{"name"=>"王俊婷", "title"=>"ECharts 设计师", "web"=>"https://www.behance.net/wjtjiayouac8aa", "image"=>"http://echarts.baidu.com/images/people/王俊婷.png", "desc"=>"喜欢神游的女子一枚,又名王叮叮"}}</name></author><entry><title>在 ECharts GL 中绘制三维地图</title><link href="http://echarts.baidu.com/blog/2017/06/14/building-realistic-map-with-echarts-gl.html" rel="alternate" type="text/html" title="在 ECharts GL 中绘制三维地图" /><published>2017-06-14T00:00:00+08:00</published><updated>2017-06-14T00:00:00+08:00</updated><id>http://echarts.baidu.com/blog/2017/06/14/building-realistic-map-with-echarts-gl</id><content type="html" xml:base="http://echarts.baidu.com/blog/2017/06/14/building-realistic-map-with-echarts-gl.html"><p>ECharts 前段时间发布了超亮眼的 GL,相对于之前已经圈粉无数的 ECharst-X 而言,ECharst GL更是帅到爆,无论是性能、颜值、类型都有了巨大的飞跃。但是对于小编这样的设计师来说是不是更易上手呢?答案是肯定的,我们除了能够根据数据画出诸如三维地图等三维的可视化图之外,只需要在项目中加入几个简单的配置项,就能配制出想要的风格的高质量画面效果。</p> |
| |
| <p>这篇教程就希望通过在 Gallery 里绘制一个有丰富的光效、阴影的写实风格的三维地图的例子,简单介绍一些ECharts GL与画质相关的配置项,最终效果见 <a href="http://gallery.echartsjs.com/editor.html?c=xBkY4tpszb">http://gallery.echartsjs.com/editor.html?c=xBkY4tpszb</a>(下图为最后的效果)。涉及到太高深专业的算法、代码、什么什么的小设计师我实在是不会,所以这个仅仅能当 GL 入门级教程使用哦~</p> |
| |
| <p><img src="http://echarts.baidu.com/blog/images/post/2017-06-14/banner.png" alt="" /></p> |
| |
| <h2 id="绘制一个基础的三维地图">绘制一个基础的三维地图</h2> |
| |
| <p>首先我们在 Gallery 中用 ECharts GL 画一个基础的三维地图。注意因为 GL 是 ECharts 的一个扩展,所以我们需要在 Gallery 中额外引入 GL 的脚本文件。 |
| 「引入文件」只需要在 Gallery中新建作品,然后在「脚本」的配置中加入这行地址就行了。</p> |
| |
| <p><a href="http://echarts.baidu.com/resource/echarts-gl-latest/dist/echarts-gl.min.js">http://echarts.baidu.com/resource/echarts-gl-latest/dist/echarts-gl.min.js</a></p> |
| |
| <p>如果要绘制世界地图的话还需要引入上面「常用脚本」的世界地图文件。</p> |
| |
| <p><img src="http://echarts.baidu.com/blog/images/post/2017-06-14/scripts.png" alt="" /></p> |
| |
| <p>做好准备工作后我们就可以开始画一个三维的世界地图了,GL 中画三维地图的配置项跟画普通的二维地图一样,只是系列名称从原来的<code class="highlighter-rouge">map</code>改成<code class="highlighter-rouge">map3D</code>。</p> |
| |
| <p>我们先用下面的最基础配置项,基于引入的脚本,生成一个最基础的三维地图系列。</p> |
| |
| <div class="language-js highlighter-rouge"><pre class="highlight"><code><span class="nx">option</span> <span class="o">=</span> <span class="p">{</span> |
| <span class="na">series</span><span class="p">:</span> <span class="p">[{</span> |
| <span class="na">type</span><span class="p">:</span> <span class="s1">'map3D'</span><span class="p">,</span> |
| <span class="na">map</span><span class="p">:</span> <span class="s1">'world'</span> |
| <span class="p">}]</span> |
| <span class="p">};</span> |
| </code></pre> |
| </div> |
| |
| <p>是不是很简单,当然画出来的效果也是非常基础和简陋的。</p> |
| |
| <p><img src="http://echarts.baidu.com/blog/images/post/2017-06-14/map3D-basic.png" alt="" /></p> |
| |
| <p>接下来就我们需要做的就是一步一步的添加光照、阴影、后期的配置项把这个三维地图画得更漂亮。</p> |
| |
| <h2 id="添加更丰富的灯光">添加更丰富的灯光</h2> |
| |
| <p>GL 中大部分组件都支持灯光的配置,这些灯光会影响到组件中的所有图形,灯光的配置项需要统一在组件<code class="highlighter-rouge">light</code>属性下设置。</p> |
| |
| <div class="language-js highlighter-rouge"><pre class="highlight"><code><span class="nx">light</span><span class="err">:</span> <span class="p">{</span> |
| <span class="nl">main</span><span class="p">:</span> <span class="p">{</span> |
| <span class="nl">intensity</span><span class="p">:</span> <span class="mi">1</span> |
| <span class="p">},</span> |
| <span class="nx">ambient</span><span class="err">:</span> <span class="p">{</span> |
| <span class="nl">intensity</span><span class="p">:</span> <span class="mi">0</span> |
| <span class="p">}</span> |
| <span class="p">}</span> |
| </code></pre> |
| </div> |
| |
| <p>通常情况下组件中默认会有一个主光源<code class="highlighter-rouge">main</code>和一个全局的环境光<code class="highlighter-rouge">ambient</code>。主光源起到了主要的照明作用,可以让我们刚才画出来的三维地图产生基础的明暗对比,从而使图形产生真实的立体感。全局的环境光可以为整个场景提供全局照亮和统一材质的效果。(添加光照效果如下图)</p> |
| |
| <p><img src="http://echarts.baidu.com/blog/images/post/2017-06-14/map3D-light.png" alt="" /></p> |
| |
| <p>我们可以通过<code class="highlighter-rouge">intensity</code>属性设置不同光源的强度。例如在上面的代码中我们将主光源的强度设成<code class="highlighter-rouge">2</code>,环境光源的强度设成<code class="highlighter-rouge">0</code>后可以得到更加强烈的明暗对比。</p> |
| |
| <p><img src="http://echarts.baidu.com/blog/images/post/2017-06-14/map3D-light-high-contrast.png" alt="" /></p> |
| |
| <p>默认的环境光只是单纯的对所有图形都加上一个固定的亮度,所以会显得很平淡,如果把主光源去掉(<code class="highlighter-rouge">intensity</code>设为<code class="highlighter-rouge">0</code>)的话,整个地图场景会变成灰色。所以为了更丰富的光照效果,我们可以使用 GL 提供的更为强大的<code class="highlighter-rouge">ambientCubemap</code>作为环境光源。</p> |
| |
| <p><code class="highlighter-rouge">ambientCubemap</code>是指使用一张全景贴图作为环境光源。一般全景的环境光贴图大概是下面这样。</p> |
| |
| <p><img src="http://echarts.baidu.com/blog/images/post/2017-06-14/hdr.png" alt="" /></p> |
| |
| <p>大家使用手机的全景模式中就可以拍出类似的全景照片。不过小编建议去寻找专业的 <a href="https://zh.wikipedia.org/zh-hans/%E9%AB%98%E5%8A%A8%E6%80%81%E8%8C%83%E5%9B%B4%E6%88%90%E5%83%8F">HDR</a> 格式的全景图资源。这里推荐一个有不少免费的HDR全景图资源的网站 <a href="http://www.hdrlabs.com/sibl/archive.html">http://www.hdrlabs.com/sibl/archive.html</a>。</p> |
| |
| <p>找到合适的全景图片后,我们可以在 Gallery 的<code class="highlighter-rouge">导入数据</code>中上传该图片。</p> |
| |
| <p><img src="http://echarts.baidu.com/blog/images/post/2017-06-14/asset-hdr.png" alt="" /></p> |
| |
| <p>得到在 Gallery 上该图片地址链接后插入到<code class="highlighter-rouge">ambientCubemap</code>的<code class="highlighter-rouge">texture</code>属性中。</p> |
| <div class="language-js highlighter-rouge"><pre class="highlight"><code><span class="nx">light</span><span class="err">:</span> <span class="p">{</span> |
| <span class="nl">main</span><span class="p">:</span> <span class="p">{</span> |
| <span class="nl">intensity</span><span class="p">:</span> <span class="mi">1</span> |
| <span class="p">},</span> |
| <span class="nx">ambient</span><span class="err">:</span> <span class="p">{</span> |
| <span class="nl">intensity</span><span class="p">:</span> <span class="mi">0</span> |
| <span class="p">},</span> |
| <span class="nx">ambientCubemap</span><span class="err">:</span> <span class="p">{</span> |
| <span class="nl">diffuseIntensity</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span> |
| <span class="nx">texture</span><span class="err">:</span> <span class="s1">'/asset/get/s/data-1497251035660-HkVJTnsMW.hdr'</span> |
| <span class="p">}</span> |
| <span class="p">}</span> |
| </code></pre> |
| </div> |
| <p>设置了<code class="highlighter-rouge">texture</code>属性后 GL 就会自动启用环境光贴图作为环境光源。</p> |
| |
| <p><img src="http://echarts.baidu.com/blog/images/post/2017-06-14/map3D-ambientcubemap.png" alt="" /></p> |
| |
| <p>因为全景贴图的每个像素都会被计算到光照里,所以相比普通的环境光,使用环境光贴图会让整个光照会显得更真实和丰富。</p> |
| |
| <p>为了得到更真实的环境光效果,注意此处建议使用<code class="highlighter-rouge">.hdr</code>格式的图片,因为 <a href="https://zh.wikipedia.org/zh-hans/%E9%AB%98%E5%8A%A8%E6%80%81%E8%8C%83%E5%9B%B4%E6%88%90%E5%83%8F">HDR</a> 也就是高动态范围图像,它比其他格式的图像有更大亮度的数据存储。对比一下同一张图片<code class="highlighter-rouge">HDR</code>和<code class="highlighter-rouge">PNG</code>格式照亮的不同效果。</p> |
| |
| <p><img src="http://echarts.baidu.com/blog/images/post/2017-06-14/map3D-hdr-compare.png" alt="" /></p> |
| |
| <h2 id="添加阴影">添加阴影</h2> |
| |
| <p>有光的地方就会有阴影,阴影给了光照更多的层次,失去了阴影的光照是没有灵魂的,是平淡乏味的。</p> |
| |
| <p>在 GL 中可以简单的加上<code class="highlighter-rouge">shadow: true</code>为主光源添加阴影。同时为了让三维地图有一种放在地面上的立体模型的感觉,我们再显示一个地面<code class="highlighter-rouge">groundPlane</code>。</p> |
| |
| <div class="language-js highlighter-rouge"><pre class="highlight"><code><span class="nx">light</span><span class="err">:</span> <span class="p">{</span> |
| <span class="nl">main</span><span class="p">:</span> <span class="p">{</span> |
| <span class="nl">intensity</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span> |
| <span class="nx">shadow</span><span class="err">:</span> <span class="kc">true</span> |
| <span class="p">},</span> |
| <span class="nx">ambient</span><span class="err">:</span> <span class="p">{</span> |
| <span class="nl">intensity</span><span class="p">:</span> <span class="mi">0</span> |
| <span class="p">},</span> |
| <span class="nx">ambientCubemap</span><span class="err">:</span> <span class="p">{</span> |
| <span class="nl">diffuseIntensity</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span> |
| <span class="nx">texture</span><span class="err">:</span> <span class="s1">'/asset/get/s/data-1491896094618-H1DmP-5px.hdr'</span> |
| <span class="p">}</span> |
| <span class="p">},</span> |
| <span class="nx">groundPlane</span><span class="err">:</span> <span class="p">{</span> |
| <span class="nl">show</span><span class="p">:</span> <span class="kc">true</span> |
| <span class="p">}</span> |
| </code></pre> |
| </div> |
| |
| <p><img src="http://echarts.baidu.com/blog/images/post/2017-06-14/map3D-shadow.png" alt="" /></p> |
| |
| <p>通过阴影还可以更容易得感受到光照的方向,我们可以通过设置主光源<code class="highlighter-rouge">alpha</code>、<code class="highlighter-rouge">beta</code>两个属性设置不同的光照角度,来查看阴影的变化。</p> |
| |
| <div class="language-js highlighter-rouge"><pre class="highlight"><code><span class="nx">main</span><span class="err">:</span> <span class="p">{</span> |
| <span class="nl">intensity</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span> |
| <span class="nx">shadow</span><span class="err">:</span> <span class="kc">true</span><span class="p">,</span> |
| <span class="nx">alpha</span><span class="err">:</span> <span class="mi">150</span><span class="p">,</span> |
| <span class="nx">beta</span><span class="err">:</span> <span class="mi">70</span> |
| <span class="p">}</span> |
| </code></pre> |
| </div> |
| |
| <p><img src="http://echarts.baidu.com/blog/images/post/2017-06-14/map3D-shadow-long.png" alt="" /></p> |
| |
| <p>这样就可以实现之前设计圈非常流行的一种长阴影的风格。</p> |
| |
| <h2 id="更丰富的颜色">更丰富的颜色</h2> |
| |
| <p>到这里我们得到的效果跟最初那个简陋的画面已经是天壤之别了,小编作为一个设计师是很钟情于白模的效果的,但是如果你手里有一份数据的话更是锦上添花。 |
| 数据的上传和转换可以通过echarts提供的表格数据转换工具实现, |
| <a href="http://echarts.baidu.com/spreadsheet.html">http://echarts.baidu.com/spreadsheet.html</a>,数据部分内容不在此多述。如果暂时没有现成数据,可以直接先复制教程实例中的数据,见左侧代码区域<code class="highlighter-rouge">var regionData = [{……}];</code>内的全部内容,直接复制粘贴即可进行之后操作。</p> |
| |
| <p><img src="http://echarts.baidu.com/blog/images/post/2017-06-14/data.png" width="500px" alt="" /></p> |
| |
| <p>将这份数据导入并写入配置项里,</p> |
| |
| <p><img src="http://echarts.baidu.com/blog/images/post/2017-06-14/data-assign.png" width="430px" alt="" /></p> |
| |
| <p>接下来,我们可以使用 ECharts 中视觉映射「visualMap」组件将地图中的每块区域赋予不同的颜色。</p> |
| |
| <p>在 ECharts GL 中使用 visualMap 和在ECharts中并没有任何的不同:</p> |
| |
| <div class="language-js highlighter-rouge"><pre class="highlight"><code><span class="nx">visualMap</span><span class="err">:</span> <span class="p">{</span> |
| <span class="nl">show</span><span class="p">:</span> <span class="kc">false</span><span class="p">,</span> |
| <span class="nx">min</span><span class="err">:</span> <span class="mi">0</span><span class="p">,</span> |
| <span class="nx">max</span><span class="err">:</span> <span class="mi">15</span><span class="p">,</span> |
| <span class="nx">inRange</span><span class="err">:</span> <span class="p">{</span> |
| <span class="nl">color</span><span class="p">:</span> <span class="p">[</span><span class="s1">'#313695'</span><span class="p">,</span> <span class="s1">'#4575b4'</span><span class="p">,</span> <span class="s1">'#74add1'</span><span class="p">,</span> <span class="s1">'#abd9e9'</span><span class="p">,</span> <span class="s1">'#e0f3f8'</span><span class="p">,</span> <span class="s1">'#ffffbf'</span><span class="p">,</span> <span class="s1">'#fee090'</span><span class="p">,</span> <span class="s1">'#fdae61'</span><span class="p">,</span> <span class="s1">'#f46d43'</span><span class="p">,</span> <span class="s1">'#d73027'</span><span class="p">,</span> <span class="s1">'#a50026'</span><span class="p">]</span> |
| <span class="p">}</span> |
| <span class="p">}</span> |
| </code></pre> |
| </div> |
| |
| <p>就是这样子每个国家根据不同数据就呈现出不同的颜色啦。</p> |
| |
| <p><img src="http://echarts.baidu.com/blog/images/post/2017-06-14/map3D-data.png" alt="" /></p> |
| |
| <h2 id="后期处理">后期处理</h2> |
| |
| <p>看到后期可能大家第一个想到的就是使用 PS 调色,小编这次主要用到的确实是调色。但其实GL 中除了调色之外,还有例如景深 、描边等诸多的后期效果能让整个画面呈现出你需要的效果,大家之后可以大胆的尝试。</p> |
| |
| <p>不知道大家是否能感受到其实此时得到的图片整体明度偏暗,色相偏蓝。就如我们在拍完照片后发现色调和曝光不理想需要再次调整图片一样,我们也需要对这张的画面进行后期处理和调色。</p> |
| |
| <p>后期处理的配置项都是在组件的<code class="highlighter-rouge">postEffect</code>下。首先可以通过 enable 属性开启。</p> |
| |
| <div class="language-js highlighter-rouge"><pre class="highlight"><code><span class="nx">postEffect</span><span class="err">:</span> <span class="p">{</span> |
| <span class="nl">enable</span><span class="p">:</span> <span class="kc">true</span> |
| <span class="p">}</span> |
| </code></pre> |
| </div> |
| |
| <p>开启后 GL 会自动对整个画面调整曝光到合适的颜色。</p> |
| |
| <p>当然如果这个画面并不能让我们满意的话,我们还可以通过<code class="highlighter-rouge">postEffect</code>下的<code class="highlighter-rouge">colorCorrection</code>配置项去手动的调整颜色。<code class="highlighter-rouge">colorCorrection</code>下有常见的曝光<code class="highlighter-rouge">exposure</code>、亮度<code class="highlighter-rouge">brightness</code>、对比度<code class="highlighter-rouge">contrast</code>和饱和度<code class="highlighter-rouge">saturation</code>选项。</p> |
| |
| <p>但是这次小编要教大家使用这里面更强大的颜色查找表功能<code class="highlighter-rouge">lookupTexture</code>。这个功能可以让我们在 PS 等自己用着顺手的图像处理软件里处理好图片之后再到 GL 里复现我们在 PS 里调整的颜色曲线。</p> |
| |
| <p>小编给大家提供了一张初始的颜色查找表,大家把下面这张查找表的图片下载下来后和你的作品截图一起放入 Photoshop 中(可以把作品截图拖入查找表图层的上方,注意需要保持查找表大小不变,作品截图是为了让我们直观的预览调整的效果,调到满意之后,删除作品图层,只保存查找表,之后在GL中载入查找表,查找表的颜色映射会直接在GL中复现)。</p> |
| |
| <p><img src="http://echarts.baidu.com/blog/images/post/2017-06-14/lookup.png" width="300px" alt="" /></p> |
| |
| <p><img src="http://echarts.baidu.com/blog/images/post/2017-06-14/ps.png" alt="" /></p> |
| |
| <p>点击左下角<code class="highlighter-rouge">创建新的填充或调整工具</code>来选择自己需要调整的配置项,此时两个图层是可以同时调整的,这里可以自由调整各项参数来实现自己想要的效果。我在此使用的是<code class="highlighter-rouge">颜色查找</code>下自带的<code class="highlighter-rouge">Candlelight.cube</code>将图片调整成了一种蜡烛光照的复古风格,又调整了亮度和对比度使其更清晰。</p> |
| |
| <p><img src="http://echarts.baidu.com/blog/images/post/2017-06-14/ps-adjusted.png" alt="" /></p> |
| |
| <p><img src="http://echarts.baidu.com/blog/images/post/2017-06-14/ps-adjusted2.png" alt="" /></p> |
| |
| <p>调整完成之后,隐藏作品截图的图层,只需保存颜色查找表(如下图)</p> |
| |
| <p><img src="http://echarts.baidu.com/blog/images/post/2017-06-14/lookup-adjusted.png" width="300px" alt="" /></p> |
| |
| <p><img src="http://echarts.baidu.com/blog/images/post/2017-06-14/asset-lookup.png" alt="" /></p> |
| |
| <p>将该图在 Gallery 内上传数据,得到在 Gallery 上该图片地址链接后插入到<code class="highlighter-rouge">colorCorrection</code>的 <code class="highlighter-rouge">lookupTexture</code>中即可。</p> |
| |
| <p><img src="http://echarts.baidu.com/blog/images/post/2017-06-14/code-lookup.png" alt="" /></p> |
| |
| <p>到此,在 ECharts GL 中配置一个三维地图的步骤就完成啦,还想解锁更多 GL 技能的话, 可以直接去 ECharts 官网查看 GL 超多酷炫的实例,或者去查看GL的配置项手册 <a href="http://echarts.baidu.com/option-gl.html">http://echarts.baidu.com/option-gl.html</a> 尽情的尝试吧~</p> |
| |
| <p><img src="http://echarts.baidu.com/blog/images/post/2017-06-14/banner.png" alt="" /></p> |
| |
| <h2 id="总结">总结</h2> |
| |
| <p>本文我们介绍了如何在 ECharts GL 中配置出一张好看的写实风格三维地图。小编要偷偷地告诉你,用 ECharts GL 生成的效果图你还可以直接用来做图片素材哦,如果你还在为 PPT 或者自己的设计作品找不到合适的配图素材发愁的话,快来试试直接在 Gallery 里用 ECharts GL 直接生成一张吧。</p></content><author><name>dingding</name></author><category term="GL" /><category term="教程" /><summary>ECharts 前段时间发布了超亮眼的 GL,相对于之前已经圈粉无数的 ECharst-X 而言,ECharst GL更是帅到爆,无论是性能、颜值、类型都有了巨大的飞跃。但是对于小编这样的设计师来说是不是更易上手呢?答案是肯定的,我们除了能够根据数据画出诸如三维地图等三维的可视化图之外,只需要在项目中加入几个简单的配置项,就能配制出想要的风格的高质量画面效果。</summary><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://echarts.baidu.com/blog{"feature"=>"post/2017-06-14/banner.png"}" /></entry><entry><title>ECharts v3.6 发布:自定义系列、极坐标柱状图</title><link href="http://echarts.baidu.com/blog/2017/05/25/new-release.html" rel="alternate" type="text/html" title="ECharts v3.6 发布:自定义系列、极坐标柱状图" /><published>2017-05-25T00:00:00+08:00</published><updated>2017-05-25T00:00:00+08:00</updated><id>http://echarts.baidu.com/blog/2017/05/25/new-release</id><content type="html" xml:base="http://echarts.baidu.com/blog/2017/05/25/new-release.html"><p>在 ECharts 新发布的 <a href="https://github.com/ecomfe/echarts/releases/tag/3.6.0">3.6 版本</a>中,新增了 <a href="http://echarts.baidu.com/option.html#series-custom">自定义系列(custom series)</a>,能让用户定制渲染逻辑,从而在已有坐标系中创造新的图表。此外还有极坐标柱状图、自定义维度映射、dataZoom 等其他一些增强。</p> |
| |
| <h2 id="自定义系列">自定义系列</h2> |
| |
| <p>图表的类型多种多样,有些大众有些小众,echarts 难于内置得支持所有类型的图表。所以推出了 <a href="http://echarts.baidu.com/option.html#series-custom">自定义系列(custom series)</a>。</p> |
| |
| <p>自定义系列可以自定义系列中的图形元素渲染。从而能扩展出不同的图表。同时,echarts 会统一管理图形的创建删除、动画、与其他组件(如 <a href="http://echarts.baidu.com/option.html#dataZoom">dataZoom</a>、<a href="http://echarts.baidu.com/option.html#visualMap">visualMap</a>)的联动,使用户不必纠结这些细节。</p> |
| |
| <p><strong>例如,下面的例子使用 custom series 扩展出了 x-range 图:</strong></p> |
| <div class="ec-lazy" data-thumb="http://echarts.baidu.com/gallery/data/thumb/custom-profile.png" data-src="http://echarts.baidu.com/gallery/view.html?c=custom-profile&amp;edit=1&amp;reset=1" style="width: 100%; height: 300px"></div> |
| |
| <p>可以注意到,里面须用户自定义的渲染逻辑,在 <code class="highlighter-rouge">renderItem</code> 这个函数中,并不十分复杂。但是得到的功能是比较完备的。</p> |
| |
| <div class="language-js highlighter-rouge"><pre class="highlight"><code><span class="kd">var</span> <span class="nx">option</span> <span class="o">=</span> <span class="p">{</span> |
| <span class="p">...,</span> |
| <span class="na">series</span><span class="p">:</span> <span class="p">[{</span> |
| <span class="na">type</span><span class="p">:</span> <span class="s1">'custom'</span><span class="p">,</span> |
| <span class="na">renderItem</span><span class="p">:</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">params</span><span class="p">,</span> <span class="nx">api</span><span class="p">)</span> <span class="p">{</span> |
| <span class="kd">var</span> <span class="nx">categoryIndex</span> <span class="o">=</span> <span class="nx">api</span><span class="p">.</span><span class="nx">value</span><span class="p">(</span><span class="mi">0</span><span class="p">);</span> |
| <span class="kd">var</span> <span class="nx">start</span> <span class="o">=</span> <span class="nx">api</span><span class="p">.</span><span class="nx">coord</span><span class="p">([</span><span class="nx">api</span><span class="p">.</span><span class="nx">value</span><span class="p">(</span><span class="mi">1</span><span class="p">),</span> <span class="nx">categoryIndex</span><span class="p">]);</span> |
| <span class="kd">var</span> <span class="nx">end</span> <span class="o">=</span> <span class="nx">api</span><span class="p">.</span><span class="nx">coord</span><span class="p">([</span><span class="nx">api</span><span class="p">.</span><span class="nx">value</span><span class="p">(</span><span class="mi">2</span><span class="p">),</span> <span class="nx">categoryIndex</span><span class="p">]);</span> |
| <span class="kd">var</span> <span class="nx">height</span> <span class="o">=</span> <span class="nx">api</span><span class="p">.</span><span class="nx">size</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">])[</span><span class="mi">1</span><span class="p">]</span> <span class="o">*</span> <span class="mf">0.6</span><span class="p">;</span> |
| |
| <span class="k">return</span> <span class="p">{</span> |
| <span class="na">type</span><span class="p">:</span> <span class="s1">'rect'</span><span class="p">,</span> |
| <span class="na">shape</span><span class="p">:</span> <span class="nx">echarts</span><span class="p">.</span><span class="nx">graphic</span><span class="p">.</span><span class="nx">clipRectByRect</span><span class="p">({</span> |
| <span class="na">x</span><span class="p">:</span> <span class="nx">start</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> |
| <span class="na">y</span><span class="p">:</span> <span class="nx">start</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">-</span> <span class="nx">height</span> <span class="o">/</span> <span class="mi">2</span><span class="p">,</span> |
| <span class="na">width</span><span class="p">:</span> <span class="nx">end</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">-</span> <span class="nx">start</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> |
| <span class="na">height</span><span class="p">:</span> <span class="nx">height</span> |
| <span class="p">},</span> <span class="p">{</span> |
| <span class="na">x</span><span class="p">:</span> <span class="nx">params</span><span class="p">.</span><span class="nx">coordSys</span><span class="p">.</span><span class="nx">x</span><span class="p">,</span> |
| <span class="na">y</span><span class="p">:</span> <span class="nx">params</span><span class="p">.</span><span class="nx">coordSys</span><span class="p">.</span><span class="nx">y</span><span class="p">,</span> |
| <span class="na">width</span><span class="p">:</span> <span class="nx">params</span><span class="p">.</span><span class="nx">coordSys</span><span class="p">.</span><span class="nx">width</span><span class="p">,</span> |
| <span class="na">height</span><span class="p">:</span> <span class="nx">params</span><span class="p">.</span><span class="nx">coordSys</span><span class="p">.</span><span class="nx">height</span> |
| <span class="p">}),</span> |
| <span class="na">style</span><span class="p">:</span> <span class="nx">api</span><span class="p">.</span><span class="nx">style</span><span class="p">()</span> |
| <span class="p">};</span> |
| <span class="p">},</span> |
| <span class="na">data</span><span class="p">:</span> <span class="nx">data</span> |
| <span class="p">}]</span> |
| <span class="p">}</span> |
| </code></pre> |
| </div> |
| |
| <p><strong>下面的两个例子使用 custom series 扩展出了 error-chart 图:</strong></p> |
| <div class="ec-lazy" data-thumb="http://echarts.baidu.com/gallery/data/thumb/custom-error-bar.png" data-src="http://echarts.baidu.com/gallery/view.html?c=custom-error-bar&amp;edit=1&amp;reset=1" style="width: 100%; height: 300px"></div> |
| |
| <div class="ec-lazy" data-thumb="http://echarts.baidu.com/gallery/data/thumb/custom-error-scatter.png" data-src="http://echarts.baidu.com/gallery/view.html?c=custom-error-scatter&amp;edit=1&amp;reset=1" style="width: 100%; height: 400px"></div> |
| |
| <p><strong>下面是其他一些例子:</strong></p> |
| |
| <div class="ec-lazy" data-thumb="http://echarts.baidu.com/gallery/data/thumb/custom-bar-trend.png" data-src="http://echarts.baidu.com/gallery/view.html?c=custom-bar-trend&amp;edit=1&amp;reset=1" style="width: 100%; height: 300px"></div> |
| |
| <div class="ec-lazy" data-thumb="http://echarts.baidu.com/gallery/data/thumb/custom-profit.png" data-src="http://echarts.baidu.com/gallery/view.html?c=custom-profit&amp;edit=1&amp;reset=1" style="width: 100%; height: 300px"></div> |
| |
| <div class="ec-lazy" data-thumb="http://echarts.baidu.com/gallery/data/thumb/custom-hexbin.png" data-src="http://echarts.baidu.com/gallery/view.html?c=custom-hexbin&amp;edit=1&amp;reset=1" style="width: 100%; height: 500px"></div> |
| |
| <h2 id="极坐标柱状图">极坐标柱状图</h2> |
| |
| <p>极坐标中的柱状图,可以按径向排布或者切向排布。</p> |
| |
| <div class="ec-lazy" data-thumb="http://echarts.baidu.com/gallery/data/thumb/bar-polar-stack.png" data-src="http://echarts.baidu.com/gallery/view.html?c=bar-polar-stack&amp;edit=1&amp;reset=1" style="width: 100%; height: 300px"></div> |
| |
| <div class="ec-lazy" data-thumb="http://echarts.baidu.com/gallery/data/thumb/bar-polar-stack-radial.png" data-src="http://echarts.baidu.com/gallery/view.html?c=bar-polar-stack-radial&amp;edit=1&amp;reset=1" style="width: 100%; height: 300px"></div> |
| |
| <p>使用时,只需要将系列的 <code class="highlighter-rouge">coordinateSystem</code> 设置为 <code class="highlighter-rouge">'polar'</code>,将原先笛卡尔坐标系中使用的 <code class="highlighter-rouge">xAxis</code> 和 <code class="highlighter-rouge">yAxis</code> 替换成 <code class="highlighter-rouge">radiusAxis</code> 和 <code class="highlighter-rouge">angleAxis</code>,就能使用极坐标系的柱状图了。</p> |
| |
| <h2 id="其他">其他</h2> |
| |
| <p>此外,</p> |
| |
| <ul> |
| <li>支持了<a href="http://echarts.baidu.com/option.html#series-scatter.encode">encode</a> 设定,可以指定 <a href="http://echarts.baidu.com/option.html#series-scatter.data">data</a> 中哪些维度映射到坐标系中哪个轴,或者哪些维度在 <a href="http://echarts.baidu.com/option.html#tooltip">tooltip</a> 以及 <a href="http://echarts.baidu.com/option.html#series-scatter.label">label</a> 中显示。</li> |
| <li>支持了 <a href="http://echarts.baidu.com/option.html#series-scatter.dimensions">dimensions</a> 设定,能指定 <a href="http://echarts.baidu.com/option.html#series-scatter.data">data</a> 中每个维度的名称和类型。名称可以显示在默认 <a href="http://echarts.baidu.com/option.html#tooltip">tooltip</a> 中。</li> |
| <li><code class="highlighter-rouge">dataZoom</code> 组件进行了增强。比如,支持了『按住 <code class="highlighter-rouge">'ctrl'</code>/<code class="highlighter-rouge">'alt'</code>/<code class="highlighter-rouge">'shift'</code> 和滚轮时才能出发缩放平移』功能,避免和页面的滚动冲突(参见 <a href="http://echarts.baidu.com/option.html#dataZoom-inside.moveOnMouseMove">moveOnMouseMove</a> 和 <a href="http://echarts.baidu.com/option.html#dataZoom-inside.zoomOnMouseWheel">zoomOnMouseWheel</a>。另外支持了 <a href="http://echarts.baidu.com/option.html#dataZoom.minSpan">minSpan</a> 和 <a href="http://echarts.baidu.com/option.html#dataZoom.maxSpan">maxSpan</a> 等细节配置。</li> |
| </ul> |
| |
| <p>更多的升级信息,参见 <a href="http://echarts.baidu.com/changelog.html">changelog</a>。</p></content><author><name>{"dingding"=>{"name"=>"王俊婷", "title"=>"ECharts 设计师", "web"=>"https://www.behance.net/wjtjiayouac8aa", "image"=>"http://echarts.baidu.com/images/people/王俊婷.png", "desc"=>"喜欢神游的女子一枚,又名王叮叮"}}</name></author><category term="新版本" /><category term="扩展" /><category term="教程" /><summary>在 ECharts 新发布的 3.6 版本中,新增了 自定义系列(custom series),能让用户定制渲染逻辑,从而在已有坐标系中创造新的图表。此外还有极坐标柱状图、自定义维度映射、dataZoom 等其他一些增强。</summary><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://echarts.baidu.com/blog{"feature"=>"post/2017-05-25-banner.png"}" /></entry><entry><title>ECharts 统计扩展教程</title><link href="http://echarts.baidu.com/blog/2017/05/09/echarts-statistical-extension-tutorial.html" rel="alternate" type="text/html" title="ECharts 统计扩展教程" /><published>2017-05-09T00:00:00+08:00</published><updated>2017-05-09T00:00:00+08:00</updated><id>http://echarts.baidu.com/blog/2017/05/09/echarts-statistical-extension-tutorial</id><content type="html" xml:base="http://echarts.baidu.com/blog/2017/05/09/echarts-statistical-extension-tutorial.html"><h1 id="echarts-统计扩展教程">ECharts 统计扩展教程</h1> |
| |
| <p>你是否想了解一组样本数据的分布情况?你是否想根据用户的数值属性将用户分成不同的群体?你是否想预测两个变量的变化趋势?—— 什么?不需要?不要再违心了,小编已经听到来自你们内心深处的呐喊,今天就为大家推荐一款神器 —— <a href="https://github.com/ecomfe/echarts-stat/">ECharts 统计扩展</a>,这是一个用来进行数据分析的扩展工具,包含的功能有直方图、聚类、回归、以及常用的汇总统计。通过统计扩展和 <a href="http://echarts.baidu.com/">ECharts</a> 的结合,可以使大家方便地实现可视分析,也就是将数据分析的结果,通过可视化直观地呈现出来。下面我们就一起来学习一下这些功能。</p> |
| |
| <h2 id="首先引入-javascript-文件">首先引入 JavaScript 文件</h2> |
| |
| <p>如果大家不仅要对数据进行分析,还要将分析的结果呈现出来,那就需要在下载引入扩展文件的同时,下载引入 ECharts 文件。如下:</p> |
| |
| <div class="language-html highlighter-rouge"><pre class="highlight"><code><span class="nt">&lt;script </span><span class="na">src=</span><span class="s">"echarts.js"</span><span class="nt">&gt;&lt;/script&gt;</span> |
| <span class="nt">&lt;script </span><span class="na">src=</span><span class="s">"ecStat.js"</span><span class="nt">&gt;&lt;/script&gt;</span> |
| |
| <span class="nt">&lt;script&gt;</span> |
| <span class="c1">//具体可视分析的代码</span> |
| <span class="nt">&lt;/script&gt;</span> |
| </code></pre> |
| </div> |
| |
| <p>除此之外,还需要指定一个具有高度和宽度的 DOM 元素,作为图表的容器,用来放置将被绘制的图表。如:</p> |
| |
| <div class="language-html highlighter-rouge"><pre class="highlight"><code><span class="nt">&lt;div</span> <span class="na">id=</span><span class="s">"main"</span> <span class="na">style=</span><span class="s">"width=100%; height=100%"</span><span class="nt">&gt;&lt;/div&gt;</span> |
| </code></pre> |
| </div> |
| |
| <p>然后传入该 DOM 元素,初始化 ECharts 图表:</p> |
| |
| <div class="language-js highlighter-rouge"><pre class="highlight"><code><span class="kd">var</span> <span class="nx">chart</span> <span class="o">=</span> <span class="nx">echarts</span><span class="p">.</span><span class="nx">init</span><span class="p">(</span><span class="nb">document</span><span class="p">.</span><span class="nx">getElementById</span><span class="p">(</span><span class="s1">'main'</span><span class="p">));</span> |
| </code></pre> |
| </div> |
| <p>完成了上面的准备工作,下面将一一介绍统计扩展的功能。</p> |
| |
| <h2 id="直方图">直方图</h2> |
| |
| <p>直方图主要用来反映一组样本数据的分布情况,可以近似估计一个数值类变量的概率分布。直方图是一种特殊的柱状图,它的任意两个 bar 之间不允许有间隙,这是因为整个数轴范围被分割成了一个个连续的、相互邻接的小区间。这个分割过程就是由统计扩展做的,用户只需要传入一维的数据,如下:</p> |
| |
| <div class="language-js highlighter-rouge"><pre class="highlight"><code><span class="kd">var</span> <span class="nx">girth</span> <span class="o">=</span> <span class="p">[</span><span class="mf">8.3</span><span class="p">,</span> <span class="mf">8.6</span><span class="p">,</span> <span class="mf">8.8</span><span class="p">,</span> <span class="mf">10.5</span><span class="p">,</span> <span class="mf">10.7</span><span class="p">,</span> <span class="mf">10.8</span><span class="p">,</span> <span class="mf">11.0</span><span class="p">,</span> <span class="mf">11.0</span><span class="p">,</span> <span class="mf">11.1</span><span class="p">,</span> <span class="mf">11.2</span><span class="p">,</span> <span class="mf">11.3</span><span class="p">,</span> <span class="mf">11.4</span><span class="p">,</span> <span class="mf">11.4</span><span class="p">,</span> <span class="mf">11.7</span><span class="p">,</span> <span class="mf">12.0</span><span class="p">,</span> <span class="mf">12.9</span><span class="p">,</span> <span class="mf">12.9</span><span class="p">,</span> <span class="mf">13.3</span><span class="p">,</span> <span class="mf">13.7</span><span class="p">,</span> <span class="mf">13.8</span><span class="p">,</span> <span class="mf">14.0</span><span class="p">,</span> <span class="mf">14.2</span><span class="p">,</span> <span class="mf">14.5</span><span class="p">,</span> <span class="mf">16.0</span><span class="p">,</span> <span class="mf">16.3</span><span class="p">,</span> <span class="mf">17.3</span><span class="p">,</span> <span class="mf">17.5</span><span class="p">,</span> <span class="mf">17.9</span><span class="p">,</span> <span class="mf">18.0</span><span class="p">,</span> <span class="mf">18.0</span><span class="p">,</span> <span class="mf">20.6</span><span class="p">];</span> |
| |
| <span class="kd">var</span> <span class="nx">bins</span> <span class="o">=</span> <span class="nx">ecStat</span><span class="p">.</span><span class="nx">histogram</span><span class="p">(</span><span class="nx">girth</span><span class="p">,</span> <span class="s1">'scott'</span><span class="p">);</span> |
| </code></pre> |
| </div> |
| |
| <p>这里的第二个参数 <code class="highlighter-rouge">'scott'</code> 是用来指定切割 bin 的方法,有四个选项,分别是 <code class="highlighter-rouge">'squareRoot'</code> 、 <code class="highlighter-rouge">'scott'</code> 、 <code class="highlighter-rouge">'freedmanDiaconis'</code> 、 <code class="highlighter-rouge">'sturges'</code> ,其中 <code class="highlighter-rouge">'squareRoot'</code> 是默认的计算方法,也是Excel中直方图使用的计算 bin 的方法 |
| ,有关这四种计算方法的详细介绍,请参见 <a href="https://en.wikipedia.org/wiki/Histogram#Mathematical_definition">wikipedia</a>。使用处理后的 <code class="highlighter-rouge">bins.data</code> 配置 ECharts 柱状图中的 <code class="highlighter-rouge">option.data</code> 就可以得到如下的直方图。由于篇幅的问题,这里就不再赘述具体的 <code class="highlighter-rouge">option</code> 配置,感兴趣的读者可以点击下方的 <code class="highlighter-rouge">代码</code> 按钮,进入 ECharts Gallery 中查看。</p> |
| |
| <iframe style="width: 100%; height: 400px" src="http://gallery.echartsjs.com/view.html?cid=xBk5VZddJW&amp;v=4"></iframe> |
| |
| <h2 id="聚类分析">聚类分析</h2> |
| |
| <p>聚类分析用于将原数据集聚合成多个特性不同的数据簇,每个数据簇内的数据对象具有某些相似的特征。通过 ECharts 不仅可以可视化聚类的结果,还可以可视化聚类的过程。具体的使用方式如下:</p> |
| |
| <div class="language-js highlighter-rouge"><pre class="highlight"><code><span class="kd">var</span> <span class="nx">result</span> <span class="o">=</span> <span class="nx">ecStat</span><span class="p">.</span><span class="nx">clustering</span><span class="p">.</span><span class="nx">hierarchicalKMeans</span><span class="p">(</span><span class="nx">data</span><span class="p">,</span> <span class="nx">clusterNumber</span><span class="p">,</span> <span class="kc">false</span><span class="p">);</span> |
| </code></pre> |
| </div> |
| <p>其中 <code class="highlighter-rouge">data</code> 是用户传入的二维数值数组, <code class="highlighter-rouge">clusterNumber</code> 是由用户设定的数据簇的个数,最后一个 <code class="highlighter-rouge">boolean</code> 类型的变量是用来指定,静态地可视化聚类的结果,还是动态地可视化聚类的过程。若值为 <code class="highlighter-rouge">false</code> 则为前者,反之,则为后者。</p> |
| |
| <p>静态可视化聚类的结果:</p> |
| |
| <iframe style="width: 100%; height: 400px" src="http://gallery.echartsjs.com/view.html?cid=xSkBOEaGtx&amp;v=10"></iframe> |
| |
| <p>动态可视化聚类的过程:</p> |
| |
| <iframe style="width: 100%; height: 400px" src="http://gallery.echartsjs.com/view.html?cid=xHyr-esMtg&amp;v=4"></iframe> |
| |
| <p>同样,感兴趣的读者可以点击上方实例的 <code class="highlighter-rouge">代码</code> 按钮,进入 ECharts Gallery 中查看具体的代码,以及 <code class="highlighter-rouge">option</code> 的配置。</p> |
| |
| <h2 id="回归分析">回归分析</h2> |
| |
| <p>回归分析就是根据数据集中自变量和因变量的值,拟合出一条曲线,反映它们的变化趋势。在统计扩展中我们实现了四种回归算法,分别是线性回归、指数回归、对数回归、以及多项式回归。使用方式如下:</p> |
| |
| <div class="language-js highlighter-rouge"><pre class="highlight"><code><span class="kd">var</span> <span class="nx">myRegression</span> <span class="o">=</span> <span class="nx">ecStat</span><span class="p">.</span><span class="nx">regression</span><span class="p">(</span><span class="nx">regressionType</span><span class="p">,</span> <span class="nx">data</span><span class="p">,</span> <span class="nx">order</span><span class="p">);</span> |
| </code></pre> |
| </div> |
| <p>其中,<code class="highlighter-rouge">regressionType</code> 指的是回归类型,有四种取值,分别是 <code class="highlighter-rouge">'linear'</code> 、<code class="highlighter-rouge">'exponential'</code> 、<code class="highlighter-rouge">'logarithmic'</code> 、<code class="highlighter-rouge">'polynomial'</code> 。<code class="highlighter-rouge">data</code> 是用户传入的二维数值数组,分别是自变量和因变量的样本值。最后一个参数 <code class="highlighter-rouge">order</code> 用于多项式回归,用来指定多项式的阶数。</p> |
| |
| <p>线性回归:</p> |
| |
| <iframe style="width: 100%; height: 400px" src="http://gallery.echartsjs.com/view.html?cid=xS1bQ2AMKe&amp;v=6"></iframe> |
| |
| <p>指数回归:</p> |
| |
| <iframe style="width: 100%; height: 400px" src="http://gallery.echartsjs.com/view.html?cid=xHyaNv0fFe&amp;v=5"></iframe> |
| |
| <p>对数回归:</p> |
| |
| <iframe style="width: 100%; height: 400px" src="http://gallery.echartsjs.com/view.html?cid=xry3aWkmYe&amp;v=4"></iframe> |
| |
| <p>多项式回归:</p> |
| |
| <iframe style="width: 100%; height: 400px" src="http://gallery.echartsjs.com/view.html?cid=xB16yW0MFl&amp;v=3"></iframe> |
| |
| <h2 id="常用汇总统计">常用汇总统计</h2> |
| |
| <p>除了上面提到的数据分析方法之外,统计扩展还包括了常用的汇总统计,如分位数、样本方差、标准差、中位数、平均数、求和、最大值、最小值等。具体的用法,这里就不在展开了,详情请参见 GitHub 上的<a href="https://github.com/ecomfe/echarts-stat#statistics">详细文档</a>。</p> |
| |
| <p>最后的最后,提醒大家一句,在参照完 <code class="highlighter-rouge">Gallery</code> 上 <code class="highlighter-rouge">option</code> 的设置之后,一定要记得 <code class="highlighter-rouge">setOption</code> ,如下:</p> |
| |
| <div class="language-js highlighter-rouge"><pre class="highlight"><code><span class="nx">chart</span><span class="p">.</span><span class="nx">setOption</span><span class="p">(</span><span class="nx">option</span><span class="p">);</span> |
| </code></pre> |
| </div></content><author><name>{"dingding"=>{"name"=>"王俊婷", "title"=>"ECharts 设计师", "web"=>"https://www.behance.net/wjtjiayouac8aa", "image"=>"http://echarts.baidu.com/images/people/王俊婷.png", "desc"=>"喜欢神游的女子一枚,又名王叮叮"}}</name></author><category term="统计" /><category term="扩展" /><category term="教程" /><summary>ECharts 统计扩展教程</summary><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://echarts.baidu.com/blog{"feature"=>"post/2017-05-09-echarts-statistical-logarithmic-regression.png"}" /></entry><entry><title>那些年我们一起学过的直方图</title><link href="http://echarts.baidu.com/blog/2017/05/08/echarts-histogram-tutorial.html" rel="alternate" type="text/html" title="那些年我们一起学过的直方图" /><published>2017-05-08T00:00:00+08:00</published><updated>2017-05-08T00:00:00+08:00</updated><id>http://echarts.baidu.com/blog/2017/05/08/echarts-histogram-tutorial</id><content type="html" xml:base="http://echarts.baidu.com/blog/2017/05/08/echarts-histogram-tutorial.html"><p>某天下午小编正在安安静静地撸代码,突然听说在我们的 <a href="http://gallery.echartsjs.com/explore.html#sort=rank~timeframe=all~author=all">gallery</a> 上,有用户提出,<a href="http://echarts.baidu.com/index.html">ECharts</a> 不支持直方图,什么?这怎么能忍?于是小编将珍藏已久的机械键盘拿出来,摆好姿势,通宵达旦地为用户大大们加好了直方图,并于上周四悄悄上线了,对,我们就是这么低调。然而,很多大大们表示,直方图还是柱状图?傻傻分不清。小编深感这年头光有图怕是不行了,必须得有个教程,要做到图文并茂。下面小编就从直方图是什么,为什么要用直方图,以及如何使用 <a href="http://echarts.baidu.com/index.html">ECharts</a> 制作直方图三个方面,为各位大大们上点干货。</p> |
| |
| <h2 id="直方图是什么">直方图是什么</h2> |
| |
| <p>直方图主要用来反映一组样本数据的分布情况。从图的形式来看,它属于柱状图的一种,但它和柱状图相比还是有很多不同之处的。首先,直方图的任意两个 bar 之间不允许有间隙,这是因为原始样本值被分割成一系列连续的、相互邻接的小区间,每一个小区间都是左闭右开的,除了最后一个,如<code class="highlighter-rouge">[x0, x1), [x1,x2), [x2,x3]</code>,在直方图中小区间又被称为“bin”。其中bin的高度是由落入该区间中样本值的个数决定的;其次,在 ECharts 中绘制双数值轴(这里的双数值轴指的是 x 轴和 y 轴都是数值类型的)柱状图,用户需要传入二维的数组,如<code class="highlighter-rouge">array1 = [[1, 2], [3, 4]]</code>,而绘制直方图,用户只需要传入一维的数组,如<code class="highlighter-rouge">array2 = [1, 2, 3, 4]</code>,然后由<a href="https://github.com/ecomfe/echarts-stat">ECharts 统计扩展</a>将一维的样本值分割成一个个具体的bin,并计算输出每一个bin的绘制信息,然后选用 ECharts 柱状图绘制具体的直方图。</p> |
| |
| <h2 id="为什么要用直方图">为什么要用直方图</h2> |
| |
| <p>前面已经提到了,直方图主要用来反映样本数据的分布,如下图,这是使用著名的<a href="https://en.wikipedia.org/wiki/Iris_flower_data_set">虹膜花数据集</a>中的花瓣长度这一维度所作的直方图。从图中可以直观地看出该维度样本数据不符合正态分布,有多个峰值,具有明显的差异。这说明不同种类虹膜花的花瓣长度,受多个因素的影响,同时也表明在进一步的数据分析中,所有基于正态分布假设的分析,都不适合该维度数据。</p> |
| |
| <p><img src="http://echarts.baidu.com/blog/images/post/2017-05-08-echarts-histogram-petal-length-iris.png" alt="petal-width" /></p> |
| |
| <p>除此之外,直方图还可以用来进行数据审查。所谓的数据审查,是指在数据预处理之前,通过直方图直观地审视样本数据中的每个维度,检查是否有异常值的同时,了解值的分布。如图,这是记录 31 颗黑樱桃树周长的样本数据,从图中可以明显地看出有三个异常值,因为树的周长肯定大于 0 ,不会出现小于 0 的负数,而<code class="highlighter-rouge">[-5, 0)</code>这个区间内有三个样本值,这就需要通过数据清洗将异常值过滤掉。</p> |
| |
| <p><img src="http://echarts.baidu.com/blog/images/post/2017-05-08-echarts-histogram-girth-of-tree.png" alt="girth-tree" /></p> |
| |
| <h2 id="如何使用-echarts制作直方图">如何使用 <a href="http://echarts.baidu.com/index.html">ECharts</a>制作直方图</h2> |
| |
| <p>ECharts 是一个强大的可视化图表库,并不是一个统计分析的工具,所以我们将处理原始数据并分割成一个个具体的bin这一部分放在了 ECharts 的<a href="https://github.com/ecomfe/echarts-stat">统计扩展</a>中实现。这就需要我们在引入 <code class="highlighter-rouge">echarts.js</code> 的同时,引入统计扩展对应的 <code class="highlighter-rouge">ecStat.js</code>,如:</p> |
| |
| <div class="language-html highlighter-rouge"><pre class="highlight"><code><span class="nt">&lt;script </span><span class="na">src=</span><span class="s">"echarts.js"</span><span class="nt">&gt;&lt;/script&gt;</span> |
| <span class="nt">&lt;script </span><span class="na">src=</span><span class="s">"ecStat.js"</span><span class="nt">&gt;&lt;/script&gt;</span> |
| |
| <span class="nt">&lt;script&gt;</span> |
| |
| <span class="kd">var</span> <span class="nx">height</span> <span class="o">=</span> <span class="p">[</span><span class="mi">70</span><span class="p">,</span> <span class="mi">65</span><span class="p">,</span> <span class="mi">63</span><span class="p">,</span> <span class="mi">72</span><span class="p">,</span> <span class="mi">81</span><span class="p">,</span> <span class="mi">83</span><span class="p">,</span> <span class="mi">66</span><span class="p">,</span> <span class="mi">75</span><span class="p">,</span> <span class="mi">80</span><span class="p">,</span> <span class="mi">75</span><span class="p">,</span> <span class="mi">79</span><span class="p">,</span> <span class="mi">76</span><span class="p">,</span> <span class="mi">76</span><span class="p">,</span> <span class="mi">69</span><span class="p">,</span> <span class="mi">75</span><span class="p">,</span> <span class="mi">74</span><span class="p">,</span> <span class="mi">85</span><span class="p">,</span> <span class="mi">86</span><span class="p">,</span> <span class="mi">71</span><span class="p">,</span> <span class="mi">64</span><span class="p">,</span> <span class="mi">78</span><span class="p">,</span> <span class="mi">80</span><span class="p">,</span> <span class="mi">74</span><span class="p">,</span> <span class="mi">72</span><span class="p">,</span> <span class="mi">77</span><span class="p">,</span> <span class="mi">81</span><span class="p">,</span> <span class="mi">82</span><span class="p">,</span> <span class="mi">80</span><span class="p">,</span> <span class="mi">80</span><span class="p">,</span> <span class="mi">80</span><span class="p">,</span> <span class="mi">87</span><span class="p">];</span> |
| |
| <span class="kd">var</span> <span class="nx">bins</span> <span class="o">=</span> <span class="nx">ecStat</span><span class="p">.</span><span class="nx">histogram</span><span class="p">(</span><span class="nx">height</span><span class="p">);</span> |
| |
| <span class="nt">&lt;/script&gt;</span> |
| </code></pre> |
| </div> |
| <p>然后使用统计扩展处理过后的数据,配置 ECharts 柱状图中的 option,如:</p> |
| |
| <div class="language-js highlighter-rouge"><pre class="highlight"><code><span class="kd">var</span> <span class="nx">option</span> <span class="o">=</span> <span class="p">{</span> |
| <span class="na">color</span><span class="p">:</span> <span class="p">[</span><span class="s1">'rgb(25, 183, 207)'</span><span class="p">],</span> |
| <span class="na">grid</span><span class="p">:</span> <span class="p">{</span> |
| <span class="na">left</span><span class="p">:</span> <span class="s1">'3%'</span><span class="p">,</span> |
| <span class="na">right</span><span class="p">:</span> <span class="s1">'3%'</span><span class="p">,</span> |
| <span class="na">bottom</span><span class="p">:</span> <span class="s1">'3%'</span><span class="p">,</span> |
| <span class="na">containLabel</span><span class="p">:</span> <span class="kc">true</span> |
| <span class="p">},</span> |
| <span class="na">xAxis</span><span class="p">:</span> <span class="p">[{</span> |
| <span class="na">type</span><span class="p">:</span> <span class="s1">'value'</span><span class="p">,</span> |
| <span class="c1">//这个一定要设,不然barWidth和bins对应不上</span> |
| <span class="na">scale</span><span class="p">:</span> <span class="kc">true</span><span class="p">,</span> |
| <span class="p">}],</span> |
| <span class="na">yAxis</span><span class="p">:</span> <span class="p">[{</span> |
| <span class="na">type</span><span class="p">:</span> <span class="s1">'value'</span><span class="p">,</span> |
| <span class="p">}],</span> |
| <span class="na">series</span><span class="p">:</span> <span class="p">[{</span> |
| <span class="na">type</span><span class="p">:</span> <span class="s1">'bar'</span><span class="p">,</span> |
| <span class="na">barWidth</span><span class="p">:</span> <span class="s1">'99.3%'</span><span class="p">,</span> |
| <span class="na">label</span><span class="p">:</span> <span class="p">{</span> |
| <span class="na">normal</span><span class="p">:</span> <span class="p">{</span> |
| <span class="na">show</span><span class="p">:</span> <span class="kc">true</span><span class="p">,</span> |
| <span class="na">position</span><span class="p">:</span> <span class="s1">'insideTop'</span><span class="p">,</span> |
| <span class="na">formatter</span><span class="p">:</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">params</span><span class="p">)</span> <span class="p">{</span> |
| <span class="k">return</span> <span class="nx">params</span><span class="p">.</span><span class="nx">value</span><span class="p">[</span><span class="mi">1</span><span class="p">];</span> |
| <span class="p">}</span> |
| <span class="p">}</span> |
| <span class="p">},</span> |
| <span class="na">data</span><span class="p">:</span> <span class="nx">bins</span><span class="p">.</span><span class="nx">data</span> |
| <span class="p">}]</span> |
| <span class="p">};</span> |
| |
| </code></pre> |
| </div> |
| <p>这样就得到了如下的直方图:</p> |
| |
| <p><img src="http://echarts.baidu.com/blog/images/post/2017-05-08-echarts-histogram-height-of-tree.png" alt="height-tree" /></p> |
| |
| <p>这里不得不说的是,由于历史遗留的问题,ECharts 中的柱状图并不能完美地支持直方图的绘制,所以不得不使用一些小的 trick,如设置 <code class="highlighter-rouge">xAxis</code> 的 <code class="highlighter-rouge">scale</code> 为 <code class="highlighter-rouge">true</code>,调整 <code class="highlighter-rouge">barWidth</code> 的值等。不过,大家不用担心,作为一个良心以及正义感爆棚的团队,我们即将发布一款新的自定义图表类型。经小编亲测,该图表类型可以画出狂拽酷炫屌炸天的直方图,敬请期待哦。</p></content><author><name>{"dingding"=>{"name"=>"王俊婷", "title"=>"ECharts 设计师", "web"=>"https://www.behance.net/wjtjiayouac8aa", "image"=>"http://echarts.baidu.com/images/people/王俊婷.png", "desc"=>"喜欢神游的女子一枚,又名王叮叮"}}</name></author><category term="直方图" /><category term="教程" /><category term="扩展" /><summary>某天下午小编正在安安静静地撸代码,突然听说在我们的 gallery 上,有用户提出,ECharts 不支持直方图,什么?这怎么能忍?于是小编将珍藏已久的机械键盘拿出来,摆好姿势,通宵达旦地为用户大大们加好了直方图,并于上周四悄悄上线了,对,我们就是这么低调。然而,很多大大们表示,直方图还是柱状图?傻傻分不清。小编深感这年头光有图怕是不行了,必须得有个教程,要做到图文并茂。下面小编就从直方图是什么,为什么要用直方图,以及如何使用 ECharts 制作直方图三个方面,为各位大大们上点干货。</summary><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://echarts.baidu.com/blog{"feature"=>"post/2017-05-08-echarts-histogram-height-of-tree.png"}" /></entry><entry><title>ECharts GL 1.0 alpha 发布</title><link href="http://echarts.baidu.com/blog/2017/04/12/echarts-gl-alpha.html" rel="alternate" type="text/html" title="ECharts GL 1.0 alpha 发布" /><published>2017-04-12T00:00:00+08:00</published><updated>2017-04-12T00:00:00+08:00</updated><id>http://echarts.baidu.com/blog/2017/04/12/echarts-gl-alpha</id><content type="html" xml:base="http://echarts.baidu.com/blog/2017/04/12/echarts-gl-alpha.html"><p>距离 ECharts-X 最近一个版本已经过去了两年多时间,期间我们不断被开发者在各种渠道询问 ECharts-X 为什么还不升级新版本,是不是不再维护了等等,对于这些问题我们只能回答我们还没准备好。尽管这两年时间 ECharts X 没什么动静,但是其它的工作,像 ECharts 3 的架构大改动和后续版本的迭代升级,以及其它 WebGL 产品的开发,都是对新版本架构和技术上的积累。现在我们终于可以说我们准备得差不多了,ECharts-X 的下一代,ECharts-GL 发布 1.0 alpha。</p> |
| |
| <p><a href="https://github.com/ecomfe/echarts-gl">ECharts GL</a> 是 ECharts 的 WebGL 扩展,其中提供了三维散点图,飞线图,柱状图,曲面图,地球等多种三维可视化方式。并且增加 <code class="highlighter-rouge">scatterGL</code>,<code class="highlighter-rouge">graphGL</code> 系列类型用于二维的散点图,关系图的加速绘制和布局。</p> |
| |
| <p>先来一张 Gallery 上 <a href="https://github.com/ecomfe/echarts-gl">ECharts GL</a> 的示例图片集。</p> |
| |
| <p><img src="http://echarts.baidu.com/blog/images/post/2017-04-12/demos.jpg" alt="" /></p> |
| |
| <p>下面会一一介绍 ECharts GL 的特性,如果你已经等不及想尝鲜了,可以直接在 Gallery 上查看编辑 ECharts GL 的示例。</p> |
| |
| <ul> |
| <li> |
| <p><a href="http://gallery.echartsjs.com/explore.html#tags=echarts-gl">GL 的 Gallery 示例</a></p> |
| </li> |
| <li> |
| <p><a href="https://ecomfe.github.io/echarts-doc/public/cn/option-gl.html">GL 的配置项手册</a></p> |
| </li> |
| </ul> |
| |
| <h2 id="一更便捷的安装和引入">一、更便捷的安装和引入</h2> |
| |
| <p>大家用过 ECharts-X 的话,或许曾被其繁琐的引入方式困扰过,甚至可能因为尝试了很多次都没办法正确引入而选择放弃。</p> |
| |
| <p>ECharts-GL 中大大简化了引入方式,在标签引入的环境下。你可以从 <a href="https://github.com/ecomfe/echarts-gl/tree/master/dist">GitHub</a> 上获取 ECharts GL 后直接引入构建好的文件.</p> |
| |
| <div class="language-js highlighter-rouge"><pre class="highlight"><code><span class="o">&lt;</span><span class="nx">script</span> <span class="nx">data</span><span class="o">-</span><span class="nx">src</span><span class="o">=</span><span class="s2">"echarts/dist/echarts.min.js"</span><span class="o">&gt;&lt;</span><span class="sr">/script</span><span class="err">&gt; |
| </span><span class="o">&lt;</span><span class="nx">script</span> <span class="nx">data</span><span class="o">-</span><span class="nx">src</span><span class="o">=</span><span class="s2">"echarts-gl/dist/echarts-gl.min.js"</span><span class="o">&gt;&lt;</span><span class="sr">/script</span><span class="err">&gt; |
| </span></code></pre> |
| </div> |
| |
| <p>如果你用 webpack 和 npm 作为开发环境。也只需要在 <code class="highlighter-rouge">npm install echarts-gl</code> 之后再<code class="highlighter-rouge">require</code>引入。</p> |
| |
| <div class="language-js highlighter-rouge"><pre class="highlight"><code><span class="nx">require</span><span class="p">(</span><span class="s1">'echarts-gl'</span><span class="p">);</span> |
| </code></pre> |
| </div> |
| |
| <h2 id="二更多三维可视化类型">二、更多三维可视化类型。</h2> |
| |
| <p>除了老版本的<a href="https://ecomfe.github.io/echarts-doc/public/cn/option-gl.html#globe">地球</a>用于地理数据可视化,ECharts GL 新增了三维的<a href="https://ecomfe.github.io/echarts-doc/public/cn/option-gl.html#grid3D">笛卡尔坐标系</a>、<a href="https://ecomfe.github.io/echarts-doc/public/cn/option-gl.html#geo3D">地理坐标系</a>,并且在这些新的三维坐标系基础上提供了六个新的系列类型,包括 <a href="https://ecomfe.github.io/echarts-doc/public/cn/option-gl.html#series-scatter3D">散点图 scatter3D</a>、<a href="https://ecomfe.github.io/echarts-doc/public/cn/option-gl.html#series-line3D">折线图 line3D</a>、<a href="https://ecomfe.github.io/echarts-doc/public/cn/option-gl.html#series-bar3D">柱状图 bar3D</a>、<a href="https://ecomfe.github.io/echarts-doc/public/cn/option-gl.html#series-surface">曲面图 surface</a>、<a href="https://ecomfe.github.io/echarts-doc/public/cn/option-gl.html#series-lines3D">飞线图 lines3D</a>以及<a href="https://ecomfe.github.io/echarts-doc/public/cn/option-gl.html#series-map3D">地图 map3D</a></p> |
| |
| <p>这些新的系列类型以及组件类型都是使用 WebGL 绘制,因此能够保证高质量,高性能的展示出你想要的三维可视化作品。</p> |
| |
| <p>同时我们在配置项的设计上尽量沿用了 ECharts 的风格,保证简洁统一。比如下面这个配置就能画出一个简单的三维散点图。</p> |
| |
| <div class="language-js highlighter-rouge"><pre class="highlight"><code><span class="nx">option</span> <span class="o">=</span> <span class="p">{</span> |
| <span class="na">grid3D</span><span class="p">:</span> <span class="p">{},</span> |
| <span class="na">xAxis3D</span><span class="p">:</span> <span class="p">{},</span> |
| <span class="na">yAxis3D</span><span class="p">:</span> <span class="p">{},</span> |
| <span class="na">zAxis3D</span><span class="p">:</span> <span class="p">{},</span> |
| <span class="na">series</span><span class="p">:</span> <span class="p">[{</span> |
| <span class="na">type</span><span class="p">:</span> <span class="s1">'scatter3D'</span><span class="p">,</span> |
| <span class="na">symbolSize</span><span class="p">:</span> <span class="mi">50</span><span class="p">,</span> |
| <span class="na">data</span><span class="p">:</span> <span class="p">[[</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">],</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">]],</span> |
| <span class="na">itemStyle</span><span class="p">:</span> <span class="p">{</span> |
| <span class="na">opacity</span><span class="p">:</span> <span class="mi">1</span> |
| <span class="p">}</span> |
| <span class="p">}]</span> |
| <span class="p">};</span> |
| </code></pre> |
| </div> |
| <blockquote> |
| <p>这里跟 ECharts 有点区别,GL 中尝试了更扁平的 option 设计,使用场景更少的 emphasis 属性将会单独移出来,而原先 normal 这个层级将被移除,itemStyle 下的属性相当于原先 itemStyle.normal 下的属性。如果这次尝试没问题,接下来 ECharts 新的大版本也会使用这种更扁平的设计。 |
| 具体配置结构见 <a href="https://ecomfe.github.io/echarts-doc/public/cn/option-gl.html#series-scatter3D.itemStyle">https://ecomfe.github.io/echarts-doc/public/cn/option-gl.html#series-scatter3D.itemStyle</a></p> |
| </blockquote> |
| |
| <p>大部分 GL 中的三维组件和系列都会带上<code class="highlighter-rouge">3D</code>后缀以便跟 ECharts 中的组件系列区分开。</p> |
| |
| <p>下面这个更复杂点的例子使用<code class="highlighter-rouge">scatter3D</code>可视化了三维的 <a href="https://en.wikipedia.org/wiki/Simplex_noise">Simplex Noise</a></p> |
| |
| <p><a href="http://gallery.echartsjs.com/editor.html?c=xBkWoZOjTe"> |
| <img src="http://echarts.baidu.com/blog/images/post/2017-04-12/simplex-noise.jpg" alt="" /> |
| </a></p> |
| |
| <p>除了三维的散点图,你也可以在笛卡尔坐标系上画 <a href="https://ecomfe.github.io/echarts-doc/public/cn/option-gl.html#series-line3D">折线图 line3D</a>,<a href="https://ecomfe.github.io/echarts-doc/public/cn/option-gl.html#series-bar3D">柱状图 bar3D</a>,<a href="https://ecomfe.github.io/echarts-doc/public/cn/option-gl.html#series-surface">曲面图 surface</a>。</p> |
| |
| <p>其中 <a href="https://ecomfe.github.io/echarts-doc/public/cn/option-gl.html#series-line3D">line3D</a>,<a href="https://ecomfe.github.io/echarts-doc/public/cn/option-gl.html#series-bar3D">bar3D</a> 也是对 ECharts 中的折线图,柱状图扩展到了三维的版本。而 <a href="https://ecomfe.github.io/echarts-doc/public/cn/option-gl.html#series-surface">surface</a> 是 ECharts GL 里全新的三维图。</p> |
| |
| <p>你可以像下面这样用 <a href="https://ecomfe.github.io/echarts-doc/public/cn/option-gl.html#series-surface">surface</a> 画函数曲面。</p> |
| |
| <p><a href="http://gallery.echartsjs.com/editor.html?c=xHkcYXm9pe"> |
| <img src="http://echarts.baidu.com/blog/images/post/2017-04-12/surface.png" alt="" /> |
| </a></p> |
| |
| <p>也可以像这样用曲面去可视化像图片像素这样的数据</p> |
| |
| <p><a href="http://gallery.echartsjs.com/editor.html?c=xBk5PSvqpx"> |
| <img src="http://echarts.baidu.com/blog/images/post/2017-04-12/image-pixels.jpg" alt="" /> |
| </a></p> |
| |
| <p>甚至你可以用参数方程构建出下面这样有趣的参数曲面</p> |
| |
| <p><a href="http://gallery.echartsjs.com/editor.html?c=xHku9OE96l"> |
| <img src="http://echarts.baidu.com/blog/images/post/2017-04-12/parametric-surface.jpg" alt="" /> |
| </a></p> |
| |
| <p>除了三维笛卡尔坐标系,像柱状图,散点图也可以显示在<a href="https://ecomfe.github.io/echarts-doc/public/cn/option-gl.html#globe">地球</a>,<a href="https://ecomfe.github.io/echarts-doc/public/cn/option-gl.html#geo3D">三维地理坐标系</a>上。</p> |
| |
| <p>比如下面这个例子就是在地球上通过散点图绘制世界人口。</p> |
| |
| <p><a href="http://gallery.echartsjs.com/editor.html?c=xS1moC0s6x"> |
| <img src="http://echarts.baidu.com/blog/images/post/2017-04-12/high-quality-2.jpg" style="width:100%;" alt="" /> |
| </a></p> |
| |
| <p>你可以大胆的组合不同坐标系和系列,制作出更具创造力的可视化作品!</p> |
| |
| <h2 id="三高品质的画面">三、高品质的画面</h2> |
| |
| <p>在很多场景里,高品质的画面是一个很重要的需求,例如:</p> |
| |
| <ul> |
| <li> |
| <p>在大屏中,需要提供炫酷的,一下能够抓住人眼球的特效。</p> |
| </li> |
| <li> |
| <p>生成需要放在文章或者 PPT 中的截图,需要高质量的渲染,不能有廉价三维效果的感觉。</p> |
| </li> |
| </ul> |
| |
| <p>ECharts GL 提供了一系列诸如<a href="http://localhost/echarts-doc/public/cn/option-gl.html#geo3D.postEffect.depthOfField">景深</a>,<a href="http://localhost/echarts-doc/public/cn/option-gl.html#geo3D.postEffect.bloom">光晕</a>,<a href="http://localhost/echarts-doc/public/cn/option-gl.html#geo3D.postEffect.colorCorrection">颜色纠正</a>,<a href="http://localhost/echarts-doc/public/cn/option-gl.html#geo3D.postEffect.SSAO">阴影</a>,<a href="http://localhost/echarts-doc/public/cn/option-gl.html#geo3D.light.ambientCubemap">基于物理的渲染</a> 等等开箱即用的配置项让你去方便的提升自己可视化作品的渲染效果。</p> |
| |
| <p>在这些配置项的基础上,你可以实现这样带景深的微缩模型的效果:</p> |
| |
| <p><img src="http://echarts.baidu.com/blog/images/post/2017-04-12/high-quality-1.jpg" style="width:100%;" alt="" /></p> |
| |
| <p>或者这样的基于物理渲染的金属零件的效果:</p> |
| |
| <p><img src="http://echarts.baidu.com/blog/images/post/2017-04-12/high-quality-3.jpg" style="width:100%;" alt="" /></p> |
| |
| <p>或者这样 Bling Bling 的影视广告特效:</p> |
| |
| <p><img src="http://echarts.baidu.com/blog/images/post/2017-04-12/high-quality-5.jpg" style="width:100%;" alt="" /></p> |
| |
| <p>又或者这样的大规模建筑群:</p> |
| |
| <p><img src="http://echarts.baidu.com/blog/images/post/2017-04-12/high-quality-4.jpg" style="width:100%;" alt="" /></p> |
| |
| <p>想要了解更多的效果,可以逛逛我们的<a href="http://gallery.echartsjs.com/explore.html#tags=echarts-gl">示例集</a></p> |
| |
| <h2 id="四二维可视化的加速">四、二维可视化的加速</h2> |
| |
| <p>除了三维的可视化,ECharts GL 还内置 <a href="https://ecomfe.github.io/echarts-doc/public/cn/option-gl.html#series-scatterGL">scatterGL</a>, <a href="https://ecomfe.github.io/echarts-doc/public/cn/option-gl.html#series-scatterGL">graphGL</a> 两个系列,能够大幅度的优化常见的二维散点图和关系图的绘制和布局性能。</p> |
| |
| <p>散点图也是比较常见的会有大数据量的系列类型。ECharts 尽管能绘制像微博签到图那样上十万的散点图,但是很难做到流畅的交互。拖拽、缩放等操作都会有卡顿。</p> |
| |
| <p>在 ECharts GL 里利用 WebGL 加速绘制后,可以无压力得绘制和实时的交互十万个数据的散点图了。</p> |
| |
| <p><a href="http://gallery.echartsjs.com/editor.html?c=xHJkXhU9Tg"> |
| <img src="http://echarts.baidu.com/blog/images/post/2017-04-12/weibo-checkin.jpg" alt="" /></a></p> |
| |
| <p>而且实现这一切只需要把原先的<code class="highlighter-rouge">scatter</code>类型改为<code class="highlighter-rouge">scatterGL</code>类型,不需要再做其它的改动!</p> |
| |
| <p>对于<a href="https://ecomfe.github.io/echarts-doc/public/cn/option-gl.html#series-scatterGL">关系图 graphGL</a>除了绘制上有加速之外,我们还在 WebGL 中实现了<a href="https://github.com/gephi/gephi/wiki/Force-Atlas-2">力引导布局</a>。在高端的显卡上 GPU 布局相对于 CPU 布局甚至能有上百倍的性能提升。</p> |
| |
| <p>下面是在<code class="highlighter-rouge">GTX1070</code>和<code class="highlighter-rouge">i7 4GHz</code>的电脑中对一个<code class="highlighter-rouge">两万</code>个节点,近<code class="highlighter-rouge">五万</code>条边的关系图一次布局的迭代的性能对比。</p> |
| |
| <p><img src="http://echarts.baidu.com/blog/images/post/2017-04-12/gpu-layout-perf.png" width="400px" alt="" /></p> |
| |
| <p>以及对这个关系图实时布局的视频。</p> |
| |
| <video controls="" width="100%" src="http://echarts.baidu.com/blog/images/post/2017-04-12/graphGL.mp4"></video> |
| |
| <p><code class="highlighter-rouge">2500</code>个节点的网格图使用 GPU 布局的例子(只支持 PC 端)。</p> |
| |
| <p><a href="http://gallery.echartsjs.com/editor.html?c=xrJchBL9ag"> |
| <img src="http://echarts.baidu.com/blog/images/post/2017-04-12/grid.jpg" alt="" /></a></p> |
| |
| <p>这里特别感谢 Gephi 提供了 Force Atlas2 这样在大规模关系数据上能够有稳定优良的布局结果的算法。</p> |
| |
| <h2 id="五与-echarts-交互组件的结合">五、与 ECharts 交互组件的结合</h2> |
| |
| <p>ECharts GL 作为一个扩展,并不是独立的,它提供的系列和组件能够和 ECharts 中的大部分组件组合使用。你可以使用 <a href="http://echarts.baidu.com/option.html#visualMap">visualMap</a> 组件对 GL 中的系列进行颜色,大小,不透明的编码,可以用 <a href="http://echarts.baidu.com/option.html#tooltip">tooltip</a> 组件显示 GL 中图形的数据信息,也可以用 <a href="http://echarts.baidu.com/option.html#legend">legend</a> 筛选出想要展示的系列等等。</p> |
| |
| <p>例如下面这个例子用 <a href="http://echarts.baidu.com/option.html#visualMap">visualMap</a> 组件对柱状图做了颜色的映射,而且能够通过控件筛选出区间内的数据</p> |
| |
| <p><a href="http://gallery.echartsjs.com/editor.html?c=xSyMekmcTx"> |
| <img src="http://echarts.baidu.com/blog/images/post/2017-04-12/visual-map.jpg" alt="" /></a></p> |
| |
| <p>当然除此之外,你也可以在一个实例里任意混搭使用 ECharts GL 的组件以及 ECharts 的组件。</p> |
| |
| <h2 id="六移动端兼容">六、移动端兼容</h2> |
| |
| <p>现在很多移动端的浏览器已经支持 WebGL 了,特别是像 iOS 系统对 WebGL 的扩展特性等支持得非常完善。所以用 ECharts GL 制作的大部分例子都能在 iOS 上流畅无压力的运行。在交互上 ECharts GL 也对移动端做了兼容处理,支持平移,双指缩放等等。</p> |
| |
| <p>如果你现在不是在手机上浏览这篇文章,可以稍后在手机上打开 <a href="http://gallery.echartsjs.com/">http://gallery.echartsjs.com/</a> 看看效果。</p> |
| |
| <p>下面是在 iPhone 6 上实时预览前面示例中参数曲面的效果。</p> |
| |
| <video controls="" width="100%" src="http://echarts.baidu.com/blog/images/post/2017-04-12/mobile.mp4"></video> |
| |
| <h2 id="更多">更多</h2> |
| |
| <p>ECharts GL 1.0 alpha 只是个开始,在正式版发布之前,我们还会对画面,交互的细节,动画,性能等等做更多的优化。大家使用过程中有任何的问题或者建议都可以在 GitHub 上跟我们反馈, |
| 我们也非常期待大家能够利用 ECharts GL 做出让我们想象不到的作品。</p></content><author><name>{"dingding"=>{"name"=>"王俊婷", "title"=>"ECharts 设计师", "web"=>"https://www.behance.net/wjtjiayouac8aa", "image"=>"http://echarts.baidu.com/images/people/王俊婷.png", "desc"=>"喜欢神游的女子一枚,又名王叮叮"}}</name></author><category term="新版本" /><category term="扩展" /><category term="echarts-gl" /><summary>距离 ECharts-X 最近一个版本已经过去了两年多时间,期间我们不断被开发者在各种渠道询问 ECharts-X 为什么还不升级新版本,是不是不再维护了等等,对于这些问题我们只能回答我们还没准备好。尽管这两年时间 ECharts X 没什么动静,但是其它的工作,像 ECharts 3 的架构大改动和后续版本的迭代升级,以及其它 WebGL 产品的开发,都是对新版本架构和技术上的积累。现在我们终于可以说我们准备得差不多了,ECharts-X 的下一代,ECharts-GL 发布 1.0 alpha。</summary><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://echarts.baidu.com/blog{"feature"=>"post/2017-04-12/buildings2.jpg"}" /></entry><entry><title>ECharts v3.5 发布:新增日历坐标系、坐标轴指示器;同时统计扩展 v1.0 发布</title><link href="http://echarts.baidu.com/blog/2017/03/23/new-release.html" rel="alternate" type="text/html" title="ECharts v3.5 发布:新增日历坐标系、坐标轴指示器;同时统计扩展 v1.0 发布" /><published>2017-03-23T00:00:00+08:00</published><updated>2017-03-23T00:00:00+08:00</updated><id>http://echarts.baidu.com/blog/2017/03/23/new-release</id><content type="html" xml:base="http://echarts.baidu.com/blog/2017/03/23/new-release.html"><p>在 ECharts 新发布的 <a href="https://github.com/ecomfe/echarts/releases/tag/3.5.0">3.5 版本</a>中,新增了日历坐标系,增强了坐标轴指示器。同时,<a href="https://github.com/ecomfe/echarts-stat">ECharts 统计扩展</a> 1.0 版本发布了。日历坐标系用于在日历中绘制图表,坐标轴指示器方便用户观察数据内容,统计扩展是一个专门用来进行数据分析的工具。</p> |
| |
| <h2 id="统计扩展">统计扩展</h2> |
| |
| <p>统计扩展是一个专门用来进行数据分析的工具,目前主要包含了二维的回归、多维的聚类以及一些常用的统计功能。</p> |
| |
| <p>扩展中的回归算法不仅包含了常用的线性回归,还包含了指数回归、对数回归、以及多项式回归。</p> |
| |
| <p>线性回归的示例:</p> |
| <div class="ec-lazy" data-thumb="http://echarts.baidu.com/blog/images/post/2017-03-23/xS1bQ2AMKe.png" data-src="http://gallery.echartsjs.com/view.html?cid=xS1bQ2AMKe" style="width: 100%; height: 400px"></div> |
| |
| <p>对数回归的示例:</p> |
| <div class="ec-lazy" data-thumb="http://echarts.baidu.com/blog/images/post/2017-03-23/xry3aWkmYe.png" data-src="http://gallery.echartsjs.com/view.html?cid=xry3aWkmYe" style="width: 100%; height: 400px"></div> |
| |
| <p>秉承了可视分析的宗旨,我们的多维聚类分析,不仅可以静态地产出数据集聚类的结果,还可以动态地查看整个聚类分析的过程。</p> |
| |
| <p>静态地产出数据集聚类的结果的示例:</p> |
| <div class="ec-lazy" data-thumb="http://echarts.baidu.com/blog/images/post/2017-03-23/xSkBOEaGtx.png" data-src="http://gallery.echartsjs.com/view.html?cid=xSkBOEaGtx" style="width: 100%; height: 400px"></div> |
| |
| <p>动态地查看整个聚类分析的过程的示例:</p> |
| <div class="ec-lazy" data-thumb="http://echarts.baidu.com/blog/images/post/2017-03-23/xHyr-esMtg.png" data-src="http://gallery.echartsjs.com/view.html?cid=xHyr-esMtg" style="width: 100%; height: 400px"></div> |
| |
| <p>和 echarts 中的原生图表不一样,统计扩展是作为一个扩展工具发布的。这意味着,在 echarts 官网下载的完整版本将不包含该扩展包。统计扩展和 echarts 结合使用时,需要在引入 <code class="highlighter-rouge">echarts.js</code> 之后,另外引入统计扩展对应的 <code class="highlighter-rouge">ecStat.js</code>。可以在 <a href="https://github.com/ecomfe/echarts-stat/releases/latest">这里 (GitHub)</a> 找到最新版本,其中 <code class="highlighter-rouge">dist/ecStat.js</code> 可作为单文件引用。</p> |
| |
| <p>如果想了解更多内容请前往 <a href="https://github.com/ecomfe/echarts-stat">统计扩展 GitHub 首页</a>。</p> |
| |
| <h2 id="日历坐标系">日历坐标系</h2> |
| |
| <p>日历坐标系,是一种新的 echarts 坐标系,提供了在日历上绘制图表的能力。例如可以在日历坐标系上放置热力图、散点图、关系图等。如下示例:</p> |
| |
| <p>在日历坐标系中使用热力图:</p> |
| <div class="ec-lazy" data-thumb="http://echarts.baidu.com/gallery/data/thumb/bubble-gradient.png" data-src="http://echarts.baidu.com/gallery/view.html?c=calendar-heatmap&amp;edit=1&amp;reset=1" style="width: 100%; height: 300px"></div> |
| |
| <p>在日历坐标系中使用散点图:</p> |
| <div class="ec-lazy" data-thumb="http://echarts.baidu.com/gallery/data/thumb/bubble-gradient.png" data-src="http://echarts.baidu.com/gallery/view.html?c=calendar-effectscatter&amp;edit=1&amp;reset=1" style="width: 100%; height: 600px"></div> |
| |
| <p>还可以混合放置不同的图表,例如下例子,同时放置了热力图和关系图:</p> |
| <div class="ec-lazy" data-thumb="http://echarts.baidu.com/gallery/data/thumb/bubble-gradient.png" data-src="http://echarts.baidu.com/gallery/view.html?c=calendar-graph&amp;edit=1&amp;reset=1" style="width: 100%; height: 600px"></div> |
| |
| <p><strong>水平和垂直放置日历</strong></p> |
| |
| <p>在日历坐标系可以水平放置,也可以垂直放置。如上面的例子,使用热力图时,经常是水平放置的。但是如果需要格子的尺寸大些,水平放置就过于宽了,于是也可以选择垂直放置。参见 <a href="http://echarts.baidu.com/option.html#calendar.orient">calendar.orient</a>。</p> |
| |
| <p><strong>尺寸的自适应</strong></p> |
| |
| <p>日历坐标系支持不同尺寸的容器(页面)大小变化的自适应。首先,和 echarts 其他组件一样,日历坐标系可以选择使用 <a href="http://echarts.baidu.com/option.html#calendar.left">left</a>,<a href="http://echarts.baidu.com/option.html#calendar.right">right</a>,<a href="http://echarts.baidu.com/option.html#calendar.top">top</a>,<a href="bottom">bottom</a>,<a href="http://echarts.baidu.com/option.html#calendar.width">width</a>,<a href="http://echarts.baidu.com/option.html#calendar.height">height</a> 来描述尺寸和位置,从而将日历摆放在上下左右各种位置,并随着页面尺寸变动而改变自身尺寸。另外,也可以使用 <a href="http://echarts.baidu.com/option.html#calendar.cellSize">cellSize</a> 来固定日历格子的长宽。</p> |
| |
| <p><strong>中西方日历习惯的支持</strong></p> |
| |
| <p>中西方日历有所差别,西方常使用星期日作为一周的第一天,中国使用星期一为一周的第一天。日历坐标系做了这种切换的支持。参见 <a href="http://echarts.baidu.com/option.html#calendar.dayLabel.firstDay">calendar.dayLabel.firstDay</a>。</p> |
| |
| <p>另外,日历上的『月份』和『星期几』的文字,也可以较方便的切换中英文,甚至自定义。参见 <a href="http://echarts.baidu.com/option.html#calendar.dayLabel.nameMap">calendar.dayLabel.nameMap</a> <a href="http://echarts.baidu.com/option.html#calendar.monthLabel.nameMap">calendar.monthLabel.nameMap</a>。</p> |
| |
| <p><strong>其他更丰富的效果</strong></p> |
| |
| <p>灵活利用 echarts 图表和坐标系的组合,以及 API,可以实现更丰富的效果。</p> |
| |
| <p>例如,制作农历:</p> |
| <div class="ec-lazy" data-thumb="http://echarts.baidu.com/gallery/data/thumb/bubble-gradient.png" data-src="http://echarts.baidu.com/gallery/view.html?c=calendar-lunar&amp;edit=1&amp;reset=1" style="width: 100%; height: 500px"></div> |
| |
| <p>下面这个例子,使用 <code class="highlighter-rouge">chart.convertToPixel</code> 接口,实现了饼图放置在日历坐标系中的效果。</p> |
| <div class="ec-lazy" data-thumb="http://echarts.baidu.com/gallery/data/thumb/bubble-gradient.png" data-src="http://echarts.baidu.com/gallery/view.html?c=calendar-pie&amp;edit=1&amp;reset=1" style="width: 100%; height: 640px"></div> |
| |
| <h2 id="坐标轴指示器">坐标轴指示器</h2> |
| |
| <p>坐标轴指示器 (axisPointer)指的是,鼠标悬浮到坐标系上时出现的竖线、阴影区域等。它能帮助用户观察数据。echarts 原有的坐标轴指示器本次被整理和增强了,加入了文本标签,自动吸附到数据,以及移动触屏的手柄拖拽交互,以及支持了多个坐标系中指示器的联动。</p> |
| |
| <p>下面是一个K线图的示例。使用坐标轴指示器,能够比较方便得观察到每一项对应的 y 值。</p> |
| <div class="ec-lazy" data-thumb="http://echarts.baidu.com/gallery/data/thumb/bubble-gradient.png" data-src="http://echarts.baidu.com/gallery/view.html?c=doc-example/candlestick-axisPointer&amp;edit=1&amp;reset=1" style="width: 100%; height: 450px"></div> |
| |
| <p>上例中,使用了 <a href="http://echarts.baidu.com/option.html#axisPointer.link">axisPointer.link</a> 来关联上下两个直角坐标系的 axisPointer,使他们同步运动。</p> |
| |
| <p>坐标轴指示器也提供了一种适合触屏的交互方式,使用手柄来拖拽坐标轴指示器。如果触屏上和鼠标操作一样,在坐标系内部拖拽操作坐标轴指示器,那么手指可能会挡住图表,并且可能和『数据区域缩放移动』操作冲突。用单独的拖拽手柄,可以改善这个问题。</p> |
| |
| <div class="ec-lazy" data-thumb="http://echarts.baidu.com/gallery/data/thumb/bubble-gradient.png" data-src="http://echarts.baidu.com/gallery/view.html?c=line-tooltip-touch&amp;edit=1&amp;reset=1" style="width: 100%; height: 400px"></div> |
| |
| <p>这是另一个例子:</p> |
| <div class="ec-lazy" data-thumb="http://echarts.baidu.com/gallery/data/thumb/bubble-gradient.png" data-src="http://echarts.baidu.com/gallery/view.html?c=candlestick-touch&amp;edit=1&amp;reset=1" style="width: 100%; height: 400px"></div> |
| |
| <p>坐标轴指示器在多轴的场景能起到辅助作用,清晰得显示出对比数值,甚至可以在坐标轴指示器的文本标签内定制表达更多信息:</p> |
| |
| <div class="ec-lazy" data-thumb="http://echarts.baidu.com/gallery/data/thumb/bubble-gradient.png" data-src="http://echarts.baidu.com/gallery/view.html?c=multiple-y-axis&amp;edit=1&amp;reset=1" style="width: 100%; height: 300px"></div> |
| |
| <div class="ec-lazy" data-thumb="http://echarts.baidu.com/gallery/data/thumb/bubble-gradient.png" data-src="http://echarts.baidu.com/gallery/view.html?c=multiple-x-axis&amp;edit=1&amp;reset=1" style="width: 100%; height: 300px"></div> |
| |
| <p>最后提供一个内容更丰富些的例子,其中也使用了 <a href="http://echarts.baidu.com/option.html#axisPointer.link">axisPointer.link</a> 来联动不同的坐标轴指示器。他关联和高亮了处于不同坐标系中的相互对应的点。</p> |
| |
| <div class="ec-lazy" data-thumb="http://echarts.baidu.com/gallery/data/thumb/bubble-gradient.png" data-src="http://echarts.baidu.com/gallery/view.html?c=scatter-nutrients-matrix&amp;edit=1&amp;reset=1" style="width: 100%; height: 640px"></div></content><author><name>{"dingding"=>{"name"=>"王俊婷", "title"=>"ECharts 设计师", "web"=>"https://www.behance.net/wjtjiayouac8aa", "image"=>"http://echarts.baidu.com/images/people/王俊婷.png", "desc"=>"喜欢神游的女子一枚,又名王叮叮"}}</name></author><category term="新版本" /><category term="扩展" /><category term="教程" /><summary>在 ECharts 新发布的 3.5 版本中,新增了日历坐标系,增强了坐标轴指示器。同时,ECharts 统计扩展 1.0 版本发布了。日历坐标系用于在日历中绘制图表,坐标轴指示器方便用户观察数据内容,统计扩展是一个专门用来进行数据分析的工具。</summary><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://echarts.baidu.com/blog{"feature"=>"post/2017-03-23/banner.png"}" /></entry><entry><title>ECharts v3.5 Released, Publishing Calendar Coordinate System and Enhanced Axis Pointer, Meanwhile Statistic Extension v1.0 Released</title><link href="http://echarts.baidu.com/blog/2017/03/23/new-release-en.html" rel="alternate" type="text/html" title="ECharts v3.5 Released, Publishing Calendar Coordinate System and Enhanced Axis Pointer, Meanwhile Statistic Extension v1.0 Released" /><published>2017-03-23T00:00:00+08:00</published><updated>2017-03-23T00:00:00+08:00</updated><id>http://echarts.baidu.com/blog/2017/03/23/new-release-en</id><content type="html" xml:base="http://echarts.baidu.com/blog/2017/03/23/new-release-en.html"><p>We are releasing <a href="https://github.com/ecomfe/echarts/releases/tag/3.5.0">ECharts v3.5</a>, where calendar coodinate system is supported and axis pointer is enhanced. Meanwhile <a href="https://github.com/ecomfe/echarts-stat">ECharts statistic extension</a> v1.0 is published.</p> |
| |
| <p>Calendar coordiante system is a new type of echarts coordiante system, which can used to locate different charts (For example, scatter, heatmap, graph, pie, or even other coordinate systems like cartesian).</p> |
| |
| <p>The original axis pointer is enhance significantly, which currently supports text label, a new interaction approach for touch device, and other detailed configurations. Besides, that synchronization between axis pointers of different coordinate systems is supported.</p> |
| |
| <p>Statistic extension is a JavaScript liberary for statistics and data mining, including two-dimensional regression, multi-dimensional clustering and some commonly used statistical functions in v1.0.</p> |
| |
| <h2 id="statistical-extension">Statistical Extension</h2> |
| |
| <p>Statistical extension is a statistical and data mining tool for <a href="https://github.com/ecomfe/echarts">echarts</a>. At present, it mainly includes two-dimensional regression, multi-dimensional clustering and some commonly used statistical functions.</p> |
| |
| <p>The regression algorithm in the extension not only contains the commonly used linear regression, but also contains exponential regression, logarithmic regression, and polynomial regression.</p> |
| |
| <p>An example of linear regression:</p> |
| <div class="ec-lazy" data-thumb="http://echarts.baidu.com/blog/images/post/2017-03-23/xS1bQ2AMKe.png" data-src="http://gallery.echartsjs.com/view.html?cid=xS1bQ2AMKe" style="width: 100%; height: 400px"></div> |
| |
| <p>An example of logarithmic regression:</p> |
| <div class="ec-lazy" data-thumb="http://echarts.baidu.com/blog/images/post/2017-03-23/xry3aWkmYe.png" data-src="http://gallery.echartsjs.com/view.html?cid=xry3aWkmYe" style="width: 100%; height: 400px"></div> |
| |
| <p>Adhering to the purpose of visual analysis, our multi-dimensional clustering analysis, can not only statically produce the results of clustering of dataset, but also dynamically view the entire clustering analysis process.</p> |
| |
| <p>An example of the result of dataset clustering:</p> |
| <div class="ec-lazy" data-thumb="http://echarts.baidu.com/blog/images/post/2017-03-23/xSkBOEaGtx.png" data-src="http://gallery.echartsjs.com/view.html?cid=xSkBOEaGtx" style="width: 100%; height: 400px"></div> |
| |
| <p>An example demonstrating the entire process of clustering:</p> |
| <div class="ec-lazy" data-thumb="http://echarts.baidu.com/blog/images/post/2017-03-23/xHyr-esMtg.png" data-src="http://gallery.echartsjs.com/view.html?cid=xHyr-esMtg" style="width: 100%; height: 400px"></div> |
| |
| <p>Unlike built-in charts in echarts, Statistical Extension is a extension of echarts, which is not intergrated by echarts by default, and you need to inclued <code class="highlighter-rouge">ecStat.js</code> after <code class="highlighter-rouge">echarts.js</code>. You can find the file <code class="highlighter-rouge">dist/ecStat.js</code> in the latest released version at <a href="https://github.com/ecomfe/echarts-stat/releases/latest">here (GitHub)</a>.</p> |
| |
| <p>If you would like to know more, please visit the <a href="https://github.com/ecomfe/echarts-stat">Statistical Extension GitHub Home</a></p> |
| |
| <h2 id="calendar-coordinate-system">Calendar Coordinate System</h2> |
| |
| <p>Calendar coordiante system is a new type of echarts coordiante system, which can used to locate different charts (For example, scatter, heatmap, graph, pie, or even other coordinate systems like cartesian).</p> |
| |
| <p>Using heatmap in calendar:</p> |
| <div class="ec-lazy" data-thumb="https://ecomfe.github.io/echarts-examples/public/data/thumb/bubble-gradient.png" data-src="https://ecomfe.github.io/echarts-examples/public/view.html?c=calendar-heatmap&amp;edit=1&amp;reset=1" style="width: 100%; height: 300px"></div> |
| |
| <p>Using scatter in calendar:</p> |
| <div class="ec-lazy" data-thumb="https://ecomfe.github.io/echarts-examples/public/data/thumb/bubble-gradient.png" data-src="https://ecomfe.github.io/echarts-examples/public/view.html?c=calendar-effectscatter&amp;edit=1&amp;reset=1" style="width: 100%; height: 600px"></div> |
| |
| <p>Different types of chart can be place on calendar coordinate system together.</p> |
| |
| <p>Both place heatmap and graph chart in calendar:</p> |
| <div class="ec-lazy" data-thumb="https://ecomfe.github.io/echarts-examples/public/data/thumb/bubble-gradient.png" data-src="https://ecomfe.github.io/echarts-examples/public/view.html?c=calendar-graph&amp;edit=1&amp;reset=1" style="width: 100%; height: 600px"></div> |
| |
| <p><strong>Calendar layout:</strong></p> |
| |
| <p>Calendar coordinate system can be placed horizontally or vertically. By convention, the heatmap calendar is horizontal. But if we need bigger cell size in other cases, the total width may be too wide. So <a href="https://ecomfe.github.io/echarts-doc/public/en/option.html#calendar.orient">calendar.orient</a> can help in this case.</p> |
| |
| <p><strong>Adapt to container size:</strong></p> |
| |
| <p>Calendar coordinate system can be configured to adapt to container size, which is useful when page size is not sure. First of all, like other components, those location and size configurations can be specified on canlendar: <a href="https://ecomfe.github.io/echarts-doc/public/en/option.html#calendar.left">left</a>, <a href="https://ecomfe.github.io/echarts-doc/public/en/option.html#calendar.right">right</a>, <a href="https://ecomfe.github.io/echarts-doc/public/en/option.html#calendar.top">top</a>, <a href="bottom">bottom</a>, <a href="https://ecomfe.github.io/echarts-doc/public/en/option.html#calendar.width">width</a>, <a href="https://ecomfe.github.io/echarts-doc/public/en/option.html#calendar.height">height</a>, which make calendar possible to modify its size according to container size. Besides, <a href="https://ecomfe.github.io/echarts-doc/public/en/option.html#calendar.cellSize">cellSize</a> can be specified to fix the size of each cell of calendar.</p> |
| |
| <p><strong>More effects:</strong></p> |
| |
| <p>Feel free to combination charts and calendar coordinate systems. You may achieve awesome effects.</p> |
| |
| <p>For example, using API <code class="highlighter-rouge">chart.convertToPixel</code> to locate pie charts on calendar.</p> |
| <div class="ec-lazy" data-thumb="https://ecomfe.github.io/echarts-examples/public/data/thumb/bubble-gradient.png" data-src="https://ecomfe.github.io/echarts-examples/public/view.html?c=calendar-pie&amp;edit=1&amp;reset=1" style="width: 100%; height: 640px"></div> |
| |
| <h2 id="axis-pointer">Axis Pointer</h2> |
| |
| <p>The term “Axis Pointer” refers the appearing line, shadow block and text label when mouse hovering or clicking on a coordinate system, which helps users to have insight into the data.</p> |
| |
| <p>The original axis pointer is enhance significantly, which currently supports text label, a new approach of interaction on touch device, and other detailed configurations. Besides, that synchronization between axis pointers of different coordinate systems is supported.</p> |
| |
| <p>An example, where axis pointers can be displayed in candlestick.</p> |
| <div class="ec-lazy" data-thumb="https://ecomfe.github.io/echarts-examples/public/data/thumb/bubble-gradient.png" data-src="https://ecomfe.github.io/echarts-examples/public/view.html?c=doc-example/candlestick-axisPointer&amp;edit=1&amp;reset=1" style="width: 100%; height: 450px"></div> |
| |
| <p>In the example above, <a href="https://ecomfe.github.io/echarts-doc/public/en/option.html#axisPointer.link">axisPointer.link</a> is used to synchronize axes from the two different cartesian coordiante system.</p> |
| |
| <p>Besides, a approach of interaction on touch devices is supported, where axis pointer is alwayed displayed, and a handle button can be dragged to move the axis pointer, which makes the finger not block the view to charts any more.</p> |
| |
| <div class="ec-lazy" data-thumb="https://ecomfe.github.io/echarts-examples/public/data/thumb/bubble-gradient.png" data-src="https://ecomfe.github.io/echarts-examples/public/view.html?c=line-tooltip-touch&amp;edit=1&amp;reset=1" style="width: 100%; height: 400px"></div> |
| |
| <p>This is another example:</p> |
| <div class="ec-lazy" data-thumb="http://echarts.baidu.com/gallery/data/thumb/bubble-gradient.png" data-src="http://echarts.baidu.com/gallery/view.html?c=candlestick-touch&amp;edit=1&amp;reset=1" style="width: 100%; height: 400px"></div> |
| |
| <p>These examples demonstrating the effect of mutiple axes with axis pointers:</p> |
| |
| <div class="ec-lazy" data-thumb="https://ecomfe.github.io/echarts-examples/public/data/thumb/bubble-gradient.png" data-src="https://ecomfe.github.io/echarts-examples/public/view.html?c=multiple-y-axis&amp;edit=1&amp;reset=1" style="width: 100%; height: 300px"></div> |
| |
| <div class="ec-lazy" data-thumb="https://ecomfe.github.io/echarts-examples/public/data/thumb/bubble-gradient.png" data-src="https://ecomfe.github.io/echarts-examples/public/view.html?c=multiple-x-axis&amp;edit=1&amp;reset=1" style="width: 100%; height: 300px"></div> |
| |
| <p>At last, let’s see a more complicated example, where <a href="https://ecomfe.github.io/echarts-doc/public/en/option.html#axisPointer.link">axisPointer.link</a> is also be used to synchronize axis pointers of different axes.</p> |
| |
| <div class="ec-lazy" data-thumb="https://ecomfe.github.io/echarts-examples/public/data/thumb/bubble-gradient.png" data-src="https://ecomfe.github.io/echarts-examples/public/view.html?c=scatter-nutrients-matrix&amp;edit=1&amp;reset=1" style="width: 100%; height: 640px"></div></content><author><name>{"dingding"=>{"name"=>"王俊婷", "title"=>"ECharts 设计师", "web"=>"https://www.behance.net/wjtjiayouac8aa", "image"=>"http://echarts.baidu.com/images/people/王俊婷.png", "desc"=>"喜欢神游的女子一枚,又名王叮叮"}}</name></author><category term="en" /><category term="new release" /><category term="extension" /><category term="tutorial" /><summary>We are releasing ECharts v3.5, where calendar coodinate system is supported and axis pointer is enhanced. Meanwhile ECharts statistic extension v1.0 is published.</summary><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://echarts.baidu.com/blog{"feature"=>"post/2017-01-13-new-release-theme-river.png"}" /></entry><entry><title>可视化中的数据</title><link href="http://echarts.baidu.com/blog/2017/03/15/echarts-dataAbstraction-tutorial.html" rel="alternate" type="text/html" title="可视化中的数据" /><published>2017-03-15T00:00:00+08:00</published><updated>2017-03-15T00:00:00+08:00</updated><id>http://echarts.baidu.com/blog/2017/03/15/echarts-dataAbstraction-tutorial</id><content type="html" xml:base="http://echarts.baidu.com/blog/2017/03/15/echarts-dataAbstraction-tutorial.html"><p>当下随着大数据热潮的到来,数据可视化作为一个新兴的领域,受到了学术界和工业界的重视。从可视分析、数据新闻到商业报表,各个领域都在越来越多的使用它。既然是数据可视化,说明数据是主体,可视化只是将数据以可视的形式表达的手段。接下来小编就与大家一起揭开可视化中数据的面纱,一探究竟。</p> |
| |
| <h2 id="可视化什么数据抽象">可视化什么:数据抽象</h2> |
| |
| <p>既然是数据可视化,无可非议,可视化的元素肯定是数据,这里所指的数据是广义上的数据,包括文本、图片、声音等超媒体数据。ECharts在可视化过程中所涉及的四种基本数据集类型分别是表格数据、网状数据、场数据和几何空间(spatial)数据,像集合、列表等也是常用的数据集类型。这些基本数据集类型又是由不同的数据类组合构成的,这里的数据类是指可视化中所涉及的数据种类,主要包括四种数据类,分别是数据项、数据项的属性、链接(links)、位置。数据项的属性又可分为类别型和有序型两种,其中有序型又进一步细分为序数型和数值型,下面将分别介绍数据类,数据集类型,以及属性类型。</p> |
| |
| <h3 id="数据类">数据类</h3> |
| |
| <p>本文主要讨论ECharts中所涉及的四种基本数据类,分别是数据项、数据项的属性、链接、位置。数据项是指一个独立的实体,如关系数据表中的一行,或网络中的一个节点;属性是数据项的某个可被观测的特性,如年龄,性别等;链接是指数据项之间的关系,该数据类型在网状关系型数据集中用的比较多;位置是地理空间数据类型,指代二维或三维空间中的某个具体位置;下图展示了四种不同的数据集类型所包含的数据类。</p> |
| |
| <p><img src="http://echarts.baidu.com/blog/images/post/2017-03-15-echarts-dataAbstraction-tutorial-datatypes.png" alt="data" /></p> |
| |
| <h3 id="数据集类型">数据集类型</h3> |
| |
| <p>数据集是指为了分析而收集的任何信息,数据集包括数据表,网状数据,场数据(本文主要关注信息可视化,而场数据主要应用于科学可视化,因而在此不作介绍)以及几何空间数据这四种基本类型,而现实世界中的数据集一般是由这四个基本类型中的一个或多个组合而成的。下图展示了四种不同数据集类型具体的内部结构。</p> |
| |
| <p><img src="http://echarts.baidu.com/blog/images/post/2017-03-15-echarts-dataAbstraction-tutorial-dataset.png" alt="data" /></p> |
| |
| <h4 id="数据表">数据表</h4> |
| |
| <p>数据表是常用的数据集形式,由行和列组成。对于简单的扁平表格来说,每一行代表一个数据项,每一列代表一个属性,表格中的每一个单元格是由行号和列号索引的,保存着某个数据项的某个属性值;多维数据表在数据仓库中用的比较多,具有复杂的结构以及复杂的索引机制,一般来说,简单扁平表格至多具有一个键属性(key attribute),而多维表格具有多个键属性。</p> |
| |
| <h4 id="网状数据">网状数据</h4> |
| |
| <p>网状数据主要用来表明数据项之间具有某种关系,在网状数据中数据项通常被称为节点,两个节点之间的关系被称为链接,也就是网络中的边,并且节点和链接都可以拥有与之相关联的属性。树是一种具有层次结构的特殊类型网络数据,与一般网络数据相比,树没有回路,每一个子节点都对应唯一的一个父节点。</p> |
| |
| <h4 id="几何空间spatial数据">几何空间(spatial)数据</h4> |
| |
| <p>几何空间结构数据通过明确的几何空间位置指定数据项的形状信息,这些数据项可以是空间中的点、一维的直线或曲线、二维的平面或区域,以及三维的立方体。空间数据在不同的度量尺度上具有层级结构。这种层级结构要么是原始数据集固有的,要么是从原始数据集派生出来的。 |
| 可视化中的数据主要以两种形式存在,一种是静态的数据文件,一种是动态的数据流。静态的数据文件是指可以同时获得完整的数据文件,而动态的数据流是指数据在不断的更新和变化。</p> |
| |
| <h3 id="属性类型">属性类型</h3> |
| |
| <p>属性类型主要分为类别型和有序型两种,有序型又可进一步分为序数型和数值型。有序型数据的排列方向有三种,分别是单向型,有公共零点的双向型,以及环状周期型,如下图所示,除此之外,属性也可能有层级结构。 |
| 类别型属性是指名称上的不同,属性的值之间没有明确的排序,例如喜欢的球类运动包括足球、篮球、排球等。虽然类别型属性内部没有明确的排序,但任意外部的排序机制可以被应用在类别型属性上,如将球类运动的名字按字母顺序排列。 |
| 有序型属性包括序数型属性和数值型属性,所有有序型属性都有隐含的排列顺序。对于序数型属性,如小中大,虽然我们不能对它进行完全的算术运算,但在属性的内部有明确定义的顺序,如大减去中并不是有意义的概念,但我们知道中介于大和小之间。数值属性与序数属性不同,它具有大小和量级的明确度量,并且支持算术比较,一般以整数和实数形式存在,如76米减去34米是个有意义的数值,并且它们之间的差是可以被度量的,像温度、高度、长度等都是数值属性。 |
| 有序型数据可以是单向的有序序列,比如人的年龄,只能往一个方向递增,也可以是有公共零点的对向序列,如温度。有序型数据也可以是环状周期的,如时间相关的属性。 |
| 在单个属性内部或者多个属性之间可能具有层级结构,如北京一年的交通事故数量,这是一个时间序列数据,具有时间属性,可以分层级聚合,可以分别按周、月、年聚合,在不同的时间聚合尺度下可能会发现数据集中有趣的模式。除了时间属性之外,地理空间数据也具有层级结构,如可以细分到省、市、县等。</p> |
| |
| <p><img src="http://echarts.baidu.com/blog/images/post/2017-03-15-echarts-dataAbstraction-tutorial-attribute.png" alt="" /></p> |
| |
| <h2 id="总结">总结</h2> |
| <p>本文简要讨论了可视化中的数据,从数据的种类、数据集的类型以及属性的类型这三个角度阐述了可视化中需要可视表达的数据信息。</p> |
| |
| <h4 id="参考文献">参考文献</h4> |
| |
| <p>[1] Tamara Munzner.Visualization Analysis and Design. CRC Press, 2014.</p></content><author><name>{"dingding"=>{"name"=>"王俊婷", "title"=>"ECharts 设计师", "web"=>"https://www.behance.net/wjtjiayouac8aa", "image"=>"http://echarts.baidu.com/images/people/王俊婷.png", "desc"=>"喜欢神游的女子一枚,又名王叮叮"}}</name></author><category term="可视化" /><category term="教程" /><summary>当下随着大数据热潮的到来,数据可视化作为一个新兴的领域,受到了学术界和工业界的重视。从可视分析、数据新闻到商业报表,各个领域都在越来越多的使用它。既然是数据可视化,说明数据是主体,可视化只是将数据以可视的形式表达的手段。接下来小编就与大家一起揭开可视化中数据的面纱,一探究竟。</summary><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://echarts.baidu.com/blog{"feature"=>"post/2017-03-15-echarts-dataAbstraction-tutorial-dataset.png"}" /></entry><entry><title>ECharts 水球图教程</title><link href="http://echarts.baidu.com/blog/2017/02/21/echarts-liquidfill-chart-tutorial.html" rel="alternate" type="text/html" title="ECharts 水球图教程" /><published>2017-02-21T00:00:00+08:00</published><updated>2017-02-21T00:00:00+08:00</updated><id>http://echarts.baidu.com/blog/2017/02/21/echarts-liquidfill-chart-tutorial</id><content type="html" xml:base="http://echarts.baidu.com/blog/2017/02/21/echarts-liquidfill-chart-tutorial.html"><p>水球图是一种适合于展现单个百分比数据的图表类型,ECharts 的<a href="https://github.com/ecomfe/echarts-liquidfill">水球图插件</a>使你能够通过非常简单的配置,实现酷炫的数据展示效果。</p> |
| |
| <iframe style="width: 100%; height: 350px" src="http://gallery.echartsjs.com/view.html?cid=liquidfill-basic"></iframe> |
| |
| <p>那么,今天我们就一起来学习一下,如何使用 ECharts 水球图。</p> |
| |
| <h2 id="第一步引入-javascript-文件">第一步:引入 JavaScript 文件</h2> |
| |
| <p>ECharts 的水球图是一个<em>插件</em>类型的图表。这意味着,在 ECharts 官网下载的完整版本将不包含水球图——这保证了不需要使用该图表的用户能够获得一个尽可能小的代码版本。使用时,需要在引入 <code class="highlighter-rouge">echarts.js</code> 之后,另外引入水球图对应的 <code class="highlighter-rouge">echarts-liquidfill.js</code>,可以在 <a href="https://github.com/ecomfe/echarts-liquidfill/tree/gh-pages/dist">GitHub</a> 找到最新版本。</p> |
| |
| <div class="language-html highlighter-rouge"><pre class="highlight"><code><span class="nt">&lt;script </span><span class="na">src=</span><span class="s">"echarts.js"</span><span class="nt">&gt;&lt;/script&gt;</span> |
| <span class="nt">&lt;script </span><span class="na">src=</span><span class="s">"echarts-liquidfill.js"</span><span class="nt">&gt;&lt;/script&gt;</span> |
| |
| <span class="nt">&lt;script&gt;</span> |
| <span class="c1">// 使用水球图的代码</span> |
| <span class="nt">&lt;/script&gt;</span> |
| </code></pre> |
| </div> |
| |
| <h2 id="第二步指定-dom-元素作为图表容器">第二步:指定 DOM 元素作为图表容器</h2> |
| |
| <p>和创建 ECharts 的其他图表一样,我们需要指定 DOM 中的一个有高度和宽度的元素作为图表的容器——也就是图表将会绘制的位置。</p> |
| |
| <div class="language-html highlighter-rouge"><pre class="highlight"><code><span class="nt">&lt;div</span> <span class="na">id=</span><span class="s">"liquidfill-chart"</span> <span class="na">style=</span><span class="s">"width=100%; height = 400px"</span><span class="nt">&gt;&lt;/div&gt;</span> |
| </code></pre> |
| </div> |
| |
| <p>传入该 DOM 元素,使用 ECharts 初始化图表:</p> |
| |
| <div class="language-js highlighter-rouge"><pre class="highlight"><code><span class="kd">var</span> <span class="nx">chart</span> <span class="o">=</span> <span class="nx">echarts</span><span class="p">.</span><span class="nx">init</span><span class="p">(</span><span class="nb">document</span><span class="p">.</span><span class="nx">getElementById</span><span class="p">(</span><span class="s1">'liquidfill-chart'</span><span class="p">));</span> |
| </code></pre> |
| </div> |
| |
| <h2 id="第三步设置水球图参数">第三步:设置水球图参数</h2> |
| |
| <p>和其他 ECharts 图表一样,水球图提供将系列的 <code class="highlighter-rouge">type</code> 指定为 <code class="highlighter-rouge">'liquidFill'</code>(注意大小写)来表明这是一个水球图类型。</p> |
| |
| <p>一个简单的配置项可以是:</p> |
| |
| <div class="language-js highlighter-rouge"><pre class="highlight"><code><span class="kd">var</span> <span class="nx">option</span> <span class="o">=</span> <span class="p">{</span> |
| <span class="na">series</span><span class="p">:</span> <span class="p">[{</span> |
| <span class="na">type</span><span class="p">:</span> <span class="s1">'liquidFill'</span><span class="p">,</span> |
| <span class="na">data</span><span class="p">:</span> <span class="p">[</span><span class="mf">0.6</span><span class="p">,</span> <span class="mf">0.5</span><span class="p">,</span> <span class="mf">0.4</span><span class="p">,</span> <span class="mf">0.3</span><span class="p">]</span> |
| <span class="p">}]</span> |
| <span class="p">};</span> |
| <span class="nx">chart</span><span class="p">.</span><span class="nx">setOption</span><span class="p">(</span><span class="nx">option</span><span class="p">);</span> |
| </code></pre> |
| </div> |
| |
| <p>这样,就能得到文章开头的水球图效果了:</p> |
| |
| <iframe style="width: 100%; height: 350px" src="http://gallery.echartsjs.com/view.html?cid=liquidfill-basic"></iframe> |
| |
| <blockquote> |
| <p>如果发现图表没有正确显示,你可以检查以下几种可能:</p> |
| |
| <ul> |
| <li>JS 文件是否正确加载;</li> |
| <li><code class="highlighter-rouge">echarts</code> 变量是否存在;</li> |
| <li>控制台是否报错(如果报错显示 <code class="highlighter-rouge">liquidFill</code> 系列不存在,则很可能 <code class="highlighter-rouge">echarts-liquidfill.js</code> 没有正确加载);</li> |
| <li>DOM 元素在 <code class="highlighter-rouge">echarts.init</code> 的时候是否有高度和宽度。</li> |
| </ul> |
| </blockquote> |
| |
| <p>可以发现,在上面的代码中,我们只指定了图表类型为 <code class="highlighter-rouge">'liquidFill'</code>,以及把数据设置为 <code class="highlighter-rouge">[0.6, 0.5, 0.4, 0.3]</code>(对应生成的四个波浪),而其他的参数都是预设的。</p> |
| |
| <p>即使不配置很多参数,预设的参数也可以使你获得一个优雅的水球图效果。而如果有特定的需求,ECharts 水球图又支持非常高度定制的效果。下面我们具体说明如何定制化你的水球图。</p> |
| |
| <h2 id="第四步定制化水球图">第四步:定制化水球图</h2> |
| |
| <p>水球图支持非常高度定制化的需求,包括颜色(<code class="highlighter-rouge">color</code>)、大小(<code class="highlighter-rouge">radius</code>)、波的振幅(<code class="highlighter-rouge">amplitude</code>)、波长(<code class="highlighter-rouge">waveLength</code>)、相位(<code class="highlighter-rouge">phase</code>)、周期(<code class="highlighter-rouge">period</code>)、移动方向(<code class="highlighter-rouge">direction</code>)、形状(<code class="highlighter-rouge">shape</code>)、动画(<code class="highlighter-rouge">waveAnimation</code>)等等,完整的配置项参数参见<a href="https://github.com/ecomfe/echarts-liquidfill#api">水球图 API</a>。文档有针对每个配置项的详细说明,这里我们来介绍一些重要的参数。</p> |
| |
| <h3 id="形状与动画">形状与动画</h3> |
| |
| <iframe style="width: 100%; height: 600px" src="http://gallery.echartsjs.com/view.html?cid=xry0tUfcBe"></iframe> |
| |
| <p>除了默认的圆形(<code class="highlighter-rouge">'circle'</code>)水球图,还可以将 <code class="highlighter-rouge">shape</code> 设置为 ECharts <em>Symbol</em> 的其他类型:<code class="highlighter-rouge">'rect'</code>、<code class="highlighter-rouge">'roundRect'</code>、<code class="highlighter-rouge">'triangle'</code>、<code class="highlighter-rouge">'diamond'</code>、<code class="highlighter-rouge">'pin'</code>、<code class="highlighter-rouge">'arrow'</code>。甚至,使用 <code class="highlighter-rouge">'path://...'</code> 的形式,为其<a href="http://gallery.echartsjs.com/editor.html?c=liquidfill-echarts">指定一个 SVG 路径</a>,得到非常酷炫的效果:</p> |
| |
| <iframe style="width: 100%; height: 400px" src="http://gallery.echartsjs.com/view.html?cid=liquidfill-echarts"></iframe> |
| |
| <p>通过将 <code class="highlighter-rouge">direction</code> 设为 <code class="highlighter-rouge">'left'</code> 或 <code class="highlighter-rouge">'right'</code>,指定波浪的移动方向,或者设为 <code class="highlighter-rouge">'none'</code> 表示静止。</p> |
| |
| <p>上面的例子完整的配置项代码为:</p> |
| |
| <div class="language-js highlighter-rouge"><pre class="highlight"><code><span class="c1">// run at: http://gallery.echartsjs.com/editor.html?c=xry0tUfcBe</span> |
| <span class="kd">var</span> <span class="nx">option</span> <span class="o">=</span> <span class="p">{</span> |
| <span class="na">series</span><span class="p">:</span> <span class="p">[{</span> |
| <span class="na">type</span><span class="p">:</span> <span class="s1">'liquidFill'</span><span class="p">,</span> |
| <span class="na">data</span><span class="p">:</span> <span class="p">[</span><span class="mf">0.6</span><span class="p">,</span> <span class="mf">0.5</span><span class="p">,</span> <span class="mf">0.4</span><span class="p">,</span> <span class="mf">0.3</span><span class="p">],</span> |
| <span class="na">radius</span><span class="p">:</span> <span class="s1">'40%'</span><span class="p">,</span> |
| <span class="na">shape</span><span class="p">:</span> <span class="s1">'diamond'</span><span class="p">,</span> |
| <span class="na">center</span><span class="p">:</span> <span class="p">[</span><span class="s1">'25%'</span><span class="p">,</span> <span class="s1">'25%'</span><span class="p">]</span> |
| <span class="p">},</span> <span class="p">{</span> |
| <span class="na">type</span><span class="p">:</span> <span class="s1">'liquidFill'</span><span class="p">,</span> |
| <span class="na">data</span><span class="p">:</span> <span class="p">[</span><span class="mf">0.6</span><span class="p">,</span> <span class="mf">0.5</span><span class="p">,</span> <span class="mf">0.4</span><span class="p">,</span> <span class="mf">0.3</span><span class="p">],</span> |
| <span class="na">direction</span><span class="p">:</span> <span class="s1">'left'</span><span class="p">,</span> |
| <span class="na">radius</span><span class="p">:</span> <span class="s1">'40%'</span><span class="p">,</span> |
| <span class="na">shape</span><span class="p">:</span> <span class="s1">'rect'</span><span class="p">,</span> |
| <span class="na">center</span><span class="p">:</span> <span class="p">[</span><span class="s1">'75%'</span><span class="p">,</span> <span class="s1">'25%'</span><span class="p">]</span> |
| <span class="p">},</span> <span class="p">{</span> |
| <span class="na">type</span><span class="p">:</span> <span class="s1">'liquidFill'</span><span class="p">,</span> |
| <span class="na">data</span><span class="p">:</span> <span class="p">[</span><span class="mf">0.6</span><span class="p">,</span> <span class="mf">0.5</span><span class="p">,</span> <span class="mf">0.4</span><span class="p">,</span> <span class="mf">0.3</span><span class="p">],</span> |
| <span class="na">radius</span><span class="p">:</span> <span class="s1">'40%'</span><span class="p">,</span> |
| <span class="na">shape</span><span class="p">:</span> <span class="s1">'roundRect'</span><span class="p">,</span> |
| <span class="na">center</span><span class="p">:</span> <span class="p">[</span><span class="s1">'25%'</span><span class="p">,</span> <span class="s1">'75%'</span><span class="p">],</span> |
| <span class="na">backgroundStyle</span><span class="p">:</span> <span class="p">{</span> |
| <span class="na">borderColor</span><span class="p">:</span> <span class="s1">'#156ACF'</span><span class="p">,</span> |
| <span class="na">borderWidth</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span> |
| <span class="na">shadowColor</span><span class="p">:</span> <span class="s1">'rgba(0, 0, 0, 0.4)'</span><span class="p">,</span> |
| <span class="na">shadowBlur</span><span class="p">:</span> <span class="mi">20</span> |
| <span class="p">},</span> |
| <span class="na">outline</span><span class="p">:</span> <span class="p">{</span> |
| <span class="na">show</span><span class="p">:</span> <span class="kc">false</span> |
| <span class="p">},</span> |
| <span class="na">waveAnimation</span><span class="p">:</span> <span class="kc">false</span><span class="p">,</span> <span class="c1">// 禁止左右波动</span> |
| <span class="p">},</span> <span class="p">{</span> |
| <span class="na">type</span><span class="p">:</span> <span class="s1">'liquidFill'</span><span class="p">,</span> |
| <span class="na">data</span><span class="p">:</span> <span class="p">[</span><span class="mf">0.6</span><span class="p">,</span> <span class="mf">0.5</span><span class="p">,</span> <span class="mf">0.4</span><span class="p">,</span> <span class="mf">0.3</span><span class="p">],</span> |
| <span class="na">radius</span><span class="p">:</span> <span class="s1">'50%'</span><span class="p">,</span> |
| <span class="na">shape</span><span class="p">:</span> <span class="s1">'pin'</span><span class="p">,</span> |
| <span class="na">center</span><span class="p">:</span> <span class="p">[</span><span class="s1">'75%'</span><span class="p">,</span> <span class="s1">'75%'</span><span class="p">],</span> |
| <span class="na">amplitude</span><span class="p">:</span> <span class="mi">0</span><span class="p">,</span> |
| <span class="na">waveAnimation</span><span class="p">:</span> <span class="kc">false</span><span class="p">,</span> |
| <span class="na">outline</span><span class="p">:</span> <span class="p">{</span> |
| <span class="na">show</span><span class="p">:</span> <span class="kc">false</span> |
| <span class="p">},</span> |
| <span class="na">backgroundStyle</span><span class="p">:</span> <span class="p">{</span> |
| <span class="na">shadowColor</span><span class="p">:</span> <span class="s1">'rgba(0, 0, 0, 0.4)'</span><span class="p">,</span> |
| <span class="na">shadowBlur</span><span class="p">:</span> <span class="mi">20</span> |
| <span class="p">}</span> |
| <span class="p">}]</span> |
| <span class="p">};</span> |
| </code></pre> |
| </div> |
| |
| <h3 id="单个波的配置">单个波的配置</h3> |
| |
| <p>除了对所有水波做的设置之外,每个水波可以进行单独的配置。和 ECharts 的其他配置项一样,对单个数据的配置项将覆盖整个系列的配置项。</p> |
| |
| <iframe style="width: 100%; height: 350px" src="http://gallery.echartsjs.com/view.html?cid=xry6CHNCVl"></iframe> |
| |
| <p>在这个例子中,我们将第二条水波设为红色,并且改变其移动方向。</p> |
| |
| <div class="language-js highlighter-rouge"><pre class="highlight"><code><span class="kd">var</span> <span class="nx">option</span> <span class="o">=</span> <span class="p">{</span> |
| <span class="na">series</span><span class="p">:</span> <span class="p">[{</span> |
| <span class="na">type</span><span class="p">:</span> <span class="s1">'liquidFill'</span><span class="p">,</span> |
| <span class="na">data</span><span class="p">:</span> <span class="p">[</span><span class="mf">0.6</span><span class="p">,</span> <span class="p">{</span> |
| <span class="na">value</span><span class="p">:</span> <span class="mf">0.5</span><span class="p">,</span> |
| <span class="na">direction</span><span class="p">:</span> <span class="s1">'left'</span><span class="p">,</span> |
| <span class="na">itemStyle</span><span class="p">:</span> <span class="p">{</span> |
| <span class="na">normal</span><span class="p">:</span> <span class="p">{</span> |
| <span class="na">color</span><span class="p">:</span> <span class="s1">'red'</span> |
| <span class="p">}</span> |
| <span class="p">}</span> |
| <span class="p">},</span> <span class="mf">0.4</span><span class="p">,</span> <span class="mf">0.3</span><span class="p">]</span> |
| <span class="p">}]</span> |
| <span class="p">};</span> |
| </code></pre> |
| </div> |
| |
| <p>可以发现,原先 <code class="highlighter-rouge">data</code> 中的一项是一个数字,而在需要做特殊定制的数据中,我们将其设置为一个对象,<code class="highlighter-rouge">value</code> 值是原先的数字,其他配置项将覆盖系列配置项的值。</p> |
| |
| <h3 id="文字显示">文字显示</h3> |
| |
| <p>水球图中间的文字有个酷炫的效果,在水波和背景前的文字颜色是不同的,可以通过 <code class="highlighter-rouge">insideColor</code> 设置水波处的文字颜色,<code class="highlighter-rouge">color</code> 设置背景处的文字颜色。</p> |
| |
| <div class="language-js highlighter-rouge"><pre class="highlight"><code><span class="kd">var</span> <span class="nx">option</span> <span class="o">=</span> <span class="p">{</span> |
| <span class="na">series</span><span class="p">:</span> <span class="p">[{</span> |
| <span class="na">type</span><span class="p">:</span> <span class="s1">'liquidFill'</span><span class="p">,</span> |
| <span class="na">radius</span><span class="p">:</span> <span class="s1">'80%'</span><span class="p">,</span> |
| <span class="na">data</span><span class="p">:</span> <span class="p">[</span><span class="mf">0.5</span><span class="p">,</span> <span class="mf">0.45</span><span class="p">,</span> <span class="mf">0.4</span><span class="p">,</span> <span class="mf">0.3</span><span class="p">],</span> |
| <span class="na">label</span><span class="p">:</span> <span class="p">{</span> |
| <span class="na">normal</span><span class="p">:</span> <span class="p">{</span> |
| <span class="na">textStyle</span><span class="p">:</span> <span class="p">{</span> |
| <span class="na">color</span><span class="p">:</span> <span class="s1">'red'</span><span class="p">,</span> |
| <span class="na">insideColor</span><span class="p">:</span> <span class="s1">'yellow'</span><span class="p">,</span> |
| <span class="na">fontSize</span><span class="p">:</span> <span class="mi">50</span> |
| <span class="p">}</span> |
| <span class="p">}</span> |
| <span class="p">}</span> |
| <span class="p">}]</span> |
| <span class="p">};</span> |
| </code></pre> |
| </div> |
| |
| <iframe style="width: 100%; height: 350px" src="http://gallery.echartsjs.com/view.html?cid=xHyUvV_tFe"></iframe> |
| |
| <p>图表中间默认显示百分比数据,如果你需要将其设置为其他文字内容,可以通过 <code class="highlighter-rouge">formatter</code> 指定,这与 ECharts 的其他格式化函数也是相同的。</p> |
| |
| <p><code class="highlighter-rouge">formatter</code> 可以是一个字符串,其中 <code class="highlighter-rouge">'{a}'</code>、<code class="highlighter-rouge">'{b}'</code>、<code class="highlighter-rouge">'{c}'</code> 会被分别替换成系列名称、数据名称、数据值。</p> |
| |
| <p>如:</p> |
| |
| <div class="language-js highlighter-rouge"><pre class="highlight"><code><span class="kd">var</span> <span class="nx">option</span> <span class="o">=</span> <span class="p">{</span> |
| <span class="na">series</span><span class="p">:</span> <span class="p">[{</span> |
| <span class="na">type</span><span class="p">:</span> <span class="s1">'liquidFill'</span><span class="p">,</span> |
| <span class="na">name</span><span class="p">:</span> <span class="s1">'Liquid Fill'</span><span class="p">,</span> |
| <span class="na">data</span><span class="p">:</span> <span class="p">[{</span> |
| <span class="na">name</span><span class="p">:</span> <span class="s1">'First Data'</span><span class="p">,</span> |
| <span class="na">value</span><span class="p">:</span> <span class="mf">0.6</span> |
| <span class="p">},</span> <span class="mf">0.5</span><span class="p">,</span> <span class="mf">0.4</span><span class="p">,</span> <span class="mf">0.3</span><span class="p">],</span> |
| <span class="na">label</span><span class="p">:</span> <span class="p">{</span> |
| <span class="na">normal</span><span class="p">:</span> <span class="p">{</span> |
| <span class="na">formatter</span><span class="p">:</span> <span class="s1">'{a}\n{b}\nValue: {c}'</span><span class="p">,</span> |
| <span class="na">textStyle</span><span class="p">:</span> <span class="p">{</span> |
| <span class="na">fontSize</span><span class="p">:</span> <span class="mi">28</span> |
| <span class="p">}</span> |
| <span class="p">}</span> |
| <span class="p">}</span> |
| <span class="p">}]</span> |
| <span class="p">};</span> |
| </code></pre> |
| </div> |
| |
| <iframe style="width: 100%; height: 350px" src="http://gallery.echartsjs.com/view.html?cid=xHk5831cHg"></iframe> |
| |
| <p>此外,<code class="highlighter-rouge">formatter</code> 也可以是一个函数,以下代码能得到和上面字符串形式同样的效果。</p> |
| |
| <div class="language-js highlighter-rouge"><pre class="highlight"><code><span class="nx">formatter</span><span class="err">:</span> <span class="kd">function</span><span class="p">(</span><span class="nx">param</span><span class="p">)</span> <span class="p">{</span> |
| <span class="k">return</span> <span class="nx">param</span><span class="p">.</span><span class="nx">seriesName</span> <span class="o">+</span> <span class="s1">'\n'</span> |
| <span class="o">+</span> <span class="nx">param</span><span class="p">.</span><span class="nx">name</span> <span class="o">+</span> <span class="s1">'\n'</span> |
| <span class="o">+</span> <span class="s1">'Value:'</span> <span class="o">+</span> <span class="nx">param</span><span class="p">.</span><span class="nx">value</span><span class="p">;</span> |
| <span class="p">}</span> |
| </code></pre> |
| </div> |
| |
| <h2 id="小结">小结</h2> |
| |
| <p>以上,我们介绍了 ECharts 水球图的一些基本用法,希望能够给大家启发,创作出更多波涛汹涌的作品。</p> |
| |
| <p>更完整的配置项请参考 GitHub 上<a href="https://github.com/ecomfe/echarts-liquidfill">详细的文档</a>,或者到 ECharts Gallery 上查看其它<a href="http://gallery.echartsjs.com/explore.html#sort=rank~timeframe=all~query=liquidFill~author=all">水球图作品</a>。</p></content><author><name>{"dingding"=>{"name"=>"王俊婷", "title"=>"ECharts 设计师", "web"=>"https://www.behance.net/wjtjiayouac8aa", "image"=>"http://echarts.baidu.com/images/people/王俊婷.png", "desc"=>"喜欢神游的女子一枚,又名王叮叮"}}</name></author><category term="扩展" /><category term="教程" /><summary>水球图是一种适合于展现单个百分比数据的图表类型,ECharts 的水球图插件使你能够通过非常简单的配置,实现酷炫的数据展示效果。</summary><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://echarts.baidu.com/blog{"feature"=>"post/2017-02-21-echarts-liquidfill-chart-tutorial.gif"}" /></entry><entry><title>ECharts Liquid-fill Chart Tutorial</title><link href="http://echarts.baidu.com/blog/2017/02/21/echarts-liquidfill-chart-tutorial-en.html" rel="alternate" type="text/html" title="ECharts Liquid-fill Chart Tutorial" /><published>2017-02-21T00:00:00+08:00</published><updated>2017-02-21T00:00:00+08:00</updated><id>http://echarts.baidu.com/blog/2017/02/21/echarts-liquidfill-chart-tutorial-en</id><content type="html" xml:base="http://echarts.baidu.com/blog/2017/02/21/echarts-liquidfill-chart-tutorial-en.html"><p>Liquid-fill is a type of charts that are suitable for displaying single percentage data. <a href="https://github.com/ecomfe/echarts-liquidfill">ECharts liquid-fill Chart</a> provides fancy presentation of percentage data through single but power configurations.</p> |
| |
| <iframe style="width: 100%; height: 350px" src="http://gallery.echartsjs.com/view.html?cid=liquidfill-basic"></iframe> |
| |
| <p>Now, let’s learn how to use it.</p> |
| |
| <h2 id="step-1-including-javascript-files">Step 1: Including JavaScript Files</h2> |
| |
| <p>ECharts liquid-fill chart is a <em>plugin</em> for ECharts, which means it is not included in the full version downloaded from official site. This ensures those who don’t need liquid-fill charts can have a smaller package size. When use it, you need to include <code class="highlighter-rouge">echarts-liquidfill.js</code> after <code class="highlighter-rouge">echarts.js</code>, the former of which can be downloaded at <a href="https://github.com/ecomfe/echarts-liquidfill/tree/gh-pages/dist">GitHub</a>.</p> |
| |
| <div class="language-html highlighter-rouge"><pre class="highlight"><code><span class="nt">&lt;script </span><span class="na">src=</span><span class="s">"echarts.js"</span><span class="nt">&gt;&lt;/script&gt;</span> |
| <span class="nt">&lt;script </span><span class="na">src=</span><span class="s">"echarts-liquidfill.js"</span><span class="nt">&gt;&lt;/script&gt;</span> |
| |
| <span class="nt">&lt;script&gt;</span> |
| <span class="c1">// your code here</span> |
| <span class="nt">&lt;/script&gt;</span> |
| </code></pre> |
| </div> |
| |
| <h2 id="step-2-assign-dom-element-as-chart-container">Step 2: Assign DOM Element As Chart Container</h2> |
| |
| <p>We need to assign a DOM element with width and height as chart container, just as we do with other chart types when using ECharts.</p> |
| |
| <div class="language-html highlighter-rouge"><pre class="highlight"><code><span class="nt">&lt;div</span> <span class="na">id=</span><span class="s">"liquidfill-chart"</span> <span class="na">style=</span><span class="s">"width=100%; height = 400px"</span><span class="nt">&gt;&lt;/div&gt;</span> |
| </code></pre> |
| </div> |
| |
| <p>Use the DOM element to init chart.</p> |
| |
| <div class="language-js highlighter-rouge"><pre class="highlight"><code><span class="kd">var</span> <span class="nx">chart</span> <span class="o">=</span> <span class="nx">echarts</span><span class="p">.</span><span class="nx">init</span><span class="p">(</span><span class="nb">document</span><span class="p">.</span><span class="nx">getElementById</span><span class="p">(</span><span class="s1">'liquidfill-chart'</span><span class="p">));</span> |
| </code></pre> |
| </div> |
| |
| <h2 id="step-3-configure-the-chart">Step 3: Configure The Chart</h2> |
| |
| <p>We set the chart series <code class="highlighter-rouge">type</code> to be <code class="highlighter-rouge">'liquidFill'</code> to use it.</p> |
| |
| <p>A simple configuration item may be:</p> |
| |
| <div class="language-js highlighter-rouge"><pre class="highlight"><code><span class="kd">var</span> <span class="nx">option</span> <span class="o">=</span> <span class="p">{</span> |
| <span class="na">series</span><span class="p">:</span> <span class="p">[{</span> |
| <span class="na">type</span><span class="p">:</span> <span class="s1">'liquidFill'</span><span class="p">,</span> |
| <span class="na">data</span><span class="p">:</span> <span class="p">[</span><span class="mf">0.6</span><span class="p">,</span> <span class="mf">0.5</span><span class="p">,</span> <span class="mf">0.4</span><span class="p">,</span> <span class="mf">0.3</span><span class="p">]</span> |
| <span class="p">}]</span> |
| <span class="p">};</span> |
| <span class="nx">chart</span><span class="p">.</span><span class="nx">setOption</span><span class="p">(</span><span class="nx">option</span><span class="p">);</span> |
| </code></pre> |
| </div> |
| |
| <p>Thus, we can get the liquid-fill chart at the beginning of this post.</p> |
| |
| <iframe style="width: 100%; height: 350px" src="http://gallery.echartsjs.com/view.html?cid=liquidfill-basic"></iframe> |
| |
| <blockquote> |
| <p>If the chart doesn’t display as expected, you may check the following things:</p> |
| |
| <ul> |
| <li>Whether JS files are loaded correctly;</li> |
| <li>Whether <code class="highlighter-rouge">echarts</code> variable exists;</li> |
| <li>Whether there are error messages in Console;</li> |
| <li>Whether the DOM element has width and height when init.</li> |
| </ul> |
| </blockquote> |
| |
| <p>As you can see, we only assigned series type to be <code class="highlighter-rouge">'liquidFill'</code>, and set the data to be <code class="highlighter-rouge">[0.6, 0.5, 0.4, 0.3]</code>, which generate the four waves in the chart. Other parameters are all by default.</p> |
| |
| <p>Even without much configuration, you may get an elegant liquid-fill chart with default parameters. And if you have specific demands, you may easily acheive them with our configuration. Here is how to customerize it.</p> |
| |
| <h2 id="step-4-customerize-the-chart">Step 4: Customerize The Chart</h2> |
| |
| <p>ECharts liquid-fill chart supports highly customizable configuration, including color, radius, amplitude, wave length, phase, period, wave direction, shape, wave animation and so on. Full configuration please refer to <a href="https://github.com/ecomfe/echarts-liquidfill#api">API</a>. Here, we are going to introduces some important parameters.</p> |
| |
| <h3 id="shape-and-animation">Shape And Animation</h3> |
| |
| <iframe style="width: 100%; height: 600px" src="http://gallery.echartsjs.com/view.html?cid=xry0tUfcBe"></iframe> |
| |
| <p>Besides the default <code class="highlighter-rouge">'circle'</code> shape, it also supports symbols like <code class="highlighter-rouge">'rect'</code>, <code class="highlighter-rouge">'roundRect'</code>, <code class="highlighter-rouge">'triangle'</code>, <code class="highlighter-rouge">'diamond'</code>, <code class="highlighter-rouge">'pin'</code>, and <code class="highlighter-rouge">'arrow'</code>. Even more, you can set it to be an <a href="http://gallery.echartsjs.com/editor.html?c=liquidfill-echarts">SVG path</a> to get some fancy effect.</p> |
| |
| <iframe style="width: 100%; height: 400px" src="http://gallery.echartsjs.com/view.html?cid=liquidfill-echarts"></iframe> |
| |
| <p>By setting <code class="highlighter-rouge">direction</code> to be <code class="highlighter-rouge">'left'</code> or <code class="highlighter-rouge">'right'</code>, we may assign the moving direction of the wave. Or, we can set it to be <code class="highlighter-rouge">'none'</code> for still.</p> |
| |
| <p>Full configuration of the above is:</p> |
| |
| <div class="language-js highlighter-rouge"><pre class="highlight"><code><span class="c1">// run at: http://gallery.echartsjs.com/editor.html?c=xry0tUfcBe</span> |
| <span class="kd">var</span> <span class="nx">option</span> <span class="o">=</span> <span class="p">{</span> |
| <span class="na">series</span><span class="p">:</span> <span class="p">[{</span> |
| <span class="na">type</span><span class="p">:</span> <span class="s1">'liquidFill'</span><span class="p">,</span> |
| <span class="na">data</span><span class="p">:</span> <span class="p">[</span><span class="mf">0.6</span><span class="p">,</span> <span class="mf">0.5</span><span class="p">,</span> <span class="mf">0.4</span><span class="p">,</span> <span class="mf">0.3</span><span class="p">],</span> |
| <span class="na">radius</span><span class="p">:</span> <span class="s1">'40%'</span><span class="p">,</span> |
| <span class="na">shape</span><span class="p">:</span> <span class="s1">'diamond'</span><span class="p">,</span> |
| <span class="na">center</span><span class="p">:</span> <span class="p">[</span><span class="s1">'25%'</span><span class="p">,</span> <span class="s1">'25%'</span><span class="p">]</span> |
| <span class="p">},</span> <span class="p">{</span> |
| <span class="na">type</span><span class="p">:</span> <span class="s1">'liquidFill'</span><span class="p">,</span> |
| <span class="na">data</span><span class="p">:</span> <span class="p">[</span><span class="mf">0.6</span><span class="p">,</span> <span class="mf">0.5</span><span class="p">,</span> <span class="mf">0.4</span><span class="p">,</span> <span class="mf">0.3</span><span class="p">],</span> |
| <span class="na">direction</span><span class="p">:</span> <span class="s1">'left'</span><span class="p">,</span> |
| <span class="na">radius</span><span class="p">:</span> <span class="s1">'40%'</span><span class="p">,</span> |
| <span class="na">shape</span><span class="p">:</span> <span class="s1">'rect'</span><span class="p">,</span> |
| <span class="na">center</span><span class="p">:</span> <span class="p">[</span><span class="s1">'75%'</span><span class="p">,</span> <span class="s1">'25%'</span><span class="p">]</span> |
| <span class="p">},</span> <span class="p">{</span> |
| <span class="na">type</span><span class="p">:</span> <span class="s1">'liquidFill'</span><span class="p">,</span> |
| <span class="na">data</span><span class="p">:</span> <span class="p">[</span><span class="mf">0.6</span><span class="p">,</span> <span class="mf">0.5</span><span class="p">,</span> <span class="mf">0.4</span><span class="p">,</span> <span class="mf">0.3</span><span class="p">],</span> |
| <span class="na">radius</span><span class="p">:</span> <span class="s1">'40%'</span><span class="p">,</span> |
| <span class="na">shape</span><span class="p">:</span> <span class="s1">'roundRect'</span><span class="p">,</span> |
| <span class="na">center</span><span class="p">:</span> <span class="p">[</span><span class="s1">'25%'</span><span class="p">,</span> <span class="s1">'75%'</span><span class="p">],</span> |
| <span class="na">backgroundStyle</span><span class="p">:</span> <span class="p">{</span> |
| <span class="na">borderColor</span><span class="p">:</span> <span class="s1">'#156ACF'</span><span class="p">,</span> |
| <span class="na">borderWidth</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span> |
| <span class="na">shadowColor</span><span class="p">:</span> <span class="s1">'rgba(0, 0, 0, 0.4)'</span><span class="p">,</span> |
| <span class="na">shadowBlur</span><span class="p">:</span> <span class="mi">20</span> |
| <span class="p">},</span> |
| <span class="na">outline</span><span class="p">:</span> <span class="p">{</span> |
| <span class="na">show</span><span class="p">:</span> <span class="kc">false</span> |
| <span class="p">},</span> |
| <span class="na">waveAnimation</span><span class="p">:</span> <span class="kc">false</span><span class="p">,</span> <span class="c1">// disable moving</span> |
| <span class="p">},</span> <span class="p">{</span> |
| <span class="na">type</span><span class="p">:</span> <span class="s1">'liquidFill'</span><span class="p">,</span> |
| <span class="na">data</span><span class="p">:</span> <span class="p">[</span><span class="mf">0.6</span><span class="p">,</span> <span class="mf">0.5</span><span class="p">,</span> <span class="mf">0.4</span><span class="p">,</span> <span class="mf">0.3</span><span class="p">],</span> |
| <span class="na">radius</span><span class="p">:</span> <span class="s1">'50%'</span><span class="p">,</span> |
| <span class="na">shape</span><span class="p">:</span> <span class="s1">'pin'</span><span class="p">,</span> |
| <span class="na">center</span><span class="p">:</span> <span class="p">[</span><span class="s1">'75%'</span><span class="p">,</span> <span class="s1">'75%'</span><span class="p">],</span> |
| <span class="na">amplitude</span><span class="p">:</span> <span class="mi">0</span><span class="p">,</span> |
| <span class="na">waveAnimation</span><span class="p">:</span> <span class="kc">false</span><span class="p">,</span> |
| <span class="na">outline</span><span class="p">:</span> <span class="p">{</span> |
| <span class="na">show</span><span class="p">:</span> <span class="kc">false</span> |
| <span class="p">},</span> |
| <span class="na">backgroundStyle</span><span class="p">:</span> <span class="p">{</span> |
| <span class="na">shadowColor</span><span class="p">:</span> <span class="s1">'rgba(0, 0, 0, 0.4)'</span><span class="p">,</span> |
| <span class="na">shadowBlur</span><span class="p">:</span> <span class="mi">20</span> |
| <span class="p">}</span> |
| <span class="p">}]</span> |
| <span class="p">};</span> |
| </code></pre> |
| </div> |
| |
| <h3 id="configuration-for-a-single-wave">Configuration For A Single Wave</h3> |
| |
| <p>Besides the configuration of the waves as introduced above, each single wave can have configuration to be overwritten.</p> |
| |
| <iframe style="width: 100%; height: 350px" src="http://gallery.echartsjs.com/view.html?cid=xry6CHNCVl"></iframe> |
| |
| <p>In this example, we set the second wave to be red, and changed its moving direction.</p> |
| |
| <div class="language-js highlighter-rouge"><pre class="highlight"><code><span class="kd">var</span> <span class="nx">option</span> <span class="o">=</span> <span class="p">{</span> |
| <span class="na">series</span><span class="p">:</span> <span class="p">[{</span> |
| <span class="na">type</span><span class="p">:</span> <span class="s1">'liquidFill'</span><span class="p">,</span> |
| <span class="na">data</span><span class="p">:</span> <span class="p">[</span><span class="mf">0.6</span><span class="p">,</span> <span class="p">{</span> |
| <span class="na">value</span><span class="p">:</span> <span class="mf">0.5</span><span class="p">,</span> |
| <span class="na">direction</span><span class="p">:</span> <span class="s1">'left'</span><span class="p">,</span> |
| <span class="na">itemStyle</span><span class="p">:</span> <span class="p">{</span> |
| <span class="na">normal</span><span class="p">:</span> <span class="p">{</span> |
| <span class="na">color</span><span class="p">:</span> <span class="s1">'red'</span> |
| <span class="p">}</span> |
| <span class="p">}</span> |
| <span class="p">},</span> <span class="mf">0.4</span><span class="p">,</span> <span class="mf">0.3</span><span class="p">]</span> |
| <span class="p">}]</span> |
| <span class="p">};</span> |
| </code></pre> |
| </div> |
| |
| <p>You may notice that an item of the previous <code class="highlighter-rouge">data</code> is a number, but for those to be configured, they are an object containing <code class="highlighter-rouge">value</code>.</p> |
| |
| <h2 id="label">Label</h2> |
| |
| <p>Label of liquid-fill charts have a nice effect that the text colors before wave and background are different. <code class="highlighter-rouge">insideColor</code> can be used to set the text color before wave, and <code class="highlighter-rouge">color</code> can be used to set the color before background.</p> |
| |
| <div class="language-js highlighter-rouge"><pre class="highlight"><code><span class="kd">var</span> <span class="nx">option</span> <span class="o">=</span> <span class="p">{</span> |
| <span class="na">series</span><span class="p">:</span> <span class="p">[{</span> |
| <span class="na">type</span><span class="p">:</span> <span class="s1">'liquidFill'</span><span class="p">,</span> |
| <span class="na">radius</span><span class="p">:</span> <span class="s1">'80%'</span><span class="p">,</span> |
| <span class="na">data</span><span class="p">:</span> <span class="p">[</span><span class="mf">0.5</span><span class="p">,</span> <span class="mf">0.45</span><span class="p">,</span> <span class="mf">0.4</span><span class="p">,</span> <span class="mf">0.3</span><span class="p">],</span> |
| <span class="na">label</span><span class="p">:</span> <span class="p">{</span> |
| <span class="na">normal</span><span class="p">:</span> <span class="p">{</span> |
| <span class="na">textStyle</span><span class="p">:</span> <span class="p">{</span> |
| <span class="na">color</span><span class="p">:</span> <span class="s1">'red'</span><span class="p">,</span> |
| <span class="na">insideColor</span><span class="p">:</span> <span class="s1">'yellow'</span><span class="p">,</span> |
| <span class="na">fontSize</span><span class="p">:</span> <span class="mi">50</span> |
| <span class="p">}</span> |
| <span class="p">}</span> |
| <span class="p">}</span> |
| <span class="p">}]</span> |
| <span class="p">};</span> |
| </code></pre> |
| </div> |
| |
| <iframe style="width: 100%; height: 350px" src="http://gallery.echartsjs.com/view.html?cid=xHyUvV_tFe"></iframe> |
| |
| <p>Label displays percentage data by default. If you want to set it otherwise, you may use <code class="highlighter-rouge">formatter</code> to do this. This is similar to other formatter of ECharts.</p> |
| |
| <p><code class="highlighter-rouge">formatter</code> can be a string, in which <code class="highlighter-rouge">'{a}'</code>, <code class="highlighter-rouge">'{b}'</code>, <code class="highlighter-rouge">'{c}'</code> will be replaced to be series name, data name, and data value.</p> |
| |
| <p>For example:</p> |
| |
| <div class="language-js highlighter-rouge"><pre class="highlight"><code><span class="kd">var</span> <span class="nx">option</span> <span class="o">=</span> <span class="p">{</span> |
| <span class="na">series</span><span class="p">:</span> <span class="p">[{</span> |
| <span class="na">type</span><span class="p">:</span> <span class="s1">'liquidFill'</span><span class="p">,</span> |
| <span class="na">name</span><span class="p">:</span> <span class="s1">'Liquid Fill'</span><span class="p">,</span> |
| <span class="na">data</span><span class="p">:</span> <span class="p">[{</span> |
| <span class="na">name</span><span class="p">:</span> <span class="s1">'First Data'</span><span class="p">,</span> |
| <span class="na">value</span><span class="p">:</span> <span class="mf">0.6</span> |
| <span class="p">},</span> <span class="mf">0.5</span><span class="p">,</span> <span class="mf">0.4</span><span class="p">,</span> <span class="mf">0.3</span><span class="p">],</span> |
| <span class="na">label</span><span class="p">:</span> <span class="p">{</span> |
| <span class="na">normal</span><span class="p">:</span> <span class="p">{</span> |
| <span class="na">formatter</span><span class="p">:</span> <span class="s1">'{a}\n{b}\nValue: {c}'</span><span class="p">,</span> |
| <span class="na">textStyle</span><span class="p">:</span> <span class="p">{</span> |
| <span class="na">fontSize</span><span class="p">:</span> <span class="mi">28</span> |
| <span class="p">}</span> |
| <span class="p">}</span> |
| <span class="p">}</span> |
| <span class="p">}]</span> |
| <span class="p">};</span> |
| </code></pre> |
| </div> |
| |
| <iframe style="width: 100%; height: 350px" src="http://gallery.echartsjs.com/view.html?cid=xHk5831cHg"></iframe> |
| |
| <p>Besides, <code class="highlighter-rouge">formatter</code> can also be a function. The following code provides the same effect as before.</p> |
| |
| <div class="language-js highlighter-rouge"><pre class="highlight"><code><span class="nx">formatter</span><span class="err">:</span> <span class="kd">function</span><span class="p">(</span><span class="nx">param</span><span class="p">)</span> <span class="p">{</span> |
| <span class="k">return</span> <span class="nx">param</span><span class="p">.</span><span class="nx">seriesName</span> <span class="o">+</span> <span class="s1">'\n'</span> |
| <span class="o">+</span> <span class="nx">param</span><span class="p">.</span><span class="nx">name</span> <span class="o">+</span> <span class="s1">'\n'</span> |
| <span class="o">+</span> <span class="s1">'Value:'</span> <span class="o">+</span> <span class="nx">param</span><span class="p">.</span><span class="nx">value</span><span class="p">;</span> |
| <span class="p">}</span> |
| </code></pre> |
| </div> |
| |
| <h2 id="conclusion">Conclusion</h2> |
| |
| <p>In this post, we introduced how to use ECharts liquid-fill charts. Hopefully, you can be inspired by it and create more interesting works.</p> |
| |
| <p>Full document please refer to <a href="https://github.com/ecomfe/echarts-liquidfill">GitHub</a>. And you may go to <a href="http://gallery.echartsjs.com/explore.html#sort=rank~timeframe=all~query=liquidFill~author=all">ECharts Gallery</a> to view more liquid-fill charts.</p></content><author><name>{"dingding"=>{"name"=>"王俊婷", "title"=>"ECharts 设计师", "web"=>"https://www.behance.net/wjtjiayouac8aa", "image"=>"http://echarts.baidu.com/images/people/王俊婷.png", "desc"=>"喜欢神游的女子一枚,又名王叮叮"}}</name></author><category term="en" /><category term="extension" /><category term="tutorial" /><summary>Liquid-fill is a type of charts that are suitable for displaying single percentage data. ECharts liquid-fill Chart provides fancy presentation of percentage data through single but power configurations.</summary><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://echarts.baidu.com/blog{"feature"=>"post/2017-02-21-echarts-liquidfill-chart-tutorial.gif"}" /></entry></feed> |