首先因为在echart3.0版本就已经舍弃了和弦图,所以不得不使用echarts2.0
和弦图和饼图类似可以使用center定位,radius控制大小,所以只要设置每个series的这两个值就会在相应位置画出和弦图。
代码如下
option = {
series : [
{
center:["20%","50%"],
type:'chord',
sort : 'ascending',
sortSub : 'descending',
showScale : false,
nodes: [
{name:'a'},
{name:'b'},
],
links: [
{source: 'a', target: 'b', weight: 0.9},
{source: 'b', target: 'a', weight: 0.9},
]
},
{
center:["70%","50%"],
type:'chord',
sort : 'ascending',
sortSub : 'descending',
showScale : false,
nodes: [
{name:'a'},
{name:'b'},
],
links: [
{source: 'a', target: 'b', weight: 0.9},
{source: 'b', target: 'a', weight: 0.9},
]
}
]
};
效果如此:
image.png
第一个series没有被显示。
下面开始解决问题
源码位置:echarts/src/chart/chord.js
问题1: _init方法中

image.png
问题2: _buildChords方法中
因为问题一已经将series分组成了两个series,buildChords方法中也只考虑了series长度为1的情况。最后在输出图表数据的时候如下图所示seriesIndex是错误的。

image.png
以下为解决方案

image.png