'How to display label inside pie chart in Chartkick?
I'm using Haml.
So the code is this:
= pie_chart @chart_ratings, donut: true, suffix: "%", loading: "Generating charts...", download: true, width: "350px", library: {plotOptions: { pie: { dataLabels: { enabled: true }}}}
But the library doesn't include the labels.
Is there anything missing?
Solution 1:[1]
I found the solution.
Chart.js doesn't support labels inside of the chart. So instead, I'm using Highcharts.
Install the highchart. You can have both libraries in the Chartkick installation.
yarn add highchart
Then you add the following into the application.js file.
import "chartkick/highcharts"
Then in the view for the pie chart, you append this.
= pie_chart @data, donut: true, library: { pieSliceText: 'value-and-percentage', plotOptions: {pie: {dataLabels: {enabled: true,format: '{point.name}:
{point.percentage:.1f} %',}}}}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Chim Kan |
