Add conditional color to Treemap - highcharts

Trying to add color to Heatmap. The color is based on the values with the following conditions.
if value 'equals or less than': -3.0 (green)
if value less than or equal to' -1.0 (red)
if value equals zero (grey)
if value 'greater than or equal to' 0.1 (orange)
if value 'greater than or equal to' 3.0 (purple)
https://jsfiddle.net/d_paul/rq862nuv/

What you defined as point's value, in fact it should be the point's colorValue. value is the information about the point's size, colorValue about its color. colorValue might be a negative number - value must not. If you want the point's size depends on its color, you need to transform colorValue scale to some positive scale, e.g. [1, 10].
If you define colorValue for points, then you can use colorAxis.dataClasses and the colors will be applied.
var dataMin = points.filter(p => !isNaN(p.value)).reduce((min, p) => Math.min(min, p.value), Infinity);
var dataMax = points.filter(p => !isNaN(p.value)).reduce((max, p) => Math.max(max, p.value), -Infinity);
var newMin = 1;
var newMax = 10;
function transformValue (value) {
return (newMax - newMin) * (value - dataMin) / (dataMax - dataMin) + newMin;
}
var transformedData = points.map(p => {
var transformedPoint = Object.assign({}, p);
if (p.value !== undefined) {
transformedPoint.value = transformValue(p.value);
transformedPoint.colorValue = p.value;
}
return transformedPoint;
});
Classes for colorAxis
colorAxis: {
dataClasses: [{
to: -3,
color: '#00ff00'
}, {
from: -3,
to: -1,
color: '#ff0000'
}, {
from: 0,
to: 0,
color: '#000000'
}, {
from: 0.1,
to: 3,
color: '#0000ff'
}, {
from: 3,
color: '#00ffff'
}]
},
example with the transformed data: https://jsfiddle.net/aepu6dvt/
example with the points with the same size: https://jsfiddle.net/aepu6dvt/1/

Related

Highcharts Multiseries Gauge with DataLabels at Ends

How would you achieve this (jsFiddle link)
dynamically for the Highcharts "Activity Gauge", so obviously it works there but I had to manually determine the correct x & y coordinates for the labels.
This result is similar to using the "inside" property for column charts, but seems nothing is built-in like that for this chart type (that I've run across at least). One could come close by passing in the same y values as for each series as tick marks on the y-axis (see snippet below) and getting rid of all markings except the number, but then I can't stagger those to be positioned correctly within each series, and for the dataLabel x & y approach I don't know the equation to be able to position the labels based on the series y values dynamically with a callback.
yAxis: {
labels: {
enabled: true,
x: 10, y: -15,
format: '{value} %',
style: {
fontSize: 16,
color: 'black'
}
},
min: 0,
max: 100,
gridLineColor: 'transparent',
lineColor: 'transparent',
minorTickLength: 0,
//tickInterval: 67,
tickPositions: [50, 65, 80], //TRIED TO USE Y-AXIS LABELS BUT COULDN'T STAGGER THEM
tickColor: '#000000',
tickPosition: 'inside',
//tickLength: 50,
tickWidth: 0
},
Any help would be much appreciated, thanks in advance.
Solved via Highcharts support forum:
fiddle
, just call the following function on chart load and redraw events:
function redrawConnectors() {
var chart = this,
cX, cY,
shapeArgs, ang, posX, posY, bBox;
Highcharts.each(chart.series, function(series, j) {
Highcharts.each(series.points, function(point, i) {
if (point.dataLabel) {
bBox = point.dataLabel.getBBox();
shapeArgs = point.shapeArgs;
cX = shapeArgs.x,
cY = shapeArgs.y,
ang = shapeArgs.end;
posX = cX + shapeArgs.r * Math.cos(ang);
posY = cY + shapeArgs.r * Math.sin(ang);
point.dataLabel.attr({
x: posX - bBox.width / 2,
y: posY - bBox.height / 2
});
}
});
});
}

Highcharts heatmap does not render correct colours according to specified colour stops

On a Highcharts heat map I specify the data in JSON format as follows:
var dataJson = [];
if (model.ActivityData != undefined) {
var index = 0;
if (model.ActivityData.length > 0) {
model.ActivityData.forEach(function(timeLineItem) {
dataJson.push({
x: $scope.getChartDate(timeLineItem.Date.split("T")[0]),
y: timeLineItem.IndicatorMeasure,
value: Math.round(timeLineItem.Amount * 100) / 100,
name: $scope.getChartDate(timeLineItem.Date.split("T")[0]),
});
});
}
}
"Value" is always between 0 and 1. I have added a tooltip showing "value" when hovering over a point.
I specify the colour stops as follows (it is
Orange: 0
White: 0.5
Green: 1
colorAxis: {
stops: [
[0, '#F9A847'],
[0.5, '#ffffff'],
[1, '#b1d4b1']
]
},
I would expect any values below 0.5 to be a shade of orange and any values over 0.5 to be a shade of green. However when the chart is rendered some values above 0.5 are orange.
Does Highcharts use "value" explicitly to set the colour and if so, why is it not respecting the specified colour tops. Or does highcharts adjust the colours by averaging (or something similar) to determine the colours.
Live demo at jsFiddle.
As you can see from the color axis, it extends from 0.4 to 0.7, which means that your middle color stop is actually as 0.55 in terms of axis values. The axis extremes is based on the data values.
So in order to make the axis extend from 0 to 1, like you probably expect, you need to set min and max. View jsFiddle.
colorAxis: {
stops: [
[0, '#F9A847'],
[0.5, '#ffffff'],
[1, '#b1d4b1']
],
min: 0,
max: 1
},

Highcharts navigator handle height

Is there any way to increase the height of the handles in the highstock navigator component? Right now, the only options available are to change the color and the border-color. How about the height and width of the handles?
http://api.highcharts.com/highstock#navigator.handles
Thanks,
Vikas.
You can wrap drawHandles function and modify it to have increased height.
var height = 20;
(function (H) {
H.wrap(H.Scroller.prototype, 'drawHandle', function (proceed, x, index) {
var scroller = this,
chart = scroller.chart,
renderer = chart.renderer,
elementsToDestroy = scroller.elementsToDestroy,
handles = scroller.handles,
handlesOptions = scroller.navigatorOptions.handles,
attr = {
fill: handlesOptions.backgroundColor,
stroke: handlesOptions.borderColor,
'stroke-width': 1
},
tempElem;
// create the elements
if (!scroller.rendered) {
// the group
handles[index] = renderer.g('navigator-handle-' + ['left', 'right'][index])
.css({
cursor: 'e-resize'
})
.attr({
zIndex: 4 - index
}) // zIndex = 3 for right handle, 4 for left
.add();
// the rectangle
tempElem = renderer.rect(-4.5, 0, 9, height, 0, 1)
.attr(attr)
.add(handles[index]);
elementsToDestroy.push(tempElem);
// the rifles
tempElem = renderer.path([
'M', -1.5, 4,
'L', -1.5, 12,
'M',
0.5, 4,
'L',
0.5, 12]).attr(attr)
.add(handles[index]);
elementsToDestroy.push(tempElem);
}
// Place it
handles[index][chart.isResizing ? 'animate' : 'attr']({
translateX: scroller.scrollerLeft + scroller.scrollbarHeight + parseInt(x, 10),
translateY: scroller.top + scroller.height / 2 - 8
});
});
}(Highcharts));
http://jsfiddle.net/za68w54r/
There is an option for increasing the height of the navigator too..
Check this fiddle:
http://jsfiddle.net/gh/get/jquery/1.7.2/highslide-software/highcharts.com/tree/master/samples/stock/navigator/height/
Code:
navigator: {
height: 100
},

highcharts datalabel dynamic rotation as column height

As you can see in the picture each column is accompanied by its datalabels, all is well. The detail is when small amounts and their datalabels is misconfigured with the categories, as seen in the picture (Red square). What I want to do is check if your height is less, to change its rotation from -90 to 0 (Green letters)
See picture of the solution (HighCharts) here:
https://docs.google.com/file/d/0B93NeaQX1VjUMldzcGIxNnBqaWc/edit
See code JSFiddle of my solution (HighCharts) here :
http://jsfiddle.net/bryan376/325dev4h/1/
This is my code push of series:
options.series.push({
name: 'Vendedor',
data: arrFinal,
dataLabels: {
enabled: true,
rotation: -90, //Validation height < 70 "rotation=0" else rotation=-90
color: 'black',
align: 'right',
x: 4,
y: 10,
style: {
fontSize: '11px',
fontFamily: 'Verdana, sans-serif'
}
}
});
var chart = new Highcharts.Chart(options);
}
Greetings
You can change Highcharts.Series.prototype.drawDataLabels, the function to draw the dataLabels:
Highcharts.Series.prototype.drawDataLabels = (function (func) {
return function () {
func.apply(this, arguments);
if (this.options.dataLabels.enabled || this._hasPointLabels) realignLabels(this);
};
}(Highcharts.Series.prototype.drawDataLabels));
realignLabels would be the function to check for the shorter columns, and in it change the rotation, x and y of that specific dataLabel:
function realignLabels(serie) {
$.each(serie.points, function (j, point) {
if (!point.dataLabel) return true;
var max = serie.yAxis.max,
labely = point.dataLabel.attr('y'),
labelx = point.dataLabel.attr('x');
if (point.y / max < 0.05) {
point.dataLabel.attr({
y: labely - 20,
x: labelx + 5,
rotation: 0
});
}
});
};
http://jsfiddle.net/325dev4h/7

Change the color of bar on condition in highcharts

I am using highcharts and I want to change the color of bar depending on their Y axis values.
Something like:
{
color: '#92D050', //DEFAULT COLOR OF CURRENT YEAR BAR ON EACH GROUP
name: 'AUG',
shadow: false,
data: [
{ y: 66, color: '#92D050' },
{ y: 55, color: 'red' },
{ y: 78, color: '#92D050' },
{ y: 55, color: 'red'}
]
}
Here how can I apply codition like y: > 60
You can iterate for each element and modify SVG parameter like fill.
http://jsfiddle.net/CaPG9/
var max = 200;
$.each(chart.series[0].data,function(i,data){
if(data.y > max)
data.graphic.attr({
fill:'red'
});
});
It doesn't work, cause if you put the mouse over the columns, the color reset for the original.
I solved with this code, using a variable that counts how many columns I want to color. In my case, j is set before to 6.
var j = 6;
$.each(chart.series[0].data, function(i,data){
for (var n = 0; n <= j; n++) {
chart.series[0].data[n].update({color:'#441606'});
}
});

Resources