Giter Club home page Giter Club logo

iruby-chartkick's Introduction

iruby-chartkick build

You like writing Ruby within Juypter notebooks? Awesome, you're not alone - we do so, too ☀️ Since we also fell in love with the handy charting API of ankane/chartkick, we wrote this little gem bringing them together.

iruby-chartkick was made for easy plug-n-play plotting data using the awesomeness of chartkick within IRuby-backed Jupyter notebooks.

Installation

gem install iruby-chartkick

Usage

You can either include the module IRuby::Chartkick and use the wrapper methods, like line_chart:

include IRuby::Chartkick
		
data = {
  2019 => 1,
  2020 => 122,
  2021 => 34
}
 
line_chart(data)

Or you use the chart wrapper classes directly:

include IRuby::Chartkick
		
data = {
  2019 => 1,
  2020 => 122,
  2021 => 34
}

IRuby::Chartkick::LineChart.new(data).plot

Examples:

include IRuby::Chartkick

data = [
  {
    name: "Monkeys",
    data: {
      2010 => 20,
      2011 => 190,
      2012 => 188,
      2013 => 230,
      2014 => 422,
      2015 => 56,
      2016 => 299,
      2019 => 100
    }
  },
  {
    name: "Pirates",
    data: {
      2010 => 20,
      2011 => 90,
      2012 => 488,
      2013 => 430,
      2014 => 122,
      2015 => 6,
      2016 => 399,
      2019 => 500
    }
  }
]

LineChart

line_chart(data)

LineChart

line_chart(data, points: false)

LineChart

line_chart(data, points: false, width: "700px", min: 50, max: 300)

LineChart

AreaChart

area_chart(data)

AreaChart

ColumnChart

column_chart(data)

ColumnChart

BarChart

bar_chart(data)

BarChart

ScatterChart

scatter_chart(data)

ScatterChart

PieChart

include IRuby::Chartkick

data = [
  ["Blueberry", 44],
  ["Strawberry", 23],
  ["Banana", 22],
  ["Apple", 21],
  ["Grape", 13]
]

pie_chart(data)

PieChart

iruby-chartkick's People

Contributors

dependabot[bot] avatar elalemanyo avatar rstammer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

iruby-chartkick's Issues

Access vendored JS directly via chartkick gem

Since we are loading chartkick, I'd like to load all the necessary JS directly from it, i.e. like

  chartkick_dir = Gem::Specification.find_by_name("chartkick").gem_dir
  js = File.read("#{chartkick_dir}/vendor/assets/javascripts/Chart.bundle.js")

… but unfortunately I haven't managed to get this working, in the Jupyter frontend it results in Chartkick is not defined in the browser's JS console.

As a workaround for that I packaged the JS files for chart.js and chartkick.js from a CDN source, but let's see how we can fix that 🤔

iRuby keeps showing Loading ... for the chart

Hi,

In a cell from my Notebook, I add:

 require "iruby/chartkick"

 include IRuby::Chartkick

Then I just run:

 line_chart data

Then the screen keeps showing Loading ... . Is there anything else I need to do in order to load the chart?

Explore why area charts behave awkward sometimes

Observe two functions, f and g with the property that f is constant and g is not monotone
on an interval [a, b] where g(a) > f(a) and g(b) > f(b) and g(c) < f(c) for at least one c within [a, b]. Then, the line chart is correctly reflecting the situation, but the area chart not:

Example case:

Bildschirmfoto 2019-11-08 um 13 33 06

--
I don't know yet whether this is an issue with Chart.js or chartkick, but I wanted to roughly document it for later inspection.

column_chart auto-cuts data to display

This problem may is a problem of the underlying charting engine, but let's document it anyway and possibly supply some useful information.


When one wants to visualize time-based data, i.e. date ranges, then, if the date range is greater than one year, the column_chart does not display the full data. Here's a comparison of a line chart with a column chart:

Bildschirmfoto 2020-05-02 um 12 18 31

It could be the case that the charting lib runs into trouble when each column to display would be too thin - but I wonder if this data cut is intended and what possible options could look like.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.