score:36
You can also use the label-formatter to set the style. Full example on jsfiddle:
labels: {
formatter: function () {
if ('Jun' === this.value) {
return '<span style="fill: red;">' + this.value + '</span>';
} else {
return this.value;
}
}
}
score:1
I am using dataLabels in a doughnut pie chart. I wanted to change the label text colors for individual pie slices, based on conditional logic, comparing values.
Just sharing because my search brought me here.
data: outerData,
dataLabels: {
formatter:
function () {
if ((outerData[this.point.x].y > innerData[this.point.x].y) && (this.point.x != 0)) {
return this.y > 0.1 ? '<span style="fill: red;">' + this.point.name + ': ' + this.y + '% ' + '</span>' : null;
} else {
return this.y > 0.1 ? '<span style="fill: #006400;">' + this.point.name + ': ' + this.y + '% ' + '</span>' : null;
}
}
}
score:1
xAxis: {
categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
labels: {
formatter: function () {
if ('Jan' === this.value) {
return '<span style="fill: blue;">' + this.value + '</span>';
} else {
return this.value;
}
}
}
},
score:2
Note that when you use the highcharts exporting server at exporting.highcharts.com to render images for your graphs, javascript formatters will not be executed.
Fortunately highcharts translates some html tags and style attributes of individual label and title strings into equivalent SVG styling, but it is quite finicky about how it parses the html. It will strip tags that are using single quoted attributes, you need to use double quotes. Also, nesting a <br/>
tag inside another tag will not work.
So if you want two lines of text colored red for example, you get:
<span style="color: #ff0000">First line</span> <br/>
<span style="color: #ff0000">Second line</span>
score:4
I understood that you want to change the color for a specific item inside the x-axis.
I looked at the API but i didn't found an easy way to do it.
Since you can set a callback for the "chart ready event":
Chart (Object options, Function callback) :
Parameters
options: Object The chart options, as documented under the heading "The options object" in the left menu.
callback: Function
A function to execute when the chart object is finished loading and rendering. In most cases the chart is built in one thread, but in Internet Explorer version 8 or less the chart is sometimes initiated before the document is ready, and in these cases the chart object will not be finished directly after calling new Highcharts.Chart(). As a consequence, code that relies on the newly built Chart object should always run in the callback. Defining a chart.event.load handler is equivalent.
Returns: A reference to the created Chart object.
You can do it in a dirty way:
$(function () {
var chart = new Highcharts.Chart({
chart: {
renderTo: 'container',
marginBottom: 80
},
xAxis: {
categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
labels: {
style: {
color: 'red'
}
}
},
series: [{
data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4]
}]
},
function(c){
// this relies in that te xAxis is before the yAxis
// also, setting the color with color: #ABCDEA didn't work
// you have to use fill.
$(".highcharts-axis:first text").each(function(i, label){
var $label = $(label);
if($label.children().text() === "Jun") {
$label.css({fill: "blue"});
}
});
// You also can to something like:
$(".highcharts-axis:first text:eq(6)").css({fill: "green"});
})
});
Hope this helps you
Source: stackoverflow.com
Related Query
- Highchart - change color of one x-axis label only
- How to set series-label to false by default and change the color of series label text in highchart
- Change a highchart x axis Label
- Change color of bars depending on value in Highchart bar-chart with MVC3
- Disable marker hover in only one marker of highchart
- Can color of data label be different inside and outside of the bar in Highchart
- Change Y Axis vertical line color in Highcharts
- highcharts - removing decimal places on Y axis with only one point
- How to dynamically change axis from linear to logarithmic in HighChart
- How to change axis label size when exporting in Highcharts / Highstock
- How to change series legend text color in HighChart chart?
- Highcharts.js - Background color of axis only
- last label in x axis with datetime format not coming in highchart
- Highcharts - change color of only clicked column
- Highcharts: Change color of bubbles in one serie
- How to change Highcharts xAxis label color individually?
- highchart change color of single bar in single category
- How to Change Highchart Column Color Dynamicly
- highchart Axis values color
- HighCharts - Dynamically Change Axis Title Color
- Need to change title color donut highchart
- Update color of plotline label on change highcharts
- how to change color of line chart in highchart based on a categorical column in r?
- Set background color for only one pane in multi-pane Highstock chart
- How to remove label incase column has only one item
- How to change one point color on click in Highcharts
- Change color code on colum, depending on data value (highchartJS)
- Pan one of multiple Y axis for highchart
- Change the color of legend symbol highchart
- Highchart Axis with only min and max series value
More Query from same tag
- HighCharts refresh size?
- Applying custom style on ticks of Highchart
- HighChart pointPlacement on y-axis
- dates cannot be shown on highcharts
- Line chart Y axix value not show with single data
- How to show first and last date ticks in the navigator - Highcharts?
- WebPack and Require
- Highcharts: locating column group information on mouseover
- set the background color for column group graphs in highcharts
- Mouse out event on highcharts
- Highcharts Line Chart with multicolor area
- How to extend X axis datetime in Highchart
- Javascript relative time 24 hours ago etc as time
- How To Use Highmaps Data In JSON Not Labeled 'value'
- How to get data in Highstock from PHP MySQL data on AJAX call
- Uncaught TypeError: undefined is not a function - Highcharts - MVC
- Fixed Datalabel dimensions in Highcharts Series DataLabels
- How to use HighCharts dart library in Flutter app?
- Size and offset for plotBackgroundImage in Highcharts
- highchart not displaying in the center on mobile screen
- Highcharts: Show x-axis labels ony for years ending in zero (1950, 1960, 1970, ...)
- Chart not resizing according to it's container Highcharts reactjs
- How do I get x-axis to expand to take more of the chart width
- Highcharts loading data from a table generated by Ajax
- How to create more gap between axis labels on a stacked bar chart?
- high charts parse json data
- Highcharts view data table is showing incorrect data
- Multiple series highstock live chart
- Is it possible to plot time series on top of a heat map in highcharts?
- Highcharts prevent xAxis Labels hidden