Rails Project Chartkick with Highcharts - ruby-on-rails

I am adding charts on my Rails application and I started using chartkick the variety of charts that it offers are not quite what I would like.
I found in their documentation that you can use the Highcharts library. The issue is, I followed the steps but nothing happens...
Does anyone know the correct way to use these two together?
Here is the code I write: <%= column_chart #prsd_data, xtitle: "Members", ytitle: " # of publications", width: "100%", height: "100%" %>
#prsd_data is a hash that contains as keys the names of some people and as values an array of 2 integers.s
NOTE: The chart I want to generate is something like this one : Highcharts

Try this,
Add this gem "chartkick" to your gemfile
Add this <%= javascript_include_tag "https://www.google.com/jsapi" %> to your application.html.erb.
and you are good to go for any chartkick graph.

Related

Ruby on Rails Chartkick data

I am working on a multiple series line chart in ruby on rails. I have passed to the chart data as such:
<%= line_chart #budget.transactions.group(:category).group(:date).sum(:amount) %>
In the developer tools I looked at the script that populates the chart and it looks like:
new Chartkick.LineChart("chart-2", [{"name":"debt","data":[["2017-04-19",5.43],["2017-04-20",60.0]]},
{"name":"entertainment","data":[["2017-04-19",30.0]]},
{"name":"food","data":[["2017-04-20",15.0],["2017-04-21",20.0]]},
{"name":"housing","data":[["2017-04-02",17.33],["2017-04-10",20.0],["2017-05-01",522.0]]},
{"name":"transportation","data":[["2017-04-20",50.0]]},
{"name":"utilities","data":[["2017-04-19",35.0],["2017-04-21",20.0],["2017-04-27",77.34]]}], {});
To me the format for the data being passed to the chart seems correct, but the output... not so much. Also I was thinking using the Ruby Date class, rather than DateTime was causing a problem but I'm not sure. Any help appreciated.
enter image description here

Chartkick yAxis and Rails

Please can anyone help me with this issue?
I have A ruby on rails app and I am trying to use ChartKick.
I have the following code in my Controller to get all Publications:
#mentor_pub = Publication.all.where(user: current_user).order("mentor ASC")
And I am using the code below in my views.
<%= column_chart #mentor_pub.group(:mentor).count, height: "600px", discrete: true%>
You can see the image of what I am talking about here
the chart is displaying the way I want it, but The Yaxis is displaying decimal numbers instead of integers.
Please How would I modify the Yaxis to show integers?
Chartkick uses Google Visualization under the hood and allows you to pass options directly to the library using the library option like so:
<%= line_chart data, library: {backgroundColor: "#eee"} %>
for your exact problem you'll have to look into Googles documentation or this stackoverflow answer https://stackoverflow.com/a/16036721/390977 might help.

Chartkick rails 4 and table charts

I can't seem to figure out how or if Chartkick supports table charts. I tried table_chart as if I were doing any other chart, but it didn't work. Anyone know if chartkick supports that? I couldn't find it in the documentation.
You can check kick chart for integration with rails
http://chartkick.com/
you can use like
for_line_chart
= line_chart Model.group_by_day(:created_at).count %>
pie_chart
= pie_chart Model.group(:field).count
column_chart
= column_chart Model.group_by_hour_of_day(:field).count
bar_chart
= bar_chart Model.group(:field).sum(:field)
area_chart
= area_chart Model.group_by_minute(:created_at).maximum(:field)
line_chart
= line_chart completed_tasks_charts_path
For more please consult the link shared above hopefully this will help you a lot.
There is no such thing as table chart in chartkick.
There are line, pie, column, area, bar, geo charts and timeline avaliable.
All kind of charts with usage explanations you can find on chartkick official website.

QR Code Plugins Issue - Jeff

I used a plugin to create A QR Code from a plugin which says to use the below code in ruby page
<%= javascript_include_tag :defaults %>
<%= qrcode('http://www.facebook.com/', 2, 3, 'my-qrcode') %>
I was expecting an image file , instead i got a table with lots of values in it. I tried a different ways to find a QRCode image generator and the only one seems to give an image is google charts, which i find not that interesting, I used them like
<%= image_tag("http://chart.apis.google.com/chart?cht=qr&chl=#{'http://www.facebook.com/'}&chs=120x120&choe=UTF-8", :size => "120x120")%>
Does anyone knows any other useful plugin that gives me the following output
I need to see a QR code for a link (where the parameters of the link
changes)
When i click on a link below it, it should be able to download the
QRCode image.
Take a look into rqrcode. It seems to do what you want.
There is an old example app here

Adding Markdown into my Rails 3 app

I am trying to add Markdown to my Rails 3 web app but am having problems.
I have tried rdiscount and markdownizer but either they're not working or I'm not writing the correct code for them.
The code I have at the moment to display a text field is <%=h simple_format (#user.desktopinfo) %>
I want to increase the functionality of this text by adding Markdown but I am unable to get it work, please help! :)
EDIT 2
Using markdownizer broke my app, so I am now using BlueCloth. Add bluecloth to the gem file and add this <%= raw BlueCloth.new(#user.desktopinfo).to_html %>
:)
EDIT
Actually, just trying again...
With markdownizer, with markdownize! :desktopinfo in the user model and <%= #user.rendered_desktopinfo %> on the page that shows the text, I get this: <h1>this is a h1</h1> on the text when I enter
this is a h1
============
so I am halfway there! How do I now turn this code into html?
Consider rdiscount which substitutes for bluecloth but is faster and better maintained.
Ryan Tomayko's comparison is a good write up regarding the different libraries for using markdown in Ruby.
You haven't really specified exactly what you are after, but I use bluecloth when working with markdown. You can add 'bluecloth' to your Gemfile.
To parse your markdown it is as simple as:
<%= raw BlueCloth.new(YOUR_MARKDOWN).to_html %>
You need the keyword raw. so the HTML is not escaped.
<%= raw #user.rendered_desktopinfo %>

Resources