Ruby on Rails Chartkick data - ruby-on-rails

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

Related

Using render_async to call a partial with highcharts

I am using Ruby on Rails and trying to call a partial named _bmetric by using render_async in the index method. This partial has html code and also a highcharts (js). The problem is that the highcharts does not show up. However, if I use render instead of rander_async, there is no problem.
Can someone please tell me what should I consider while using render_async to call a partial with highcharts?
Check out this answer https://stackoverflow.com/a/52842726/4158895
It should help you with your problem.
When you try to render a nested partial, render_async loads JS code inside a script tag that needs to be evaluated to do another request. jQuery has a powerfull method .replaceWith(text) which evaluates any script tags in the text variable. This is not so easy to achieve in plain JS. I'm trying to come up with a solution for this.

Rails Project Chartkick with Highcharts

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.

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.

Rendering Pagedown Markdown in Rails 4

I have a properly working pagedown editor in a rails 4 application, but I believe I'm missing something simple to render the pagedown data at a later point in my application.
Here's the gem (and initialization) I'm using: https://github.com/hughevans/pagedown-bootstrap-rails
Any ideas on how to render that data with the already-used gems?
EDIT: I think the root of my problem is it's not storing the data as the HTML version, so it doesn't render it when I display the data again. It's missing the converter step when the form gets saved, but I don't see any specific instruction on how to do that, so I assumed it was default part of these gems.
EDIT2: I've since taken the approach to convert the Markdown on each page load, with the following code:
Unfortunately, it doesn't use all the Pagedown Markdown, but it's at least handling new lines properly:
Any ideas?
Thanks!
So the answer to this question is two fold. Either you can convert the MD to HTML and store it in the database, or leave it as MD in the DB and convert it to HTML every time you want to render it. Note that you'll need to convert it back to MD (I'm not sure if this is entirely easy or not) if you want that field to be editable in the original MD.
Since this app doesn't care about performance, I decided to store it as MD and render it.
The results I was getting above stemmed from HAML's whitespace rendering that it does, so I had to use a little HAML filters to work around that.
The HAML ended up looking like:
.wmd-output><
:preserve
#{#object.attribute}
The second challenge was actually pretty straightforward, just not explicitly stated anywhere in the Markdown documentation. So I just wrote some javascript that automatically converts any .wmd-output class into it's proper Markdown on page load:
$(function() {
$('.wmd-output').each(function(i) {
var converter = new Markdown.Converter();
var content = $(this).html();
$(this).html(converter.makeHtml(content));
});
});
I hope this helps other people in the future.
This line of haml referenced should be what you need to render it:
= f.input :description, :as => :pagedown, :input_html => { :preview => true }

Multiple Markers on Google Map (Fails to display over 10 markers) - Ruby on Rails Environment YM4R Plugin

I have the following issue. I have a google map (using YM4r + Geokit) within Ruby on Rails, anyhow, i basically have an array of markers which are populated in the following manner
#shops.each do
|sto|
markers << GMarker.new (....)
end
They are definitely being stored fine as under 10 markers they are displayed just fine. The problem arises when there are more than 10 markers on the same page,
Further code related to displaying if this may help:
#map.overlay_global_init(GMarkerGroup.new(true, markers), "sto_markers")
in the html.erb file:
<%= GMap.header %>
<%= javascript_include_tag("markerGroup") %>
<%= #map.to_html%>
<%= #map.div(:width => 700, :height => 500)%>
Only 10 markers are displayed on screen instead of the correct amount in the markers array.
Has anyone ever encountered this issue please? i'm really at a loss on how to overcome this please
Hmm, I have never used these plugins (I prefer to work directly with the API, much easier :)), so this is just random thinking.
Have you looked in the source of the rendered HTML? In there you should have a Javascript Object or Array with all your markers defined. If all of them do show up there, then it is easier to pinpoint if the problem is on the Javascript or the Rails side. (That is what <%= #map.to_html%> should do unless I'm completely off).
Update:
After some looking into the plugin, I can't really tell what the error can be, however since it do put out everything in clear Javascript in the file, it would probably help a lot if you can post the rendered HTML source. I believe that you will find the solution by looking there.

Resources