Chartjs-How to display label inside pie chart in Chartkick?

0👍

I found the solution.

Chart.js doesn’t support labels inside of the chart. So instead, I’m using Highcharts.

  1. Install the highchart. You can have both libraries in the Chartkick installation.

    yarn add highchart

  2. Then you add the following into the application.js file.

    import "chartkick/highcharts"

  3. 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} %’,}}}}

Leave a comment