GithubHelp home page GithubHelp logo

Comments (16)

ankane avatar ankane commented on May 2, 2024 1

Chartkick now has a redraw function for this. (on master)

Chartkick.charts["chart-id"].redraw()

from chartkick.

fabionl avatar fabionl commented on May 2, 2024

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.

krainboltgreene avatar krainboltgreene commented on May 2, 2024

That's very weird, but at least you can reproduce the idea locally now.

from chartkick.

ankane avatar ankane commented on May 2, 2024

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.

rapcal avatar rapcal commented on May 2, 2024

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.

harold-s avatar harold-s commented on May 2, 2024

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.

rapcal avatar rapcal commented on May 2, 2024

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.

ankane avatar ankane commented on May 2, 2024

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.

harold-s avatar harold-s commented on May 2, 2024

Thanks a lot, it helped !

from chartkick.

jonathanstiansen avatar jonathanstiansen commented on May 2, 2024

@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.

rapcal avatar rapcal commented on May 2, 2024

Hm... What do you have on your partial?

from chartkick.

firewalker06 avatar firewalker06 commented on May 2, 2024

@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.

naoa avatar naoa commented on May 2, 2024

This is worked well in my environment.

window.dispatchEvent new Event('resize')

from chartkick.

bqst avatar bqst commented on May 2, 2024

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.

whilei avatar whilei commented on May 2, 2024

@bqst that works for me! thanks!

from chartkick.

trungnguyencmu avatar trungnguyencmu commented on May 2, 2024

@bqst: That works but I have new problem http://prntscr.com/bh09ho

from chartkick.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.