question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot Pass jQuery Object to Chartist

See original GitHub issue

Maybe I’m missing something, but any time I try and pass a jQuery object to chartist, it gives me: Uncaught SyntaxError: Failed to execute 'querySelector' on 'Document': '[object Object]' is not a valid selector.

For example:

var chart = $('.ct-chart');

new Chartist.Pie(chart, data);

Is there any way to pass a jQuery object to Chartist? I’m having to create individual IDs for each chart and then grab those with jQuery in order to put a dynamic amount of charts on the page, which works, but is a bit more time consuming/probably less performant.

I apologize if this has been covered before. Thanks for any help or advice anyone could give! Kickass chart lib.

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:9

github_iconTop GitHub Comments

1reaction
gionkunzcommented, Feb 5, 2015

Hey there. The Chartist guy hates jQuery 😃 He wants the world to be less jQuery and more JavaScript. That’s why Chartist only accepts DOM selector strings or DOM Node Objects as first parameter in the Chart.

If you’re still using jQuery in your project, Chartist is fine with that, but when you initialize a Chart you need to extract the DOM Node object from your jQuery List:

new Chartist.Pie($('.ct-chart').get(0), data);
0reactions
JulienMelissascommented, Feb 7, 2015

Not a bad solution, I’m calculating the values using JS, so I can’t exactly do it like that, but an awesome example none the less.

Thanks again for the help!

Read more comments on GitHub >

github_iconTop Results From Across the Web

jQuery object from html table into two one-dimensional arrays ...
I'm fiddling around with some jQuery code that should extract data from a 2-column HTML table and then spit out two one-dimensional arrays....
Read more >
API Documentation - Chartist.js
Detailed documentation of the Chartist.js code and API.
Read more >
Chartist.js, An Open-Source Library For Responsive Charts
To animate an SVG element, you first need to obtain a wrapper object by passing an SVG node to the Chartist. Svg constructor....
Read more >
Chartist.js data from table | Professor von Explaino
First parameter is the object to iterate through. table.getElementsByTagName('th') function gets me all the th elements in the selected table as ...
Read more >
Chartist.js Charts With Data from a MongoDB Using Flask and ...
In this video I show you how to create dynamic Chartist.js charts based ... server for the data and jQuery to send requests...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found