Skip to content

Instantly share code, notes, and snippets.

@DaseinUXD
Created March 30, 2017 15:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DaseinUXD/84b13e4009d565ac4edf87141fc1990f to your computer and use it in GitHub Desktop.
Save DaseinUXD/84b13e4009d565ac4edf87141fc1990f to your computer and use it in GitHub Desktop.
JavaScript function to hide the yAxis label when the legend is clicked to hide a data series
echartb.on('legendselectchanged', function(params) {
var legendObject = params.selected; // create variable from the selected: { object }
// console.log(legendObject) // {name: boolean-value, name: boolean-value}
// console.log(Object.values(legendObject)); // log to the console boolean values out of the key: value pair
var value1 = (Object.values(legendObject)[0]); // assign the boolean value in index[0] to value1
var value2 = (Object.values(legendObject)[1]); // assign the boolean value in index[1] to value2
// create a new option object to pass into myChart.setOption()
var option2 = {
yAxis: [{
//show: value1,
axisLabel: {
show: value1 // set axisLabel[0] visability to true | false base on value1
}
}, {
//show: value2,
axisLabel: {
show: value2 // set axisLabel[1] visability to true | false base on value2
}
}]
};
echartb.setOption(option2); // pass new option object into myCharts
// console.log(params.name)
})
@DaseinUXD
Copy link
Author

works with the JavaScript library echarts 3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment