Comments (16)
Chartkick now has a redraw
function for this. (on master)
Chartkick.charts["chart-id"].redraw()
from chartkick.
Krainboltgreene, your example didnt include the chart library, it's showing a javascript error.
"GET http://fiddle.jshell.net/zPEML/show/chartkick.js 404 (Not Found)"
I dont know how to include the lib on jsfiddle. :(
from chartkick.
That's very weird, but at least you can reproduce the idea locally now.
from chartkick.
The jsfiddle demo is missing the Google Charts library on the generated page. Once I add it above chartkick.js
, the example works. Does this solve the problem?
from chartkick.
I had the same issue. It seems Google Charts doesn't draw when the chart container is hidden.
Using the inspector or Firebug if you're on Firefox make it work because you're resizing the window and chartkick.js redraws the chart on resize.
To fix that, I added a js call to render the chart only when the element is displayed.
Hope this helps.
from chartkick.
Hello,
I have a similar problem on Foundation. If i render a chart inside a non active (hidden) tab. The size is wrong.
How did you render the chart on display ?
Thanks !
from chartkick.
On your JS:
$(document).on "click", ".show-chart", (event) ->
id = $(this).parents(".panel-heading").attr("id")
$(this).children(".panel-body").load("/show_chart?type=#{id}")
Your show_chart action would render a partial that would handle all the different chart types, like so:
<% case params[:type] %>
<% when 'pending_tasks_by_user' %>
<%= pie_chart something %>
<% when 'complete_tasks_by_user' %>
<%= bar_chart something_else %>
<% end %>
Hope this helps!
from chartkick.
For this, I'd be nice to be able to trigger an event on the chart that renders it.
// jquery version
$("#users-chart").trigger("chartkick:render")
from chartkick.
Thanks a lot, it helped !
from chartkick.
@rapcal I've been having trouble with this too, but I don't really get how your example corresponds to anything. I'm not understanding how it can work, when I attempt to do something like you're doing, the jquery renders the JSON.
Here's the code $( '#my_div_with_chart' ).load( "/my_chart_endpoint");
from chartkick.
Hm... What do you have on your partial?
from chartkick.
@ankane How to trigger redraw chart with jQuery? I have tried these but still doesn't work:
$('#chart').trigger('chartkick:render');
$('#chart').trigger('chartkick:resize');
$(window).trigger('resize');
from chartkick.
This is worked well in my environment.
window.dispatchEvent new Event('resize')
from chartkick.
This is my fix :
$('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
var ev = document.createEvent('Event');
ev.initEvent('resize', true, true);
window.dispatchEvent(ev);
});
from chartkick.
@bqst that works for me! thanks!
from chartkick.
@bqst: That works but I have new problem http://prntscr.com/bh09ho
from chartkick.
Related Issues (20)
- Make chart download link image visible at all times HOT 2
- Better adding of plugins to Chart.js with Chartkick HOT 9
- Charts stuck at "Loading..." [example included] HOT 4
- CSP compliance breaks when used with Turbo Drive w/ and random nonce generator HOT 3
- Add support for chart.js 4.x HOT 3
- Add combo bar/line charts HOT 2
- Jruby Support HOT 1
- Support for Apex Charts HOT 1
- Add support for limiting the serie to a certain time frame HOT 1
- Support for polar (spiderweb) charts HOT 1
- Demo not rendering correctly in Safari HOT 2
- `createChart` is not fired after Turbo Frame renders the view HOT 8
- Comparisons in Two Date Ranges HOT 1
- Error importing Chartkick object HOT 2
- Provide ES module for JS with default exports HOT 1
- Rails 7 Setup Additional Step Needed HOT 4
- Canvas accessibility options like aria-label HOT 1
- preffix and suffix on column HOT 1
- X-axis is converted to integers even if datapoint contains alphanumeric characters HOT 1
- Some plugins not (fully) working with Chartkick with Importmaps HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from chartkick.