score:50
$(function(){
var ctx = document.getElementById("myChart");
//Chart.defaults.global.defaultFontColor='red';
var myChart = new Chart(ctx, {
type: 'bar',
data: {
labels: ["Red", "Blue", "Yellow", "Green", "Purple", "Orange"],
datasets: [{
label: '# of Votes',
data: [12, 19, 3, 5, 2, 3],
backgroundColor: [
'rgba(255, 99, 132, 0.2)',
'rgba(54, 162, 235, 0.2)',
'rgba(255, 206, 86, 0.2)',
'rgba(75, 192, 192, 0.2)',
'rgba(153, 102, 255, 0.2)',
'rgba(255, 159, 64, 0.2)'
],
borderColor: [
'rgba(255,99,132,1)',
'rgba(54, 162, 235, 1)',
'rgba(255, 206, 86, 1)',
'rgba(75, 192, 192, 1)',
'rgba(153, 102, 255, 1)',
'rgba(255, 159, 64, 1)'
],
borderWidth: 1
}]
},
options: {
legend:{labels: {fontColor: 'orange'}},
title: {
display: true,
fontColor: 'blue',
text: 'Custom Chart Title'
},
scales: {
yAxes: [{
ticks: {
beginAtZero:true,
fontColor: 'red'
},
}],
xAxes: [{
ticks: {
fontColor: 'green'
},
}]
}
}
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.3.0/Chart.min.js"></script>
<canvas id="myChart" width="400" height="400"></canvas>
You can use fontColor inside ticks/label/legend:labels for a particular axis,
options: {
legend: {
labels: {
fontColor: 'orange'
}
},
title: {
display: true,
fontColor: 'blue',
text: 'Custom Chart Title'
} ,
scales: {
yAxes: [{
ticks: {
beginAtZero:true,
fontColor: 'red'
},
}],
xAxes: [{
ticks: {
fontColor: 'green'
},
}]
}
}
or change the defaultFontColor to change font color of entire text elements drawn on the canvas.
Chart.defaults.global.defaultFontColor='red';
score:0
if we set the options as below then the font color of axes label values changes. For example I tried it on jsfiddle and it worked. The same also worked for my chart in rails app. ...
options: {
scales: {
yAxes: [{
ticks: {
beginAtZero:true,
fontColor:'red'
}
}]
}
}
...
score:0
To change your chart object ticks and axes labels, do like so:
let changeItemColor = (item) => {
item.scaleLabel.fontColor = color;
item.ticks.fontColor = color;
item.ticks.minor.fontColor = color;
item.ticks.major.fontColor = color;
};
chart.options.scales.xAxes.forEach((item) => changeItemColor(item));
chart.options.scales.yAxes.forEach((item) => changeItemColor(item));
chart.update();
score:0
React JS - Create React App
"chart.js": "^3.7.0",
"react-chartjs-2": "^4.0.0",
I struggled with this problem, unfortunately accepted answer did not work for me, but then I tweaked it little bit and made it work.
Here is what I ended up with, hope this will be helpful for someone...
const options = {
responsive: true,
maintainAspectRatio: false,
plugins: {
legend: {
position: 'top',
labels: {
color: "#ffffff",
}
},
title: {
display: true,
text: 'License Usage',
color: "#ffffff"
},
},
scales: {
yAxes: {
ticks: {
color: "#ffffff"
},
},
xAxes: {
ticks: {
color: "#ffffff"
},
}
},
};
score:4
I might be late to this question, but this answer may be useful for people who are looking for the answers.
In Chart.js, to style the scale label and ticks we can use the below settings.
options: {
scales: {
xAxes: [{
display: true,
scaleLabel: { // To format the scale label
display: true,
labelString: 'X axis name',
fontColor: '#000000',
fontSize: 10
},
ticks: {
fontColor: "black", // To format the ticks, coming on the axis/labels which we are passing
fontSize: 14
}
}],
yAxes: [{
display: true,
scaleLabel: {
display: true,
labelString: 'Y axis name',
fontColor: '#000000',
fontSize: 10
},
ticks: {
fontColor: "black",
fontSize: 14
}
}]
}
}
Please refer to the Chart.js documentation for all the properties. Study all the properties before doing your implementation.
Happy coding!
Source: stackoverflow.com
Related Query
- Change X and Y axis font color
- Change color of X and Y axis values in Chart.js
- chartjs datalabels change font and color of text displaying inside pie chart
- Is there any way to change the font color and size of labels in Chartjs 3.0.0
- Change label color Y and X axis chart.js
- How to change axis font in PrimeFaces and Chart.js
- Change font size and font color in Chartjs Angular 5
- Can't change the default color and font size of labels in react-chartjs-2
- Cannot change font color and box width in chart
- Remove y and x axis lines and change axis font style in Chartjs
- Change point size and color on hover in chartjs
- How to change the color of legend in chartjs and be able to add one more legend?
- Chartjs change the specific label color in x axis in callback function
- Chart.js: How can a line series (out of many) change line color and thickness upon mouse hover?
- ChartJS click on bar and change it's background color
- Change font family of labels in piechart and linechart in chartjs
- Change Axis Line color in Chart created using chart.js
- Chart.js: Chaing Font Color and Size not working
- How to change fonts and axis labels for Chart.js image rendering with QuickChart?
- ChatJS 2.8 chaning x-Axis font style and color
- chartkick chart.js change colour of axis and colour of axis title
- How to change the color of y axis labels in different color in Chart.js
- How can I change background color of a specific area in my chart's grid using Chart.js and Annotation?
- How to change chart.js grid, and axis color?
- Change the color of the legend box and the color of the x grid lines in chart.js
- Change color of X axis values to multi color values - Chart.js
- Angular-chart.js click on bar and change it's background color
- I am using chart js to draw a chart. I did everything right but i don't know why the x axis and y axis label is not comming in chart. code below
- (chart.js v3.5.1) change bar background, label font color on click
- how to change the label color and set y-axis values 1k intervals and hide y-axis?
More Query from same tag
- How do I remove cartesian axes from chart js?
- Chart.js bar chart: show tooltip on label hover
- Charts.js graph not scaling to canvas size
- Data not fully displaying on bar chart
- How can I show gridlines only of the even value ones withchartjs?
- Disable or hide YAixs of chart in chartJs
- Chartjs 3.5.0 - Radar Chart - Converting the labels to images
- How to send data from struts2 to a javascript function to draw a chart
- ngx-charts-advanced-pie-chart is reading my rest api response as null
- cannot view graph using toArray()
- Chartjs multi dimensional bar chart
- How do I get a chart.js chart to display data in a Node/React web application?
- Chart.JS Chart top left corner is blocked by some visual nodejs
- Chart.js 3.x not able to display data on chart
- How to show multiple datasets in line chart js
- Chart.js setting maximum bar size of bar chart
- chart.js pie chart background colors: is there any way to generate them randomly?
- How to refresh chart in django without refreshing whole page
- Removing ChartJS 2 border and shadow from point style legend
- Chartjs: How to offset ticks on radarchart?
- ChartJS tooltip issue
- ng2-charts - bar chart, showing only one color
- Chart.js only displays font changes upon hover
- Remove radar chart labels in chart.js
- how to display bars in chartjs
- Chart.js Line Graph: Start a line in the middle of a graph
- How can I hide points on chart?
- Is it possible to show each legends aligned with each bar in chart.js
- Why do literal arrays work, but not coded arrays?
- Align lines and bars in a mixed chart