I have multiple charts on my dashboard. If I want to :
- hide all charts.
- hide all except one.
- update the single chart and hide others
How can I achieve the above points?
I have multiple charts on my dashboard. If I want to :
How can I achieve the above points?
This has already been answered here: JavaScript hide/show element
typically, you can target the element (a chart in your case) by id:
let chart = document.getElementById('chart');
then set the display to 'none' to hide it:
chart.style.display = 'none'
transversely you can empty out or unset the display value to bring the chart back:
chart.style.display = ''
without seeing your code or what the page looks like that's the best advice I can give.
Below is a really basic example of how to find container by their id and toggle their visibility on buttons:
https://jsfiddle.net/BlackLabel/7wpc26o1/
[document.getElementById('btn1'), document.getElementById('btn2'), document.getElementById('btn3')].forEach((btn, i) => {
let chartContainer = document.getElementById('container' + (i + 1))
btn.addEventListener('click', function() {
console.log(chartContainer.style.display)
if (chartContainer.style.display === 'none') {
chartContainer.style.display = 'block'
} else {
chartContainer.style.display = 'none'
}
})
})
I hope that everything is clear in this example, if not - feel free to ask.