I'm currently utilizing Chart.js to create a pie chart.
My goal is to rotate the labels on the bottom half of the pie chart.
Below is my existing code for generating the pie chart:
$(document).ready(
function() {
var data = {
datasets: [{
data: [125, 125, 125, 125, 125, 125, 125, 125],
backgroundColor: ["#FE4D42","#FFD405","#58E152","#00D59F","#8B7DFF","#E85FED","#F71663","#4F94FF"]
}],
labels: [
"Arts and Creativity",
"Careers and Employment",
"Communities and Social",
"Culture and Heritage",
"Learning and Skills",
"Personal Finance",
"Self-Environment",
"Wellbeing"
]
};
var labels_url = {
"Arts and Creativity" : "arts-and-creativity",
"Careers and Employment" : "careers-and-employment",
"Communities and Social" : "communities-and-social",
"Culture and Heritage" : "culture-and-heritage",
"Wellbeing" : "health",
"Learning and Skills" : "learning-and-skills",
"Personal Finance" : "personal-finance",
"Self-Environment" : "self-environment"
};
var canvas = document.getElementById("myChart");
var ctx = canvas.getContext("2d");
var myNewChart = new Chart(ctx,{
type: 'pie',
data: data,
options: {
legend: {
display: false,
},
plugins: {
labels: {
render: 'label',
arc: true,
fontColor:["#FF7805","#0854A3","#14A400","#048A7D","#502788","#F200F2","#FF0068","#000962"],
fontSize: 18,
position: 'outside'
}
}
}
});
canvas.onclick = function(evt) {
var activePoints = myNewChart.getElementsAtEvent(evt);
if (activePoints[0]) {
var chartData = activePoints[0]['_chart'].config.data;
var idx = activePoints[0]['_index'];
var label = chartData.labels[idx];
var value = chartData.datasets[0].data[idx];
var url = "https://www.maximiseme.co.uk/" + labels_url[label];
//alert(url);
console.log(url);
window.location.href = url;
}
};
}
);
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.9.4/Chart.js"></script>
<script src="https://cdn.jsdelivr.net/gh/emn178/chartjs-plugin-labels/src/chartjs-plugin-labels.js"></script>
<canvas id="myChart"></canvas>
To enhance readability, I would like to rotate the following labels by 180 degrees: Communities and Social, Culture and Heritage, Learning and Skills, Personal Finance.