1👍
With the code you provided the ticks array contain the correct ticks if I try to print them normally: https://jsfiddle.net/Leelenaleee/bfc3evz1/6/.
If you want the number 2 to be red and the rest be black your best option is to update to the latest version of chart.js which means you need to use the beta of ng2-charts, then you can make use of the scriptable options.
var options = {
type: 'line',
data: {
labels: ["Red", "Blue", "Yellow", "Green", "Purple", "Orange"],
datasets: [{
label: '# of Votes',
data: [12, 19, 3, 5, 2, 3],
borderColor: 'pink'
}]
},
options: {
scales: {
y: {
ticks: {
color: ({
tick
}) => (tick.value === 12 ? 'red' : Chart.defaults.color)
}
}
}
}
}
var ctx = document.getElementById('chartJSContainer').getContext('2d');
new Chart(ctx, options);
<body>
<canvas id="chartJSContainer" width="600" height="400"></canvas>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/3.5.1/chart.js"></script>
</body>
- [Chartjs]-Angular chart.js not resizing (shinking) in a flexbox
- [Chartjs]-Background color of the graph affects the other graphs too
Source:stackexchange.com