Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ask] add label on pie chart #82

Open
edwinnsan opened this issue Jan 28, 2019 · 20 comments
Open

[ask] add label on pie chart #82

edwinnsan opened this issue Jan 28, 2019 · 20 comments

Comments

@edwinnsan
Copy link

Hello guys, im already success to create pie chart, this is the result
screenshot from 2019-01-28 10-54-50

but i want add label inside chart like this
screenshot from 2019-01-28 10-55-03

can we do thing like this in chart js?thanks

@Mohammad-Yasin-Noori
Copy link

Use the data label plugin.

@Mohammad-Yasin-Noori
Copy link

First add the script file

<script src="https://cdn.jsdelivr.net/npm/[email protected]"></script>

then

add these lines of code to your optionsRaw in Controller:
'plugins' => [
'datalabels' => [
'borderColor' => 'white',
'borderRadius' => 25,
'borderWidth' => 2,
'color' => 'white',
'formatter' => 'Math.round'
]
],

@edwinnsan
Copy link
Author

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
screenshot from 2019-02-06 10-18-49

do you know why this happen?Thanks!

@Mohammad-Yasin-Noori
Copy link

This is because of the compatibility issue.
Put this version of chart js

<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/Chart.min.js"></script>

@edwinnsan
Copy link
Author

already tried it, but get the another error like this..
screenshot from 2019-02-06 10-25-52

this is because the script or not?
Thanks again btw

@Mohammad-Yasin-Noori
Copy link

Are you working with Ajax Call?

@Mohammad-Yasin-Noori
Copy link

Also, add your code snippet to better communicate

@edwinnsan
Copy link
Author

No im not using ajax for this chart..
and this is my code

screenshot from 2019-02-06 11-56-46
screenshot from 2019-02-06 11-57-01

@edwinnsan
Copy link
Author

then i get this error
screenshot from 2019-02-06 12-00-40

@Mohammad-Yasin-Noori
Copy link

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".

@edwinnsan
Copy link
Author

i already tried to change labels to datalabels, but i dont find the font-size, because im not setting it. why this happen

@Mohammad-Yasin-Noori
Copy link

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.

@edwinnsan
Copy link
Author

ah, now i got no error.. but still i cant see the label.. still like this
screenshot from 2019-02-06 12-13-40

and this is my optionraw code
screenshot from 2019-02-06 12-14-10

@Mohammad-Yasin-Noori
Copy link

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
code

@edwinnsan
Copy link
Author

oh because i ever try this code on my other chart and success..like this
screenshot from 2019-02-06 12-24-55

but i try my code into code like yours, but still no result
screenshot from 2019-02-06 12-25-26

@Mohammad-Yasin-Noori
Copy link

Check for the anchor (alignment) and the colors if there is not any error in console.

@edwinnsan
Copy link
Author

screenshot from 2019-02-06 12-57-37

i set same option like yours, but still not get the datalabel in the chart

@Mohammad-Yasin-Noori
Copy link

Any error in your browser`s console?

@edwinnsan
Copy link
Author

no, there is no error in my console..

@saulob
Copy link

saulob commented Sep 17, 2021

Any way to make it work on the latest version?

ChartJs 3.5 and plugin 2.0?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants