javascript - 点击事件 legendselectchanged 时如何刷新 ECharts
问题描述
ECharts 强制布局。
期待
我想添加一个新功能。当我切换画布顶部的类别按钮时,链接的选定名称将消失/出现。
问题描述
我已经在互联网上检查了 echarts 文档和整个示例,顶部的类别按钮似乎只支持节点,而不支持强制布局中的链接。
所以我想也许我只能在单击按钮时更改链接数据。现在我得到了我想要更改的数据并且必须刷新画布(而不是刷新页面!)
我曾经Chart.setOption(option)
想刷新链接,但似乎出错了
谁能帮我?
可能有两种方法可以解决这个问题,
- 更改数据并刷新画布。
- 也许类别按钮实际上可以切换链接消失或出现只是我不知道该怎么做。
代码
主要设置
var jdata; // ! api.js variable
const Version = 0.1;
const Version_string = `Version ${Version}`
// jQuery ajax data from back-end
const api_url = API_generator(2207, 56, 54, 1000);
GetJSON(api_url);
// init HTML dom
const Chart = echarts.init(document.getElementById('main'));
const backup_data = data_format(jdata);
const data = backup_data;
console.log(data);
var option = {
title: {
text: 'lorem', // this field will connect to the book name
subtext: Version_string,
textStyle: {
fontSize: 32,
fontWeight: 'bolder'
},
subtextStyle : {
fontSize : 15,
fontWeight : 'bolder'
}
},
tooltip: {},
toolbox: {
show: true,
feature: {
saveAsImage: {
show: true,
title: 'save image',
type: 'png'
},
// ! dataView still have to fix
dataView: {
show: true,
title: 'data',
readOnly: false,
lang: ['Detail Data Information', 'Close', 'refresh'],
// TODO : rewrite optionToContent
// optionToContent: function(opt){
// var table = `<table class="dataViewTable">
// <tbody>
// <tr class="dataViewTr">
// <td class="dataViewHead">123</td>
// </tr>
// </tbody>
// </table>`;
// return table;
// }
}
}
},
legend: {
data :data.category
},
series: [{
type: 'graph',
layout: 'force',
name: 'test',
categories: data.category,
nodes: data.nodes,
links: data.links,
itemStyle: {
normal: {
label: {
show: true,
textStyle: {
color: 'white'
}
}
}
},
draggable: true,
symbolSize: 40,
roam: true,
focusNodeAdjacency: true,
force: {
repulsion: 600,
edgeLength: 180
},
// lineStyle: {
// normal: {
// opacity: 1,
// width: 1,
// curveness: 0.5,
// length: 500
// }
// },
edgeSymbol: ['arrow'],
edgeLabel: {
normal: {
show: true,
textStyle: {
fontSize: 15
},
formatter: "{c}"
}
},
}]
}
// ! setup all option
Chart.setOption(option);
事件.js
Chart.on('legendselectchanged', (category_element) => {
const refresh_Chart = echarts.init(document.getElementById('main'));
var temp = data.links.filter(link => {
for(category_element_selected_element of Object.entries(category_element.selected)){
if(category_element_selected_element[0] === link.value && category_element_selected_element[1] == true){
return link;
}
continue;
}
})
console.log(temp);
});
解决方案
推荐阅读
- excel - 组合框更改事件的类模块代码
- javascript - 在 react-native 中使用 firebase 重定向登录用户
- java - 如何从旧版本的 spring mvc 3.0.5 使用/集成 spring security
- xamarin - 适用于 Xamarin 表单的 TokBox OpenTok SDK
- python - 我们如何才能获得存储在 python 对象中的所有内容(或几乎所有内容)的明确列表?
- javascript - npm install github 给出了意外的标识符错误
- javascript - 用 event.stopPropagation() 解决问题
- javascript - 如何缩放条形图列以正确且按比例地放入其容器中?
- swift - iOS 应用上的 Readium 和 Sony URMS 集成
- java - 没有从 jsp 页面得到正确的响应