I'm adding a series to my Highcharts chart. I'm trying to make that specific series' tooltip have a certain shape. I know that you can change the tooltip shape for the whole chart, but I want each series to have a specific one. How do I accomplish this.
P.S. This doesn't work:
chart.addSeries({
...stuff...
tooltip: {
shape: "triangle-down"
}
});
The API states that only a subset of properties are used from the Series.tooltip options. The shape attribute is not one of them. However, one way to get around this is to extend the Tooltip.refresh function to do a full redraw of the tooltip, and supplying the shape argument there.
For example:
$(function() {
(function (H) {
H.wrap(H.Tooltip.prototype, 'refresh', function (proceed, pointOrPoints, mouseEvent) {
this.update({ shape: pointOrPoints.series.tooltipOptions.shape });
return proceed.apply(this, Array.prototype.slice.call(arguments, 1));
});
}(Highcharts));
Highcharts.chart('container', {
tooltip: {
shape: 'triangle-down', // Global shape
},
series: [{
tooltip: {
shape: 'diamond' // Specific shape for series
},
data: [24916, 24064, 29742, 29851, 32490, 30282, 38121, 40434]
}, {
tooltip: {
shape: 'circle' // Specific shape for series
},
data: [11744, 17722, 16005, 19771, 20185, 24377, 32147, 39387]
}, {
tooltip: {
shape: 'square' // Specific shape for series
},
data: [0, 0, 7988, 12169, 15112, 22452, 34400, 34227]
}, {
data: [12908, 5948, 8105, 11248, 8989, 11816, 18274, 18111]
}],
});
});
#container {
min-width: 310px;
max-width: 800px;
height: 400px;
margin: 0 auto
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://code.highcharts.com/modules/export-data.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
<script src="https://code.highcharts.com/modules/series-label.js"></script>
<script src="https://code.highcharts.com/highcharts.js"></script>
<div id="container"></div>
This shows overriding the Tooltip.refresh and then using pointOrPoints.series.tooltipOptions.shape to fetch the tooltip.shape for the specific series. Note that this will be more resource intensive as the tooltip is recreated for each tooltip.refresh, as the shape can only be altered upon label creation.
Related
Problem
Run the snippet below in Firefox browser and the top tooltip label is "open". How does one replace the top tooltip label "open" with the new label "Adjusted"?
This is the csv data in the original snippet code:
<pre id="csv" style="display: none">
date,open,high,low,close
2006-05-20, 63.26, 64.88, 62.82, 64.51
2006-05-22, 63.87, 63.99, 62.77, 63.38
</pre>
Forced Solution
In the code snippet I can force the desired result by replacing the CSV header "open" with the name "Adjust" as shown below:
<pre id="csv" style="display: none">
date,Adjust,high,low,close
2006-05-20, 63.26, 64.88, 62.82, 64.51
2006-05-22, 63.87, 63.99, 62.77, 63.38
</pre>
However I prefer to change the name in the tooltip rather than to change the header in the CSV so I do not regard this as an approved solution.
Snippet
<html>
<head>
<title>
AAPL Combined OHLC and Moving Average
</title>
<script src="https://code.highcharts.com/stock/highstock.js"></script>
<script src="https://code.highcharts.com/modules/data.js"></script>
</head>
<body>
<div id="chart-container" style="width: 100%; height: 100%; margin: 0 auto"></div>
<pre id="csv" style="display: none">
date,open,high,low,close
2006-05-20, 63.26, 64.88, 62.82, 64.51
2006-05-22, 63.87, 63.99, 62.77, 63.38
2006-05-23, 64.86, 65.19, 63.00, 63.15
2006-05-24, 62.99, 63.65, 61.56, 63.34
2006-05-25, 64.26, 64.45, 63.29, 64.33
2006-05-26, 64.31, 64.56, 63.14, 63.55
2006-05-30, 63.29, 63.30, 61.22, 61.22
2006-05-31, 61.76, 61.79, 58.69, 59.77
</pre>
<script type="text/javascript">
Highcharts.stockChart('chart-container', {
rangeSelector: {
selected: 2
},
title: {
text: 'AAPL Stock Price'
},
plotOptions: {
series: {
turboThreshold: 0
},
ohlc: {
color: 'black',
tooltip: {
// pointFormat: 'Adjusted'
}
}
},
data: {
csv: document.getElementById('csv').innerHTML,
seriesMapping: [{
x: 0,
open: 1,
high: 2,
low: 3,
close: 4
}]
},
series: [{
type: 'ohlc', // bars
visible: true,
// set color in plotOptions
tooltip: {
// pointFormat: 'Adjusted'
}
}]
});
</script>
</body>
</html>
IF I uncomment either or both pointFormat statements (in the tooltip options shown above) THEN the Open, High, Low, and Close data no longer display in the tooltip pop-up. Instead only the word "Adjusted" appears in the tooltip.
Set name for the series, disable firstRowAsNames property and set startRow to 1 in data options:
data: {
firstRowAsNames: false,
startRow: 1,
...
},
series: [{
name: 'Adjust',
...
}]
Live demo: http://jsfiddle.net/BlackLabel/fkh0oa2s/
API Reference:
https://api.highcharts.com/highstock/data
https://api.highcharts.com/highstock/series.ohlc.data
I want to render a Highcharts column range chart to show runtimes of an application, with the date rendered on the x axis. However, the total timeframe that needs to be shown is more than what fits reasonably in a screen width. I see that highstock.js has a scrollbar feature, but I also see that adding a reference to highstock.js, and adding a scrollbar property in the appropriate axis is not sufficient to make a scrollbar appear. I've put an example on jsfiddle at http://jsfiddle.net/k21pzh60/3/. If I want only the timeframe from Sept 10 onward to show on the screen by default, with a scrollbar that allows the user to go backwards in time to see the Sept 6 run, is that possible?
Here is the HTML from the JsFiddle:
<script src="http://code.highcharts.com/highcharts.js"></script>
<script src="http://code.highcharts.com/highcharts-more.js"></script>
<script src="http://code.highcharts.com/modules/exporting.js"></script>
<script src="http://code.highcharts.com/stock/highstock.js"></script>
<div id="container" style="min-width: 310px; height: 400px; margin: 0 auto"></div>
And the js from the JsFiddle:
$(function () {
$('#container').highcharts({
chart: {
type: 'columnrange',
inverted: true
},
title: {
text: 'Times'
},
subtitle: {
text: 'Planned and Actual Runtimes'
},
xAxis: {
categories: ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i']
},
yAxis: {
type: 'datetime',
title: {
text: 'DateTime'
}
},
tooltip: {
formatter: function () {
var duration = this.point.high - this.point.low;
var hours1=parseInt(duration/3600000);
var mins1=parseInt((parseInt(duration%3600000))/60000);
return 'Duration: ' + (hours1 < 10 ? '0' + hours1 : hours1) + ':' + (mins1 < 10 ? '0' + mins1 : mins1);
}
},
plotOptions: {
columnrange: {
dataLabels: {
enabled: true,
formatter: function () {
return Highcharts.dateFormat('%H %M',this.y);
}
}
}
},
legend: {
enabled: false
},
series: [{
name: 'Planned Runtime',
data: [
['a', 1568242800000, 1568246400000],
['b', 1568044800000, 1568044800000],
['c', 1567728000000, 1567728180000],
['i', 1568156400000, 1568160000000]
]
}, {
name: 'Actual Runtime',
data: [
['a', 1568329200000, 1568329200000],
['b', 1568300400000, 1568300400000],
['c', 1568300400000, 1568307600000],
['d', 1568275200000, 1568390400000],
['e', 1568296800000, 1568296800000],
['f', 1568296800000, 1568300400000],
['g', 1568300400000, 1568300400000],
['h', 1568260800000, 1568264400000],
['i', 1568221200000, 1568221200000], ]
}]
});
});
Thank you!
You can use chart.scrollablePlotArea to achieve what you expect in Highcharts.
Code:
chart: {
type: 'columnrange',
inverted: true,
scrollablePlotArea: {
minWidth: 2000,
scrollPositionX: 2000
}
}
Demo:
http://jsfiddle.net/BlackLabel/j2kauod8/
API reference:
https://api.highcharts.com/highcharts/chart.scrollablePlotArea
I'm trying to duplicate the Highmaps Demos › Map bubble except that I want to add other charts to the same page. When I load the Highcharts script and the Highmaps module script, the chart doesn't render. The browser throws a generic error. See jsfiddle for the example.
https://jsfiddle.net/hkjbn6wg/1/
<script src="http://code.highcharts.com/highcharts.js"></script>
<script src="http://code.highcharts.com/maps/modules/map.js"></script>
<script src="http://code.highcharts.com/maps/modules/data.js"></script>
<script src="http://code.highcharts.com/mapdata/custom/world.js"></script>
<div id="container" style="height: 500px; min-width: 310px; max-width: 800px; margin: 0 auto"></div>
$(function () {
$.getJSON('http://www.highcharts.com/samples/data/jsonp.php?filename=world-population.json&callback=?', function (data) {
var mapData = Highcharts.geojson(Highcharts.maps['custom/world']);
// Correct UK to GB in data
$.each(data, function () {
if (this.code === 'UK') {
this.code = 'GB';
}
});
$('#container').highcharts('Map', {
chart : {
borderWidth : 1
},
title: {
text: 'World population 2013 by country'
},
subtitle : {
text : 'Demo of Highcharts map with bubbles'
},
legend: {
enabled: false
},
mapNavigation: {
enabled: true,
buttonOptions: {
verticalAlign: 'bottom'
}
},
series : [{
name: 'Countries',
mapData: mapData,
color: '#E0E0E0',
enableMouseTracking: false
}, {
type: 'mapbubble',
mapData: mapData,
name: 'Population 2013',
joinBy: ['iso-a2', 'code'],
data: data,
minSize: 4,
maxSize: '12%',
tooltip: {
pointFormat: '{point.code}: {point.z} thousands'
}
}]
});
});
});
The error is printed, because you miss highcharts-more.js file.
Add the reference to this file and example will work.
<script src="http://code.highcharts.com/highcharts-more.js"></script>
http://jsfiddle.net/hkjbn6wg/2/
I'm trying to apply the new threshold/negativeColor features of Highcharts v3.0.2 to essentially the 'spline updating each second' example.
During the animation of the chart updating, I'm seeing weird artifacts in the series line - it looks like it's animating to a different set of control points.. and then it snaps back to the correct configuration when the animation (of the new data point coming in) is done.
Commenting out the threshold/negativeColor features makes this visual artifact go away.
Am I seeing a bug?
UPDATE: I'm posting the following code as an example, which is the stock highcharts demo (my local jquery is v1.10.2) with the threshold/color/negativeColor lines (first lines under series) added by me. This code seemingly misbehaves.
<html>
<head>
<script src="js/jquery.min.js"></script>
<script src="http://code.highcharts.com/highcharts.js"></script>
<script src="http://code.highcharts.com/modules/exporting.js"></script>
<script>
$(function () {
$(document).ready(function() {
Highcharts.setOptions({
global: {
useUTC: false
}
});
var chart;
$('#container').highcharts({
chart: {
type: 'spline',
animation: Highcharts.svg, // don't animate in old IE
marginRight: 10,
events: {
load: function() {
// set up the updating of the chart each second
var series = this.series[0];
setInterval(function() {
var x = (new Date()).getTime(), // current time
y = Math.random();
series.addPoint([x, y], true, true);
}, 1000);
}
}
},
title: {
text: 'Live random data'
},
xAxis: {
type: 'datetime',
tickPixelInterval: 150
},
yAxis: {
title: {
text: 'Value'
},
plotLines: [{
value: 0,
width: 1,
color: '#808080'
}]
},
tooltip: {
formatter: function() {
return '<b>'+ this.series.name +'</b><br/>'+
Highcharts.dateFormat('%Y-%m-%d %H:%M:%S', this.x) +'<br/>'+
Highcharts.numberFormat(this.y, 2);
}
},
legend: {
enabled: false
},
exporting: {
enabled: false
},
series: [{
threshold: 0.5,
color: '#FF0000',
negativeColor: '#00FF00',
name: 'Random data',
data: (function() {
// generate an array of random data
var data = [],
time = (new Date()).getTime(),
i;
for (i = -19; i <= 0; i++) {
data.push({
x: time + i * 1000,
y: Math.random()
});
}
return data;
})()
}]
});
});
});
</script>
</head>
<body>
<div id="container" style="min-width: 400px; height: 400px; margin: 0 auto"></div>
</body>
</html>
Indeed it looks like a bug, reported here. At this moment you can only disable animations.
When startOnTick and/or endOnTick are set to true for a datetime xAxis, dragging the navigator left and right expands it until it fills up the whole range of data.
See:
http://jsfiddle.net/L3t4s/2/
Duplicate code below:
<div id="container" style="height: 400px; min-width: 600px"></div>
<script src="http://code.highcharts.com/stock/highstock.js"></script>
<script src="http://code.highcharts.com/stock/modules/exporting.js"></script>
<script type="text/javascript" src="http://www.highcharts.com/samples/data/usdeur.js"></script>
$(function() {
$('#container').highcharts('StockChart', {
chart: {
plotBorderWidth: 1
},
rangeSelector: {
selected: 4
},
xAxis: {
startOnTick: true,
endOnTick: true
},
series: [{
name: 'USD to EUR',
data: usdeur
}]
});
});
It's caused by real time redraws while dragging navigator. To prevent this set liveRedraw: false, see: http://jsfiddle.net/L3t4s/4/