Comments (8)
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.
Is it still true that LineChart only work with date time values? Thanks.
from chartkick.
Yes, still true.
from chartkick.
I found my way with it :) Thanks a lot for sharing.
from chartkick.
This is now possible with the discrete
option.
from chartkick.
How do you use the discrete option?
from chartkick.
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.
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)
- Make chart download link image visible at all times HOT 2
- Better adding of plugins to Chart.js with Chartkick HOT 9
- Charts stuck at "Loading..." [example included] HOT 4
- CSP compliance breaks when used with Turbo Drive w/ and random nonce generator HOT 3
- Add support for chart.js 4.x HOT 3
- Add combo bar/line charts HOT 2
- Jruby Support HOT 1
- Support for Apex Charts HOT 1
- Add support for limiting the serie to a certain time frame HOT 1
- Support for polar (spiderweb) charts HOT 1
- Demo not rendering correctly in Safari HOT 2
- `createChart` is not fired after Turbo Frame renders the view HOT 8
- Comparisons in Two Date Ranges HOT 1
- Error importing Chartkick object HOT 2
- Provide ES module for JS with default exports HOT 1
- Rails 7 Setup Additional Step Needed HOT 4
- Canvas accessibility options like aria-label HOT 1
- preffix and suffix on column HOT 1
- X-axis is converted to integers even if datapoint contains alphanumeric characters HOT 1
- Some plugins not (fully) working with Chartkick with Importmaps HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from chartkick.