Chart.js with php Hello,
I'm using Chart.js and i defined a max and min values of my Y axis, but i want to have '%' next to my values.
Is it possible to add '%' only with php ?
Because it didn't work when i did that :
'max' => 30+'%'
or
'max' => 30%
Thanks.
Show the surrounding code so we can see the context. Just a little on each side of this code
Concat with php uses a dot
'max' => 30 . '%'
//but why concat if it isn't a variable?
'max' => '30%'
@Sinnbeck
I've already tried that but i doesnt seems to work.
This is my code :
'scales' => [
'yAxes' => [
[
'ticks' => [
'max' => 30,
'min' => 10,
]
],
]
@The beginner does not work? How? Error?
@The beginner It won't work.
The graph is drawn according to the values you pass. If you pass 30 then they can parse it to integer and draw the map if you pass 30% it will not be an integer.
@Sinnbeck
If i try to concat this is what i got :
A non-numeric value encountered
The code that i've shown you work because it's only integer but if i add that : .'%'
it'll not work anymore
@furqanDev
Yes, it only accepts integer so i'm asking how could i put that character '%' next to my values
@Sinnbeck The only llibrary i use is chartJS one so...
I'll check your link
@The beginner well I assume you somehow convert that php to a config for chartjs?
@Sinnbeck
I'm never converting my php (or maybe i don't really understand what you mean ^^')
@The beginner Did you read the documentation ?
Check it and see if by any chance they provide this kind of option or not. I think there will be some option of prefix or postfix for datasets.
@furqanDev Hi, sorry for the delayed response...
The documentation is in js only i was looking for the "php way". But i'll give it a look
@The beginner No worries.
There is not php way I'm afraid because the Charts are rendered through JS. You pass some values as a json response from php backend and set those values/object/array as a dataset. Those dataset should be number because the chart will be drawn according to that number. If they have option to add prefix that would be perfect.
@furqanDev
Alright, thanks for your response.
I'm still going to try to find a solution with php because i might have an idea... even if i think you're right.
Thanks again :)
Please sign in or create an account to participate in this conversation.