Replies: 10 comments 4 replies
-
@ncs1 We also need this enhancement. Could you share your solution? We are looking into implementing a temporary solution as well |
Beta Was this translation helpful? Give feedback.
-
This seems to work for me, I forked the gem and changed the defer method: |
Beta Was this translation helpful? Give feedback.
-
@toddsutt in first try, I did think it solved the issue. My solution is having an object that keeps track of the graphs and redraw them in turbo event, as I noted I don't think that this is an elegant solution, but it does fix the issue completely. |
Beta Was this translation helpful? Give feedback.
-
@ncs1 Interesting, I haven't run into that yet but I'd definitely be interested in seeing your solution! |
Beta Was this translation helpful? Give feedback.
-
@toddsutt I'll upload it with instructions in the upcoming days. |
Beta Was this translation helpful? Give feedback.
-
@ncs1 It looks like this might work better without having to modify the gem. I have the options in helper methods to keep the view cleaner but then I put this in each view that has charts. Still not the cleanest but it relies more on building charts the way ApexCharts' website suggests: https://apexcharts.com/docs/chart-types/bar-chart/
UPDATE: I am now using this javascript for each of my charts. My charts are each in their own partials with the id variable set
|
Beta Was this translation helpful? Give feedback.
-
@toddsutt , I think I tried something along the lines of your update and I still had graphs redraw on top of each other in case of multiple pages of graphs. Did you try multiple pages of graphs and transition between them successfully ? Here's what I did (again, I don't think that this is elegant, but it works) - I supported both turbolinks and turbo inside:
window.ApexTurboRenderer = _MYAPEXSINGLECLASS;
ApexTurboRenderer.setup_apex();
static apex_graph = []
static setup_apex() {
window.addEventListener('turbo:before-render', () => {
_MYAPEXSINGLECLASS.apex_graph = [];
});
window.addEventListener('turbolinks:before-render', () => {
_MYAPEXSINGLECLASS.apex_graph = [];
});
}
static add_apexobj(obj) {
this.apex_graph.push(obj);
}
static render_apexes() {
for (let index = 0; index < this.apex_graph.length; index++) {
const element = this.apex_graph[index];
try {
let chrt = null;
if (!!Apex && typeof Apex._chartInstances !== 'undefined') {
chrt = ApexCharts.getChartByID(element[0]);
}
if (!!chrt) {
chrt.destroy();
}
} catch (e) {
console.log(e);
}
let chart = new ApexCharts(document.querySelector('#' + element[0]), element[1]);
try {
chart.render();
} catch (e) {
console.log(e);
}
}
_MYAPEXSINGLECLASS.apex_graph = [];
}
<script>
window.addEventListener('load', function cb(event) {
ApexTurboRenderer.render_apexes();
event.currentTarget.removeEventListener(event.type, cb);
});
window.addEventListener('turbolinks:load', function cb(event) {
ApexTurboRenderer.render_apexes();
event.currentTarget.removeEventListener(event.type, cb);
});
window.addEventListener('turbo:load', function cb(event) {
ApexTurboRenderer.render_apexes();
event.currentTarget.removeEventListener(event.type, cb);
});
</script> This is all. |
Beta Was this translation helpful? Give feedback.
-
@ncs1 @toddsutt I really love watching your discussion. Unfortunately I cannot help you guys on this one because I don't use turbolinks in my app and I have quite limited free time nowadays. 😢 |
Beta Was this translation helpful? Give feedback.
-
Welp, this library needs to be updated for Rails 7. You basically have to duplicate everything because you have to create a second graph and load that if the "original" doesn't. Might as well just use the JS instead of the ERB helpers. This is how I got it to work: Application.js:
ERB view:
|
Beta Was this translation helpful? Give feedback.
-
Hi guys, any updates on this discussion? |
Beta Was this translation helpful? Give feedback.
-
Is your feature request related to a problem? Please describe.
Currently, there's no documentation / simple solution to use apexcharts.rb in rails context (i.e. using with trubo/turbolinks).
When navigating into an apexcharts page, out and back - the chart won't show as it doesn't redraw/reload due to turbo listeners.
Describe the solution you'd like
I have a specific solution for my application, but it's not generic and poorly implemented.
Is there a solution ? Am I missing something ?
Beta Was this translation helpful? Give feedback.
All reactions