Live data from Hacker News

Show HN: Create Javascript charts with one line of Ruby

ankane.github.io

41–50 of 64 posts

Re: Show HN: Create Javascript charts with one line of Ruby

#42

Hmm. I'm getting a undefined method `group' for # error with using mongoid 3, Pixel embeds_many Hits, Hit embedded_in Pixel. referrer is a string field of a Hit.

#group is an Arel method that generates a SQL 'GROUP BY' clause in the resulting statement, not part of chartkick or mongoid.

Re: Show HN: Create Javascript charts with one line of Ruby

#43
post #6

The ruby wrapper lib around the JS is dead simple. Could be ported to any language with ease. Very nice work! https://github.com/ankane/chartkick/blob/master/lib/chartkic...

We are building something similar for Django/Python:

https://github.com/agiliq/django-graphos

I am going to pick up some ideas from your code.

Re: Show HN: Create Javascript charts with one line of Ruby

#44

Hmm. I'm getting a undefined method `group' for # error with using mongoid 3, Pixel embeds_many Hits, Hit embedded_in Pixel. referrer is a string field of a Hit.

#group is an Arel method that generates a SQL 'GROUP BY' clause in the resulting statement, not part of chartkick or mongoid.

it'd be nice to get a heads up that this was dependent on using a SQL database.

Re: Show HN: Create Javascript charts with one line of Ruby

#45

Earlier quoted context omitted.

#group is an Arel method that generates a SQL 'GROUP BY' clause in the resulting statement, not part of chartkick or mongoid.

it'd be nice to get a heads up that this was dependent on using a SQL database.

It's not dependent on SQL. @pixel.hits is returning an Array, and there is no method group for Array in Ruby. You could try group_by if you really want to group an Array, or use the Mongoid syntax for grouping.

Re: Show HN: Create Javascript charts with one line of Ruby

#47

Earlier quoted context omitted.

#group is an Arel method that generates a SQL 'GROUP BY' clause in the resulting statement, not part of chartkick or mongoid.

it'd be nice to get a heads up that this was dependent on using a SQL database.

You can do the same in just ruby:

    pie_chart @pixel.hits.group_by{|u| u.referrer }.each_with_object({}) {|(k,v), h| h[k] = v.size }

Re: Show HN: Create Javascript charts with one line of Ruby

#48

Earlier quoted context omitted.

Why should the controller be generating graphics? The UI can do that.

Depending upon the number of data points you are representing, images may take less bandwidth and transfer time than the data itself. For example suppose you have a chart showing network latency; if you sample once a minute and show a month's worth of data you could easily transfer around 500KB for the raw data (assuming 12 bytes of json per sample), while an image file would be 20KB. If you have a dashboard full of…

I see your point, but that's a somewhat contrived example: If you display per-minute data for an entire month you won't have the horizontal resolution (43200 to 44640 data points) to plot them all!

If you want zoomable charts to allow for increasing resolution, then the chart lib should ask the controller for a specific resolution and range on demand.

Even then, 500KB of numeric JSON data compresses really well (I tested with 1 month of real-world per-minute data: 92KB).

Re: Show HN: Create Javascript charts with one line of Ruby

#49
post #35

Assuming the data for the graph shown is the dots, then the lines between them should be straight, not curved, because othrwise the graph is pretending to have higher accuracy than it actually has, which is a lie.

it's called interpolation.

It has a name, but it's still a bad idea.
Post reply on HN