HighCharts : Shared Tooltip with shared Data LABELS (in Series) - highcharts

I have a simple HighChart here ----> jsFiddle
By having a Serie like this:
series: [{
name: 'Cities',
data: [
["Paris", 29.9],
["London", 71.5],
["New York", 106.4]
]
},
{
name: 'Universities',
data: [
["Cambridge", 17.5],
["Oxford", 1.5],
["MIT", 16.4]
]
}
]
There a shared Tooltip (a hover tooltip to display both series information in a single box) can only display the TOP NAME of the Series. Instead,
I want the respective CITY name and UNIVERSITY name in the TOOLTIP box.
For example, it should show:
----------------------
| • Paris: 29.9 |
| • Cambridge: 17.5 |
----------------------
Or, at least it should show:
------------------------------------
| • Cities: 29.9 (Paris) |
| • Universities: 17.5 (Cambridge) |
------------------------------------
Some thing like that.
(But now it is just showing the Serie Name)
How to do it please?

You can use the formatter function of tooltip for this.
http://api.highcharts.com/highcharts#tooltip.formatter
Demo: http://jsfiddle.net/robschmuecker/qSfJw/2/
$(function () {
$('#container').highcharts({
tooltip: {
shared: true,
formatter: function () {
console.log(this.points);
return this.points[0].key + ' : ' + this.points[0].y + '<br/>' + this.points[1].key + ' : ' + this.points[1].y;
}
},
series: [{
name: 'Cities',
data: [
["Paris", 29.9],
["London", 71.5],
["New York", 106.4]
]
}, {
name: 'Universities',
data: [
["Cambridge", 17.5],
["Oxford", 1.5],
["MIT", 16.4]
]
}]
});
});

Related

Hightchart - Series refers to many xAxis

We are using spline graph : https://api.highcharts.com/highcharts/series.spline.xAxis
In our code we have 2 xAxis:
xAxis: [
{
categories: formattedValues,
},
{
categories: axisFiltered,
},
],
My series :
series: [
{
name: `Satisfaction`,
data: formattedValues,
},
{
name: `Bottom`,
data: formattedBottomValues,
},
{
name: `Top`,
data: formattedTopValues,
},
{
name: `$Average`,
data: formattedAverageValues,
},
],
Into our series i want to refer to the 2 xAxis and not only one. In documentation it says we can refer to only one xAxis by series :
For example in my series i would like to do that :
series: [
{
name: `Satisfaction`,
data: formattedValues,
xAxis: [0, 1]
},
{
name: `Bottom`,
data: formattedBottomValues,
xAxis: [0, 1]
},
{
name: `Top`,
data: formattedTopValues,
xAxis: [0, 1]
},
{
name: `$Average`,
data: formattedAverageValues,
xAxis: [0, 1]
},
],
But the problem is currently we are allow only to do this :
series: [
{
name: `Satisfaction`,
data: formattedValues,
xAxis: 1
},
{
name: `Bottom`,
data: formattedBottomValues,
xAxis: 0
},
{
name: `Top`,
data: formattedTopValues,
xAxis: 1
},
{
name: `$Average`,
data: formattedAverageValues,
xAxis: 0
},
],
The problem with that is, when i click on the legend to hide a serie, it will hide the xAxis associated. But me i don't want this xAxis to be hide because it's usefull for other series.
Settings that give the possibility to adjust xAxis are xAxis.min and xAxis.max then they will stick to the second axis and the extremes will not change depending on the series.
xAxis: [{
title: {
text: 'Data'
},
}, {
title: {
text: 'Histogram'
},
alignTicks: false,
opposite: true,
min: 0,
max: 11
}],
Demo: https://jsfiddle.net/BlackLabel/hymjs0wL/

Display start and end date range in timeseries LineChart using HighCharts

I have a simple line chart where I am trying to display time series data which have start and end. Like this
{"beginTimeSeconds": 1626145840, "endTimeSeconds": 1626232240, "totalTimeInSeconds": 0, "uri": "/logout"}
However, as per HighChart config timeseries only accept one timestamp like this.
Highcharts.chart('container', {
chart: {
zoomType: 'x'
},
xAxis: {
type: 'datetime'
},
yAxis: {
title: {
text: 'test'
}
},
legend: {
enabled: false
},
series: [{
type: 'line',
name: 'Test',
data: [
[1167609600000, 0.7537], // Only one timestamp
[1167696040000, 0.7537] // Only one timestamp
]
}]
});
Is there any way to pass range so that tooltip shows Start date - end date followed by value.
So by default in Highcharts, your point contains 4 main attributes which you can specify. Its x and y value, its name, and color. API reference: https://api.highcharts.com/highcharts/series.line.data
If you'd like your point to have some more attributes you can add them and e.g use one of them in the tooltip. Something like that: https://jsfiddle.net/BlackLabel/k49z8mv0/
Highcharts.chart('container', {
chart: {
zoomType: 'x'
},
xAxis: {
type: 'datetime'
},
yAxis: {
title: {
text: 'test'
}
},
legend: {
enabled: false
},
tooltip: {
formatter: function() {
return 'Point value is: ' + this.y + '<br/>The total time in Second
equals: ' + this.point.totalTimeInSeconds + '<br/>' +
Highcharts.dateFormat('%Y-%m-%d', this.point.beginTimeSeconds) + ' -
' + Highcharts.dateFormat('%Y-%m-%d', this.point.endTimeSeconds);
}
},
series: [{
type: 'line',
name: 'Test',
data: [{
x: 1167609600000,
y: 0.7537,
beginTimeSeconds: 1626145840,
endTimeSeconds: 1626232240,
totalTimeInSeconds: 0
},
{
x: 1167696040000,
y: 0.7537,
beginTimeSeconds: 1626145840,
endTimeSeconds: 1626232240,
totalTimeInSeconds: 1
}
]
}]
});
If that doesn't answer your question please precise what the issue is.

Hide a specific series legend in a column chart with multiple series

I'm trying to create a chart using Chartkick that has multiple series of data. The thing is that the two sets represent the same data points at different points in the year, so the legend has the labels duplicated. Is there a way to hide one of them by series?
Here's what my current chart looks like. (The left bar represents the beginning of the year & the right represents the end of the year.)
This is the code for my chart right now: (for testing purposes, the same data hash is used for both sets)
total_effort_data = [
{ name: "Academic", data: academic_hash, stack: "9/1" },
{ name: "Administrative", data: administrative_hash, stack: "9/1" },
{ name: "Clinical", data: clinical_hash, stack: "9/1" },
{ name: "Research", data: research_hash, stack: "9/1"} ,
{ name: "Academic", data: academic_hash, stack: "8/31" },
{ name: "Administrative", data: administrative_hash, stack: "8/31" },
{ name: "Clinical", data: clinical_hash, stack: "8/31" },
{ name: "Research", data: research_hash, stack: "8/31" }, ]
...
<%= column_chart total_effort_chart_path,
stacked: true, legend: "top", suffix: "%", max: 100,
colors: ["#FFDB80", "#F7A791", "#C8EA80", "#CAE9F4"] %>
And, on a side note, is it possible to add the "9/1" & "8/31" labels to below the axis under each column (above the year range)?
Use showInLegend and linkedTo properties:
series: [..., {
data: [3, 2, 1],
showInLegend: false,
linkedTo: 'series1'
}]
It should probably look like below in your code:
total_effort_data = [
{ name: "Academic", data: academic_hash, stack: "9/1", id: "academic" },
...,
{ name: "Academic", data: academic_hash, stack: "8/31", showInLegend: false, linkedTo: "academic" },
...
]
Live demo: http://jsfiddle.net/BlackLabel/ocxyfv42/
API Reference:
https://api.highcharts.com/highcharts/series.column.showInLegend
https://api.highcharts.com/highcharts/series.column.linkedTo

How can I get every bar in different colour using Highchart?

The Highchart graph code is shown below I want every bar label color is different. Currently, I'm getting the same color in bar
Highcharts.chart('container', {
chart: {
type: 'column',
},
title: {
text: 'Popular '
},
credits:{
enabled:false
},
xAxis: {
max: 20,
type: 'category',
style:{
fontSize: '12px'
}
},
yAxis: {
min: 0,
allowDecimals:false,
title: {
text: 'Number of applications',
style:{
fontSize: '12px'
}
},
gridLineWidth:0,
minorGridLineWidth: 0,
tickLength: 5,
tickWidth: 1,
tickPosition: 'inside',
lineWidth:1
},
scrollbar: {
enabled: true
},
legend: {
enabled: false
},
tooltip: {
pointFormat: 'hi'
},
series: [{
name: Stats',
data: data,
color:'#2ecc71',
pointWidth: 25,
}],
Data format is :
[
[
"Qualcom",
17
],
[
"The ram",
12
],
[
"Aoperty",
8
],
[
"Ob.",
8
],
[
"Sugh",
8
],
]
The output is shown in the picture I want every bar is in a different color can you help me?
Referring to comments you can set a specific color to a single point by adding a color property programmatically to its object like that:
series: [{
data: [
["Qualcom", 17],
{
name: "The ram",
y: 12,
color: 'red'
},
["Aoperty", 8],
["Ob.", 8],
["Sugh", 8]
],
color: '#2ecc71'
}]
API reference:
https://api.highcharts.com/highcharts/series.column.data.color
Demo:
https://jsfiddle.net/BlackLabel/craqy1sv/1/
If you want to add a specific color to a point when a condition is matched you can loop through each series point in chart load event and update a matched point:
chart: {
type: 'column',
events: {
load: function() {
var chart = this,
series = chart.series[0];
series.points.forEach(function(point) {
if (point.name === 'The ram') {
point.update({
color: 'red'
})
}
});
}
}
}
API reference:
https://api.highcharts.com/highcharts/chart.events.load
https://api.highcharts.com/class-reference/Highcharts.Point#update
Demo:
https://jsfiddle.net/BlackLabel/jmuoevz1/
You need to set colorByPoint :true to use different colors like that
series: [{
name: 'Stats',
data: [
[
"Qualcom",
17
],
[
"The ram",
12
],
[
"Aoperty",
8
],
[
"Ob.",
8
],
[
"Sugh",
8
]
],
colorByPoint: true,
pointWidth: 25,
}]
Fiddle

Highcharts population pyramid opposite x axis not labeled correctly when using axis type 'category'

I adapted the highcharts population pyramid (https://jsfiddle.net/gh/get/library/pure/highcharts/highcharts/tree/master/samples/highcharts/demo/bar-negative-stack/) as follows:
I omitted the option "categories", instead used the option "type: 'category'" and added the categories to the data series. I want to do this because the data comes as a tuple from a file. Unfortunately, the right-hand x-axis is not labeled correctly. I want the right hand x-axis labeled same as the left one. Is this possible without using the option "categories"?
Here is the jsfiddle: https://jsfiddle.net/nehqb9k4/
chart : {
renderTo: 'container',
type: 'bar',
height: 480,
},
xAxis : [{
type: 'category',
reversed: false,
}, { // mirror axis on right side
type: 'category',
opposite: true,
linkedTo: 0,
reversed: false,
}],
yAxis: {
title: {
text: null
},
labels: {
formatter: function () {
return Math.abs(this.value) + '%';
}
}
},
plotOptions: {
series: {
stacking: 'normal'
}
},
series: [{
name: 'Male',
data: [
['0-4', -2.2],
['5-9', -2.1],
['10-14', -2.2],
['15-19', -2.4],
['20-24', -2.7],
['25-29', -3.0],
['30-34', -3.3],
['35-39', -3.2],
['40-44', -2.9],
['45-49', -3.5],
['50-54', -4.4],
['55-59', -4.1],
['60-64', -3.4],
['65-69', -2.7],
['70-74', -2.3],
['75-79', -2.2],
['80-84', -1.6],
['85-89', -0.6],
['90-94', -0.3],
['95-99', -0.0],
['100 +', -0.0]
]
}, {
name: 'Female',
data: [
['0-4', 2.1],
['5-9', 2.0],
['10-14', 2.1],
['15-19', 2.3],
['20-24', 2.6],
['25-29', 2.9],
['30-34', 3.2],
['35-39', 3.1],
['40-44', 2.9],
['45-49', 3.4],
['50-54', 4.3],
['55-59', 4.0],
['60-64', 3.5],
['65-69', 2.9],
['70-74', 2.5],
['75-79', 2.7],
['80-84', 2.2],
['85-89', 1.1],
['90-94', 0.6],
['95-99', 0.2],
['100 +', 0.0]
]
}]
You need to set the right xAxis for the second series:
series: [{
// xAxis: 0 by default
name: 'Male',
data: [
...
]
}, {
name: 'Female',
xAxis: 1,
data: [
...
]
}]
Live demo: https://jsfiddle.net/BlackLabel/70yv1Lae/
API: https://api.highcharts.com/highcharts/series.bar.xAxis

Resources