I need to display the data label in a pie_chart.
Just as the manually manipulated image shows.
in my code I have the following:
in Gemfile
:
gem 'chartkick', '>= 3.3.0'
gem 'highcharts-rails', '~> 6.0.3'
in application.js
:
//= require highcharts
//= require chartkick
in inicio_controler.rb
:
@datos = [["Muestra A", 4],["Muestra B", 7],["Muestra C", 13],["Muestra D", 2]]
In the view:
index.html.erb
:
I have already tried these four versions and none of them work:
VERSION 1
<%= pie_chart @datos, label: 'true' %>
VERSION 2
<%= pie_chart @datos, library: {plotOptions: { pie: { dataLabels: { enabled: true }}}} %>
VERSION 3
<%= pie_chart @datos, dataLabels: "Value" %>
VERSION 4
<%= pie_chart @datos3, dataLabels: "true" %>
According to the doc of
highcharts
, you could align the labels with adistance
negative and change the info withformat
(more formatting options in the doc ).This is the result:
Consideration outside the scope of this question : You could consider not using intermediary gems, like
chartkick
, to handle js libraries. I think it is to add more load to the rails app and youGemfile
are something that does not concern it, apart from the fact that in many cases (it does not seem to be the case withchartkick
) they are quite outdated with respect to the original js library. It's one of the goals ofwebpacker
, but usingsprockets
it you could still achieve this by keeping apackage.json
in the root of your project and adding a new assets folder invendor/
(which is ignored in your version control), where you can add the exact version ofchartkick
you use.