Reputation: 1166
How can I set background color to HighChart xAxis labels.
I tried the below but no luck
xAxis: { categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'], labels: { rotation: 90, style: { color: '#89A54E', fill: '#000', backgroundColor: '#FCFFC5', } }, backgroundColor: '#FCFFC5' }
Thanks in Advance Navin
Upvotes: 3
Views: 8559
Reputation: 217
Use only useHtml:true in your labels object { useHTML: true, formatter(val: any) { const category = props?.xAxis?.categories;
const findedItem = category.find(
(item: any) => item.count === val.value
);
return `<span
style="
padding:2px 4px;
color: #fff;
background: #000"
>
${val.value ? formatPrice(val.value) : 0}
</span>`;
},
}
}
Upvotes: 0
Reputation: 101
I think the answer to this could be a little tricky and but here are the steps I followed to fix it for me.
set chart Background to a color you want your xAxis and yAxis to have
chart: {
backgroundColor: '#eee',
},
then ass a polygon series to chart with max out y and x-axis with desired chart background
series: [
{
name: 'Extremely Bad',
type: 'polygon',
color: '#fff', // desired background for plot area
zIndex: 0,
data: []
},
{
name: '',
type: 'scatter', // desired series
data: [],
}]
and add z index to xAxis and y-axis to show gridlines
Upvotes: 0
Reputation: 111
xAxis: {
labels: {
useHTML: true,
formatter: function () {
return '<span class="xaxis-label">' + (this.value).toFixed(2) + '</span>';
}
}
}
then in css file
.xaxis-label {
background-color: #fff;
padding: 0px 5px;
font-size: 15px;
}
Does the trick.
Upvotes: 1
Reputation: 3554
While @dgw is technically correct in stating that the x-axis does not have a backgroundColor
property, there are alternatives you can use to achieve this effect.
renderer.rect()
function to draw a colored box at the bottom of your chart, behind the x-axis labels.I hope these resources will be helpful for others who come across this question.
Upvotes: 1
Reputation: 103
The answer by @dgw is not correct.
It's possible: you can set use HTML flag and add your own css style.
Upvotes: 3
Reputation: 13666
You can't. The xAxis object does not have the attribute backgroundColor.
Upvotes: -2