laravel-chartjs
laravel-chartjs copied to clipboard
[ask] add label on pie chart
Hello guys, im already success to create pie chart, this is the result
but i want add label inside chart like this
can we do thing like this in chart js?thanks
Use the data label plugin.
First add the script file
then
add these lines of code to your optionsRaw in Controller: 'plugins' => [ 'datalabels' => [ 'borderColor' => 'white', 'borderRadius' => 25, 'borderWidth' => 2, 'color' => 'white', 'formatter' => 'Math.round' ] ],
thanks for your answer, but when i put this script
<script src="https://cdn.jsdelivr.net/npm/[email protected]"></script>
i got an error like this
do you know why this happen?Thanks!
This is because of the compatibility issue. Put this version of chart js
already tried it, but get the another error like this..
this is because the script or not? Thanks again btw
Are you working with Ajax Call?
Also, add your code snippet to better communicate
No im not using ajax for this chart.. and this is my code
then i get this error
change the labels array inside plugins to datalabels AND also if you are trying to set font-size to datalabels use "font.size" instead of "FontSize".
i already tried to change labels to datalabels, but i dont find the font-size, because im not setting it. why this happen
The third error you faced is because of the Hover attribute try to remove it and test it again or try to work it in events.
Try to remove any other templates styles or scripts just keep chartjs and datalabels plugin in your blade files then test it.
There may be some compatibility issues.
ah, now i got no error.. but still i cant see the label.. still like this
and this is my optionraw code
a tiny issue when you open optionsRaw like a json keep all the json braces everywhere inside the optionsRaw function but if you treat to use it like array keep it all array.
as this
oh because i ever try this code on my other chart and success..like this
but i try my code into code like yours, but still no result
Check for the anchor (alignment) and the colors if there is not any error in console.
i set same option like yours, but still not get the datalabel in the chart
Any error in your browser`s console?
no, there is no error in my console..
Any way to make it work on the latest version?
ChartJs 3.5 and plugin 2.0?