11import React from 'react' ;
22import { ApiResponse , TotalLanguage } from "../types" ;
33import { Doughnut } from 'react-chartjs-2' ;
4- import 'chartjs-plugin-colorschemes ';
4+ import { Chart as ChartJS , ArcElement , Tooltip , Legend } from 'chart.js ';
55import getLangColor from '../languageColors' ;
66
7+ ChartJS . register ( ArcElement , Tooltip , Legend ) ;
8+
79type LanguagesChartProp = { languages :ApiResponse < [ TotalLanguage ] > } ;
810
911const LanguagesChart : React . FC < LanguagesChartProp > = ( { languages} ) => {
@@ -34,10 +36,21 @@ const LanguagesChart: React.FC<LanguagesChartProp> = ({languages}) => {
3436
3537 const options = {
3638 maintainAspectRatio : false ,
37- legend : {
38- position : 'bottom' ,
39- labels : {
40- padding : 15
39+ plugins : {
40+ legend : {
41+ position : 'bottom' as const ,
42+ labels : {
43+ padding : 15
44+ }
45+ } ,
46+ tooltip : {
47+ callbacks : {
48+ label : function ( context ) {
49+ const label = context . label || '' ;
50+ const value = context . parsed ;
51+ return `${ label } : ${ value } %` ;
52+ }
53+ }
4154 }
4255 } ,
4356 layout : {
@@ -51,19 +64,9 @@ const LanguagesChart: React.FC<LanguagesChartProp> = ({languages}) => {
5164 responsive : true ,
5265 rotation : 1 * Math . PI ,
5366 circumference : 1 * Math . PI ,
54- tooltips : {
55- callbacks : {
56- label : function ( tooltipItem , data ) {
57- const dataset = data . datasets [ tooltipItem . datasetIndex ] ;
58- const currentValue = dataset . data [ tooltipItem . index ] ;
59- const label = data . labels [ tooltipItem . index ]
60- return `${ label } : ${ currentValue } %` ;
61- }
62- }
63- }
6467 } ;
6568
6669 return < Doughnut data = { data } options = { options } height = { 250 } /> ;
6770} ;
6871
69- export default LanguagesChart ;
72+ export default LanguagesChart ;
0 commit comments