# trying to change Chartkick to Chart.js

**URL:** <https://www.ruby-forum.com/t/trying-to-change-chartkick-to-chart-js/251938>\
**Category:** Rails\
**Created:** [February 20, 2019, 9:42pm UTC](https://www.ruby-forum.com/t/trying-to-change-chartkick-to-chart-js/251938 "2019-02-20T21:42:13Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![marlibenicio](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/7bcc69/32.png) [@marlibenicio](https://www.ruby-forum.com/u/marlibenicio)\
**Post date:** [February 20, 2019, 9:42pm UTC](https://www.ruby-forum.com/t/trying-to-change-chartkick-to-chart-js/251938/1 "2019-02-20T21:42:13Z")

</div>

I’m trying to migrate a chart from Chartkick to a Chart.js, as I plan to “merge” charts in the future and in Chartkick that function doesn’t exist. I’m having trouble understanding how data coming from the Rails controller is used in the “date” field when you write a function from a Charts.js with the same data as the Chartkick. Does anyone have this answer?

In chartkick, I have the following function:

\<% = line\_chart charts\_loading\_stock\_days\_path (start\_date: @start\_date, end\_date: @end\_date, granularity: @ granularity, supermarket: @supermarket, product: @product, family: @ family), download: true, colors: ["# FFD700"]% \>

How would that look in Chart.js?

Thanks for the help and sorry if the question is very basic.

---

<div class="post-metadata">

**Author:** ![panic\_maven](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/47e85d/32.png) [@panic\_maven](https://www.ruby-forum.com/u/panic_maven)\
**Post date:** [February 20, 2019, 10:22pm UTC](https://www.ruby-forum.com/t/trying-to-change-chartkick-to-chart-js/251938/2 "2019-02-20T22:22:50Z")

</div>

Chartkick can use Chart.js as the plotting engine. add `//= require Chart.bundle` to application.js before the `//= require chartkick`. Make sure that application.js is included before the helper function is called.

to inspect the code (dumped to js console) you can pass `code: true` to line\_chart.

---

<div class="post-metadata">

**Author:** ![marlibenicio](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/7bcc69/32.png) [@marlibenicio](https://www.ruby-forum.com/u/marlibenicio)\
**Post date:** [February 21, 2019, 4:19pm UTC](https://www.ruby-forum.com/t/trying-to-change-chartkick-to-chart-js/251938/3 "2019-02-21T16:19:33Z")

</div>

Hello, how are you? So I checked my application.js and it already included the Require chart.bundle. I didn’t know that the chartkick could work like chart.js. Thanks.

In Chartkick is it possible to merge different graphs into the same Layout? (As if it were superimposed). Because my idea of migrating the chart is precisely because in Chart.js this is possible. Thanks again 🙂

---

<div class="post-metadata">

**Author:** ![panic\_maven](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/47e85d/32.png) [@panic\_maven](https://www.ruby-forum.com/u/panic_maven)\
**Post date:** [February 21, 2019, 8:48pm UTC](https://www.ruby-forum.com/t/trying-to-change-chartkick-to-chart-js/251938/4 "2019-02-21T20:48:12Z")

</div>

do you mean more than one data series onto one plot/graph? you can modify/replace `charts_loading_stock_days_path(…)` to something that combines multiple data series.

---

<div class="post-metadata">

**Author:** ![marlibenicio](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/7bcc69/32.png) [@marlibenicio](https://www.ruby-forum.com/u/marlibenicio)\
**Post date:** [February 22, 2019, 10:53am UTC](https://www.ruby-forum.com/t/trying-to-change-chartkick-to-chart-js/251938/5 "2019-02-22T10:53:29Z")

</div>

> [@panic\_maven](#):
>
> do you mean more than one data series onto one plot/graph? you can modify/replace `charts_loading_stock_days_path(…)` to something that combines multiple data series.

I meant more than one type of chart in the same plot, for example a bar chart and a line chart together. You know?

---

<div class="post-metadata">

**Author:** ![panic\_maven](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/47e85d/32.png) [@panic\_maven](https://www.ruby-forum.com/u/panic_maven)\
**Post date:** [February 22, 2019, 5:37pm UTC](https://www.ruby-forum.com/t/trying-to-change-chartkick-to-chart-js/251938/6 "2019-02-22T17:37:24Z")

</div>

I see now, i believe you can pass another option called library to `line_chart` whose value is a hash of options for the underlying charting library where you can set the chart type for each data series.

or …

since you’re using chart.js as the charting engine, in your data series set the dataset key to { type: ‘a\_chart\_type’ }.
