Thousand separator in pie chart of charts.js
Mobile Technologies
Mobile Computing
2 years ago
5
Star Rating
1
Rating
_x000D_
_x000D_
I 'm using Chart.js to draw pie chart.
To draw graph I used
var ctx = document.getElementById("myChart").getContext('2d');
var myChart = new Chart(ctx, {
type: 'pie',
data: {
labels: #{raw @labels.to_json},
datasets: [{
backgroundColor: #{raw @colors.to_json},
data: #{@followers}
}]
}
});
To clarify this data thing is like this
data: {
labels: ["FAISAL","muhammadfaisali","faisaliqbal3699"],
datasets: [{
backgroundColor: ["#00b638","#efaa30","#50c8ea"],
data: [500000, 75000, 100000]
}]
}
I need to show these data: [500000, 75000, 100000] as thousand separator like ["500,000", "75,000", "100,000"]
I tried different
things including writing this method
function separator(numbers)
{ data = []
for (i = 0; i < numbers.length; ++i) {
data.push(numbers[i].toLocaleString())
}
data
}
and tried to use it like this
data: separator(#{@followers})
it format data as I want but gives error like Cannot read property 'custom' of undefined
What is the way to show data in thousand separator here
Posted on 16 Aug 2022, this text provides information on Mobile Computing related to Mobile Technologies. Please note that while accuracy is prioritized, the data presented might not be entirely correct or up-to-date. This information is offered for general knowledge and informational purposes only, and should not be considered as a substitute for professional advice.
Take Quiz To Earn Credits!
Turn Your Knowledge into Earnings.