Connecting Raphael with Rails
This is a high-level question about web frameworks, that as a desktop app developer, I don't have much knowledge of.
I am planning to build a web application which visualizes some data stored in a database. I plan on using Rails for user query. For visualization, the Raphael JS library looks good. Would it be a considerable task trying to connect Rails with this library?
A开发者_如何转开发ny recommendations for substitutes for these 2 are welcome.
There isn't really much that needs to be done to connect Rails and Raphaël. Raphaël is a Javascript library, and so runs entirely on the client, and Rails is a web application framework, running on the server. All you really need to do to integrate them are include Raphaël on your page, and provide data to it in a format easy to use from Javascript; using RESTful controllers which provide data in JSON should make it easy for you to load data using XMLHttpRequest from the client, which you can then display using Raphaël.
Ryan Bates talk about charts (including Raphael) in this Railscasts, Im pretty sure It's a good starting point.
Raphael is a self-contained JS library, the server-side framework/language you pick is really unimportant. You can't just plug one into the other though, you'll have to figure out how to supply Raphael with the data it needs in the format it expects. Rails will be no better or worse than any other framework at this.
There should be no issues especially since Rails 3 has made a point of being JS-library agnostic.
Doing a quick cursory search I saw this library that might merit your consideration. Doesn't appear to do pie charts but otherwise it looks good: Flot
That particular library is made to integrate with jQuery, which is a popular and well-documented JS library that Rails 3 plays very nicely with.
If you're feeling lazy, you can use a gem which will include the relevant files for you.
It is very easy. Raphaël is a javascript library so in order to use it, put the raphael-min.js file in your app/assets/javascript folder. Then add this line
app/views/layouts/application.html.erb
<!DOCTYPE html>
<html>
<head>
<title></title>
<%= stylesheet_link_tag "application", :media => "all" %>
<%= javascript_include_tag "raphael-min" %>
<%= javascript_include_tag "application" %>
<%= csrf_meta_tags %>
...
Then, write your javascript code into the app/assets/javascript/application.js file. This should work.
精彩评论