Is your feature request related to a problem? Please describe.
The problem is with a graph I need to update dynamically in a web application where I initialize ApexChart in a module. If I use the option defer, the graph shows first time but it doesn't update dynamically, and if I dont' use the option defer it doesn't show up the first time but it is updated correctly.
To be more concrete:
This is the web application https://github.com/pasosdeJesus/sivel2 (information system to manage cases of political violence) recently updated to rails7, bundling javascript resources with both sprockets and esbuild+jsbundling-rails
I'm initializing Apexchart in the file app/javascript/application.rb (see https://github.com/pasosdeJesus/sivel2/blob/main/app/javascript/application.js ) that in rails7 is run as module after the full HTML has been loaded. (I know I could load and initialize apexchart in the part managed with sprockets but I prefer to do it in the part bundled with jsbundling-rails+esbuild).
If I don't use the defer option, usually the chart is not presented when the route is loaded first time because it tries to use ApexChart before its initialization.
If I use the defer option it is presented the first time correctly but it is not updated automatically when the users selects a new filter or aggregation criteria (because in the controller I use format.js to run a javascript that updates part of the page including the apexchar.rb <script> tag that will not run because it is defered.
Describe the solution you'd like
That I could keep the initialization of Apexchart in a module and at the same time that I could keep using format.js to update dynamically the generation of the chart. (In future I'm planning change format.js for format.html and turbo or javascript).
Describe alternatives you've considered
I have experimented by changing apexchart.rb and found that if the non-defered script created by apexchart.rb has type='module' instead of type='text/javascript' I will have the result I expect, the graph is presented correctly initially and can be updated responding to user input by updating the script.
Analogous to the option defer, I think there should be an option module for the charts of apexchart.rb that would implement this behavior.
Additional context
Wihouth defer it will not present the graph first time:
With defer it will present the chart first time:
but not when the user upates the filter:
Is your feature request related to a problem? Please describe.
The problem is with a graph I need to update dynamically in a web application where I initialize ApexChart in a module. If I use the option
defer
, the graph shows first time but it doesn't update dynamically, and if I dont' use the optiondefer
it doesn't show up the first time but it is updated correctly.To be more concrete:
sprockets
andesbuild
+jsbundling-rails
app/javascript/application.rb
(see https://github.com/pasosdeJesus/sivel2/blob/main/app/javascript/application.js ) that in rails7 is run as module after the full HTML has been loaded. (I know I could load and initialize apexchart in the part managed with sprockets but I prefer to do it in the part bundled with jsbundling-rails+esbuild).bar_chart
(orcolumn_chart
depending on the user input) for authenticated users in the routeconteos/personas
(countings about demography of victims like sex, age, etc.), see https://github.com/pasosdeJesus/sivel2_gen/blob/main/app/views/sivel2_gen/conteos/_personas_grafica.html.erb. This graph can be updated dynamically when the users select different filters or aggregations for the graph (see https://github.com/pasosdeJesus/sivel2_gen/blob/main/app/views/sivel2_gen/conteos/personas.js.erb )defer
option, usually the chart is not presented when the route is loaded first time because it tries to use ApexChart before its initialization.defer
option it is presented the first time correctly but it is not updated automatically when the users selects a new filter or aggregation criteria (because in the controller I useformat.js
to run a javascript that updates part of the page including the apexchar.rb<script>
tag that will not run because it is defered.Describe the solution you'd like
That I could keep the initialization of Apexchart in a module and at the same time that I could keep using
format.js
to update dynamically the generation of the chart. (In future I'm planning changeformat.js
forformat.html
and turbo or javascript).Describe alternatives you've considered
I have experimented by changing
apexchart.rb
and found that if the non-defered script created by apexchart.rb hastype='module'
instead oftype='text/javascript'
I will have the result I expect, the graph is presented correctly initially and can be updated responding to user input by updating the script.Analogous to the option
defer
, I think there should be an optionmodule
for the charts of apexchart.rb that would implement this behavior.Additional context
Wihouth defer it will not present the graph first time:
With
defer
it will present the chart first time: but not when the user upates the filter: