GithubHelp home page GithubHelp logo

Comments (8)

ankane avatar ankane commented on May 1, 2024

This is not possible w/ Chartkick. You could use a column chart.

new Chartkick.ColumnChart("chart-1", {"1":11,"2":6,"3":3,"4":2,"5":8});

from chartkick.

camiloribeiro avatar camiloribeiro commented on May 1, 2024

Is it still true that LineChart only work with date time values? Thanks.

from chartkick.

ankane avatar ankane commented on May 1, 2024

Yes, still true.

from chartkick.

camiloribeiro avatar camiloribeiro commented on May 1, 2024

I found my way with it :) Thanks a lot for sharing.

from chartkick.

ankane avatar ankane commented on May 1, 2024

This is now possible with the discrete option.

from chartkick.

graingerkid avatar graingerkid commented on May 1, 2024

How do you use the discrete option?

from chartkick.

StephaneJuban avatar StephaneJuban commented on May 1, 2024

I'm also interested about it. @camiloribeiro could have been great to share your solution even if it's now 3 years old.... :/

from chartkick.

fiedl avatar fiedl commented on May 1, 2024

In the view, add the discrete: true parameter to the line_chart:

- # app/views/charts/index.html.haml
- # ...
= line_chart charts_test_path, discrete: true, height: "400 px"

In the controller, where the data is filled, the x-axis values are defined as the keys of the data hash.

# app/controllers/charts_controller.rb
class ChartsController < ApplicationController

  def index
  end

  # GET /charts/test.json
  def test
    @test_series = [
      {
        name: "Series 1",
        data: { "x1": 1, "x2": 5, "x3": 9 }
      },
      {
        name: "Series 2",
        data: { "x1": 14, "x2": 25, "x3": 2 }
      }
    ]

    render json: @test_series.chart_json
  end
end

Suppose, you have an array of x-values, x_values = ["x1", "x2", "x3"], and you get the y-value by some calculation y_value(x), you may use this short syntax to generate a data hash:

{
  name: "Series 1",
  data: Hash[x_values.collect { |x| [x, y_value(x)] }]
}

from chartkick.

Related Issues (20)

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.