Skip to content

Instantly share code, notes, and snippets.

@hahwul
Created February 29, 2024 07:48
Show Gist options
  • Save hahwul/1ddaf42056eaea038722f08021276ca8 to your computer and use it in GitHub Desktop.
Save hahwul/1ddaf42056eaea038722f08021276ca8 to your computer and use it in GitHub Desktop.
rails-charts(echarts) auto-resizing
<%= area_chart Rails.cache.read("data1") %>
<%= area_chart Rails.cache.read("data2") %>
<%= area_chart Rails.cache.read("data3") %>
<script>
let eChartTriggerList = document.querySelectorAll('[id^="rails_charts_"]')
window.addEventListener('resize', function() {
let eChartList = [...eChartTriggerList].map(eChartTriggerEl => echarts.init(eChartTriggerEl).resize())
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment