I have a problem with the bubble chart. In fact, i have some points which have the same coordinates with a different name and maybe a different size (z point). For these points, i have a superposition of labels. The z-index solution doesn't work (https://stackoverflow.com/questions/15843238/highcharts-bubble-chart-datalabels-overlappinghttps://stackoverflow.com/questions/15843238/highcharts-bubble-chart-datalabels-overlapping).
Does anyone know of any solution to this problem ?
I thought to do a label connector like the pie chart but i do not how to do.
My code :
$(function () {
$('#container').highcharts({
credits: {
enabled: false
},
chart: {
type: 'bubble',
zoomType: 'xy'
},
title: {
text: ''
},
subtitle: {
text: ''
},
xAxis: {
categories:['R0', 'R1', 'R2','R3', 'R4', 'R5', 'R6']
},
yAxis: {
title: {
text: ''
}
},
plotOptions: {
bubble: {
dataLabels: {
enabled: true,
useHTML: true,
//inside: false,
//y:-10,
//overflow: false,
//crop: false,
style: { textShadow: 'none',fontSize: '10px',color:'black' },
formatter: function() {
return "<i>" + this.point.name.split(' ').join('<br>') + "</i>";
}
},
tooltip : {
headerFormat: '<b>{series.name}</b><br>',
pointFormat : 'S : <i>{point.name}</i><br>Y : {point.y}<br>Num : {point.z}'
}
}
},
series: [
{
name: 'Sample1',
marker: { fillColor: '#89A54E' },
data: [
{ name:'A',x:2,y:0.0,z:47},
{ name:'Z',x:3,y:1.0,z:35},
{ name:'E',x:4,y:0.5,z:9},
{ name:'R',x:0,y:1.0,z:34},
{ name:'T',x:3,y:0.0,z:37},
{ name:'T',x:2,y:0.0,z:22},
{ name:'p',x:0,y:1.0,z:39},
{ name:'m',x:2,y:0.5,z:47},
{ name:'h',x:0,y:0.5,z:48},
{ name:'l',x:5,y:1.0,z:25},
]
},
{
name: 'Sample2',
marker: { fillColor: '#92A8CD' },
data: [
{ name:'AB',x:2,y:0.5,z:23},
{ name:'CA',x:6,y:0.5,z:19},
{ name:'OP',x:3,y:0.5,z:21},
{ name:'CP',x:1,y:0.75,z:38},
{ name:'TS',x:3,y:1.0,z:13},
{ name:'SP',x:0,y:1.0,z:43},
{ name:'SE',x:4,y:1.0,z:2},
{ name:'CS',x:6,y:0.5,z:48},
{ name:'CL',x:1,y:0.5,z:5},
{ name:'H',x:1,y:0.0,z:11},
]
}
]
});
});
Apparently there is a labelrank property on the Highcharts point objects that can be used to dictate which point labels are on top. It can be used when you're creating your data like this:
data: [{
x: 1, y: 1, labelrank: 1, name: 'A'
},{
x: 1, y: 1, labelrank: 2, name: 'B'
}]
Or it can be updated on an individual point to bring that point's dataLabel to the front by doing something like this: chart.series[0].points[0].update({labelrank: 3});
I had a similar issue and created this question on SO that just was answered.
EDIT
They have updated their docs to include series.data.labelrank as well: http://api.highcharts.com/highcharts#series.data.labelrank
Related
I have a stacked column/scatter chart with some dataLabels off to one side. The issue I am facing is that when my two markers begin to get close to one another, their dataLabels overlap
I need to always show both labels, so is there a way to detect when labels are overlapping and move the bottom one down by adjusting its y value based on how much overlap there is?
sample fiddle of the issue
Highcharts.chart('container', {
chart: {
type: 'column',
width: 500
},
title: {
text: 'Stacked column chart'
},
xAxis: {
visible: false,
},
yAxis: {
min: 0,
visible: false,
title: {
},
},
legend: {
layout:"vertical",
align: "right",
verticalAlign: "bottom",
itemMarginTop: 15,
y: -10,
x: -50
},
tooltip: {
enabled: false,
},
plotOptions: {
scatter: {
marker: {
symbol: "triangle",
},
dataLabels: {
enabled: true,
x: -80,
y: 50,
allowOverlap: true,
useHTML: true,
}
},
column: {
pointWidth: 70,
stacking: 'normal',
dataLabels: {
enabled: false
}
}
},
series: [{
name: '',
data: [100],
color: "#ededed"
}, {
name: '',
data: [500]
}, {
name: '',
data: [400]
},
{
type: "scatter",
data: [1000],
color: "#000",
dataLabels: {
formatter: function(){
return "<div class='label-text'>Your goal of <br/>$"+ this.y +"<br/>text</div>"
},
}
},
{
type: "scatter",
data: [900],
color: "#000",
dataLabels: {
formatter: function(){
return "<div class='label-text'>You are here <br/>$"+ this.y +"<br/>text</div>"
},
}
}]
});
You can correct data-labels positions by using the attr method on their SVG elements.
For example:
chart: {
events: {
render: function() {
const series = this.series;
const dl1 = series[3].points[0].dataLabel;
const dl2 = series[4].points[0].dataLabel;
if (dl1.y + dl1.height > dl2.y) {
dl2.attr({
y: dl1.y + dl1.height
});
}
}
}
}
Live demo: https://jsfiddle.net/BlackLabel/5Lmh4owb/
API Reference:
https://api.highcharts.com/class-reference/Highcharts.SVGElement.html#attr
https://api.highcharts.com/highcharts/chart.events.render
I am trying to set the start of drawing column data from a minimum value, but cannot figure out how to do this. That is, that the axis starts with a value of -43, and not with 0 (see screenshots).
what i have
I want to get something like this:
what i want
chart: {
renderTo: 'container',
backgroundColor: 'transparent'
},
tooltip: {
formatter() {
return `${moment(this.x).format('MMM DD')}: ${this.y.toFixed(2)}`;
}
},
plotOptions: {
column: {
pointStart: -50,
dataLabels: {
enabled: true,
format: '{point.y:.2f}'
}
}
},
title: {
text: ''
},
yAxis: {
plotLines: [{
zIndex: 1,
color: '#5c5c5c',
value: 0,
width: 3,
}],
title: {
text: ''
}
},
xAxis: {
gridLineWidth : 1,
labels: {
formatter() {
return moment(this.value).format('MMM DD');
}
}
},
legend: {
enabled: false
},
series: [{
data: [...this.monthData.resultByDays.map(res => [res.date, res.result])],
type: 'column'
}]
I think that a good approach will be to use the columnrange series rather than basic column. In the columnrange it is possible to set the range where the point could start from.
Demo: https://jsfiddle.net/BlackLabel/ur6qgnbz/
And the code to hide the '-60' data label:
dataLabels: {
enabled: true,
formatter() {
if(this.y === -60) {
return false
} else {
return this.y
}
}
}
API: https://api.highcharts.com/highcharts/plotOptions.columnrange
I want to show tree map with different on different levels by using property 'colorByPoint' true.
Highcharts.chart('container', {
chart: {
marginTop: 50,
events: {
load: function() {
this.bread = {
'': makeNode('', this.series[0].name, this.series[0])
}
}
}
},
series: [{
type: 'treemap',
layoutAlgorithm: 'squarified',
allowDrillToNode: true,
animationLimit: 1000,
dataLabels: {
enabled: false
},
levelIsConstant: false,
levels: [{
level: 1,
dataLabels: {
enabled: true,
align:'left',
verticalAlign:'Top'
},
borderWidth: 1
},
{
level: 2,
colorByPoint: true,
dataLabels: {
enabled: true,
},
borderWidth: 1
}
],
data: points
}],
credits:false,
plotOptions: {
series: {
dataLabels: {
color: '#fff',
textOutline:0,
style: {
fontWeight: 'bold'
}
},
point: {
events: {
click: function(e) {
const hasChildren = !!this.node.childrenTotal
if (hasChildren) {
const bread = this.series.chart.bread
bread[this.id] = makeNode(this.id, this.name, this.series, bread[this.node.parent])
}
}
}
}
}
},
title: {
text: ''
}
});
Here is my js fiddle. https://jsfiddle.net/irfanbsse/8djawts9/
But I dont want show second level color on first level.Same for second level and so on. how i can do it ? Thanks
Here's a demo that shows how to change color of child nodes on point.click.event:
click: function() {
var points = this.series.points;
this.node.children.forEach(function(child, i) {
var point = points.find(function(point_) {
return child.id === point_.id
});
point.update({
color: color[i % (color.length - 1)]
});
});
Live demo: https://jsfiddle.net/BlackLabel/sgkah0fq/
The next thing to implement is reverting the original colors while clicking on the previous level in navigation (label with callout shape).
I use buttons to switch the chart type from pie to column and back. Pie is the default. When I switched to column, no categories are shown.
Image: Pie is the default
Here is a fiddle: http://jsfiddle.net/Gebifa/vLrx47a6/1/
I aleady tried to set x-axis categories but only got Highcharts Error 18 - The requested axis does not exist. Do anybody have an idea how to show the labels? Thanks in advance.
exporting: {
buttons: {
contextButton: {
symbol: 'url(../../img/chartexport.png)'
},
barButton: {
x: -30,
_titleKey: 'barChart',
onclick: function () {
$.each(this.series,function(i,serie){
serie.update({
type:'column',
tooltip: {
positioner: function () {
return { x: 0, y: 0 };
},
pointFormat: '<span style="color:{series.color}">{series.name}</span>: <b>{point.y}</b><br/>',
shared: true
}
});
});
},
symbol: 'url(../../img/chartButtonBar.png)'
},
pieButton: {
x: -60,
_titleKey: 'pieChart',
onclick: function () {
$.each(this.series,function(i,serie){
serie.update({
type:'pie',
tooltip: {
positioner: function () {
return { x: 0, y: 0 };
},
pointFormat: '<span style="color:{series.color}">{series.name}</span>: <b>{point.percentage:.2f}%</b><br/>',
shared: true
}
});
});
},
symbol: 'url(../../img/chartButtonPie.png)'
}
},
This might help you switching between two charts. Please provide fiddle if it does not fix the issue.
$('#Pie').click(function () {
chart.inverted = true;
chart.xAxis[0].update({}, false);
chart.yAxis[0].update({}, false);
chart.series[0].update({
type: 'pie'
});
}
http://jsfiddle.net/wvymmy80/
I think your xAxis configuration has a little issue, title is not required in xAxis configuration.Please try replacing below code.
xAxis: {
categories: ["20-29 years", "30-39 years", "40-49 years", "50-59 years", "60-69 years", ],
enabled: false,
text: '',
style: {
color: '#656565'
},
tickmarkPlacement: 'between',
labels: {
style: {
color: '#656565'
},
rotation: 0
},
crosshair: true
},
Fiddle: http://jsfiddle.net/xxLochh6/
I have a area chart build with highcharts, I am trying to reduce some spaces between y axis cell columns means reduce height from 0 to 1 , 1 to 2 etc, but not getting proper result. how to achieve it ?
jQuery(document).ready(function () {
var txt = document.getElementById('hdnYaxis');
var txtFoxXAxis = document.getElementById('hdnXaxis');
$('#container').highcharts({
chart: {
type: 'area'
},
title: {
text: 'Monthly Status'
},
xAxis: {
categories: $.parseJSON(txtFoxXAxis.value),
labels: {
style: {
color: 'red'
}
},
maxPadding: 0,
},
tooltip: {
pointFormat: '{series.name} <b>{point.y:,.0f}'
},
plotOptions: {
area: {
marker: {
enabled: false,
symbol: 'circle',
radius: 2,
states: {
hover: {
enabled: true
}
}
}
}
},
series: $.parseJSON(txt.value)
});
});
set tickPixelInterval in yAxis ,use this:
yAxis: {
tickPixelInterval: 10 // whatever you want
}
Set maxPadding on yAxis as 0.
yAxis:{
maxPadding:0
}