echarts
echarts copied to clipboard
使用connect,数据为null时不能联动
One-line summary [问题简述]
使用Echarts的connect方法,有柱形图和折线图,当柱形图的数据为null时,点击折线图不能联动。
Version & Environment [版本及环境]
- ECharts version [ECharts 版本]: npm安装,版本3.8.5
- Browser version [浏览器类型和版本]: Google Chrome 版本 63.0.3239.132
- OS Version [操作系统类型和版本]: MACOS 10.12.6
Expected behaviour [期望结果]
柱形图为null时,点击折线图也能联动
ECharts option [ECharts配置项]
由于有两个元素,所以不能直接使用option,写了个demo。
我尝试多种方法(可修改源码中的method)都不能实现我想要的效果。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>echarts-connect</title>
<style>
.my-chart{
width: 700px;
height: 200px;
}
</style>
</head>
<body>
<div id="my-chart1" class="my-chart"></div>
<div id="my-chart2" class="my-chart"></div>
<script src="http://echarts.baidu.com/dist/echarts.min.js"></script>
<script>
let option = {
color: ['#3398DB', '#f97'],
tooltip : {
trigger: 'axis',
triggerOn: 'none',
axisPointer : { // 坐标轴指示器,坐标轴触发有效
type : 'shadow' // 默认为直线,可选为:'line' | 'shadow'
}
},
grid: {
left: '3%',
right: '4%',
bottom: '3%',
containLabel: true
},
xAxis : [
{
type : 'category',
data : ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
axisTick: {
alignWithLabel: true
}
}
],
yAxis : [
{
type : 'value'
}
],
series : [
{
name:'直接访问',
type:'bar',
data:[null, 100, 200, 364, 390, 370, 220]
},
{
name:'直接访问2',
type:'line',
data:[150, 52, 210, 334, 390, 330, 250]
}
]
}
/**
*
* @param id
* @param method 方法
*/
function drawChart(id, method = 2){
const myChart = echarts.init(document.querySelector(id))
myChart.setOption(option, true)
myChart.on('click', (params) => {
// console.log(params)
console.log('method: ' + method)
if(method === 1){
myChart.dispatchAction({
type: 'showTip',
seriesIndex: 0,
dataIndex: params.dataIndex
})
}else if(method === 2){
myChart.dispatchAction({
type: 'showTip',
seriesIndex: 1,
dataIndex: params.dataIndex
})
}else if(method === 3){
const position = myChart.convertToPixel('grid', [params.dataIndex, null])
myChart.dispatchAction({
type: 'showTip',
x: position[0],
y: position[1]
})
}
})
myChart.group = 'group1'
echarts.connect('group1')
}
drawChart('#my-chart1')
drawChart('#my-chart2')
</script>
</body>
</html>
Other comments [其他信息]

我也遇到同样的问题,楼主解决了吗?
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
This issue has been automatically closed because it did not have recent activity. If this remains to be a problem with the latest version of Apache ECharts, please open a new issue and link this to it. Thanks!