Related
I want to display my exact tooltips display ( 'LabelName:y.axis' (with legend color)) , into another div (most probably above the chart). And it should be per panehovering (currently having 3 panes). Is this possible?..
Highcharts.getJSON('https://demo-live-data.highcharts.com/aapl-ohlcv.json',
function(data) {
// split the data set into ohlc and volume
var ohlc = [],
volume = [],
volume2 = [],
dataLength = data.length,
// set the allowed units for data grouping
groupingUnits = [
[
'week', // unit name
[1] // allowed multiples
],
[
'month',
[1, 2, 3, 4, 6]
]
],
i = 0;
for (i; i < dataLength; i += 1) {
ohlc.push([
data[i][0], // the date
data[i][1], // open
data[i][2], // high
data[i][3], // low
data[i][4] // close
]);
volume.push([
data[i][0], // the date
data[i][5] // the volume
]);
volume2.push([
data[i][0], // the date
data[i][5] // the volume
]);
}
// create the chart
Highcharts.stockChart('container', {
title: {
text: 'AAPL Historical'
},
yAxis: [{
labels: {
align: 'right',
x: -3
},
title: {
text: 'OHLC'
},
height: '33%',
lineWidth: 2,
id: '0',
}, {
labels: {
align: 'right',
x: -3
},
title: {
text: 'Volume'
},
top: '33%',
height: '33%',
offset: 0,
lineWidth: 2,
id: '1',
}, {
labels: {
align: 'right',
x: -3
},
title: {
text: 'Volume 123'
},
top: '66%',
height: '33%',
offset: 0,
lineWidth: 2,
id: '2'
},{
opposite:false,
labels: {
align: 'right',
x: -3
},
title: {
text: 'second AAPL'
},
height: '33%',
offset: 0,
lineWidth: 2,
id: '3'
}],
xAxis: [{
offset: -4,
lineWidth: 2
}],
legend: {
enabled: true
},
tooltip: {
split: true
},
series: [{
type: 'candlestick',
name: 'AAPL',
data: ohlc,
yAxis: 0
}, {
type: 'column',
name: 'Volume',
data: volume,
yAxis: 1,
}, {
type: 'column',
name: 'Volume123',
data: volume,
yAxis: 2,
}, {
type: 'spline',
name: 'second AAPL',
data: ohlc,
yAxis: 3,
}]
});
});
This is my working demo fiddle . This is how my code look like.I want to make the tooltip data to be displayed in other div,so far I have tried, only one data series getting called..
Visual Representation of desired tooltips
I really appreciate any help
Use the below options to position a tooltip in the div above the chart:
tooltip: {
...,
shared: true,
split: false,
shape: 'rect',
outside: true,
positioner: function() {
return {
x: 0,
y: 0
}
}
}
Live demo: https://jsfiddle.net/BlackLabel/akwgf7hm/
API Reference: https://api.highcharts.com/highcharts/tooltip.positioner
Still not finding a solution, I am compelled to post here.
I have a candlestick chart and volume chart from “Highcharts”. Both should be in the same axis. When I resize, both should resize as one. See the image below.
Currently, Highchart supports it as two panes, which is of no use for me. Any help would be highly appreciated.
Resizing is for axes and series could be assigned to any axis, so if you will have multiple series in the same yAxis then resizing will work for all series in that yAxis.
Default demo data for volume is about 1 000 000 greater than OHLC data, so I have adjusted that in the below demo: https://jsfiddle.net/BlackLabel/oegqudbz/
Highcharts.getJSON('https://www.highcharts.com/samples/data/aapl-ohlcv.json', function (data) {
// split the data set into ohlc and volume
var ohlc = [],
volume = [],
dataLength = data.length,
// set the allowed units for data grouping
groupingUnits = [[
'week', // unit name
[1] // allowed multiples
], [
'month',
[1, 2, 3, 4, 6]
]],
i = 0;
for (i; i < dataLength; i += 1) {
ohlc.push([
data[i][0], // the date
data[i][1], // open
data[i][2], // high
data[i][3], // low
data[i][4] // close
]);
volume.push([
data[i][0], // the date
data[i][5] / 1e6 // the volume in milions
]);
}
// create the chart
Highcharts.stockChart('container', {
rangeSelector: {
selected: 1
},
title: {
text: 'AAPL Historical'
},
yAxis: [{
labels: {
align: 'right',
x: -3
},
title: {
text: 'OHLC'
},
height: '60%',
lineWidth: 2,
resize: {
enabled: true
}
}, {
labels: {
align: 'right',
x: -3
},
title: {
text: 'Volume'
},
top: '65%',
height: '35%',
offset: 0,
lineWidth: 2
}],
tooltip: {
split: true
},
series: [{
type: 'candlestick',
name: 'AAPL',
data: ohlc,
dataGrouping: {
units: groupingUnits
}
}, {
type: 'column',
name: 'Volume',
data: volume,
dataGrouping: {
units: groupingUnits
}
}]
});
});
<script src="https://code.highcharts.com/stock/highstock.js"></script>
<script src="https://code.highcharts.com/stock/modules/data.js"></script>
<script src="https://code.highcharts.com/stock/modules/drag-panes.js"></script>
<script src="https://code.highcharts.com/stock/modules/exporting.js"></script>
<div id="container" style="height: 600px; min-width: 310px"></div>
There is no limit for how many panes (or yAxes) are possible to change through the draggable-pane module, so you could have more than 2 axes and more than 2 resizers and more than just 2 axes assigned to one resizer. More info in the API reference:
https://api.highcharts.com/highstock/yAxis.resize
I want create a bar line graphs with navigator,range selector, y axis from both side and graph sector. I implement it using Highcharts.Chart() but it's x-axis not comes properly. when i create x-axis properly after change categories to ["2017-2-3'] then range selector goes to 1970 (default value) so i convert date to milliseconds. Now in the x-axis have unwanted values. I want to show only x-axis values which shows in category array. currently 1m,3m,6m not worked i think it happen because of this x-axis issue.
jsfiddle : http://jsfiddle.net/m05sgk3j/1/
$(document).ready(function() {
var categories = [1551420000000,1549000800000,1546322400000,1543644000000,1541052000000, 1538373600000, 1535781600000,1533103200000, 1530424800000, 1527832800000, 1525154400000, 1522562400000, 1519884000000, 1517464800000,1514786400000];
new Highcharts.Chart({
chart: {
renderTo: 'container'
},
title: {
text: 'In March 2019, the average CT_HOURS is 10.55 hours.'
},
rangeSelector: {
enabled: true,
buttons: [{
type: 'millisecond',
count: 1,
text: '1m'
}, {
type: 'millisecond',
count: 3,
text: '3m'
}, {
type: 'millisecond',
count: 6,
text: '6m'
}, {
type: 'all',
text: 'All'
}],
selected: 4,
inputDateFormat: '%Y-%m-%d',
inputEditDateFormat: '%Y-%m-%d'
},
navigator: {
enabled: true,
xAxis: {
tickInterval: 15,
labels: {
/* formatter: function() {
return categories[this.pos]
} */
}
}
},
scrollbar: {
enabled: true
},
xAxis: {
// categories: categories,
type: 'datetime',
tickInterval : 2,
// tickInterval: {_tickInterval},
/* labels: {
step:10
}, */
/* maxZoom: 30 * 24 * 3600000, */
dateTimeLabelFormats : {
day: '%Y-%m'
}
// crosshair: true,
// minRange: 1
},
yAxis: [{ // Primary yAxis
labels: {
format: '{value}h',
style: {
color: Highcharts.getOptions().colors[1]
}
},
title: {
text: 'AVERAGE CT_HOURS',
style: {
color: Highcharts.getOptions().colors[1]
}
}
}, { // Secondary yAxis
title: {
text: 'REQUEST COUNT',
style: {
color: Highcharts.getOptions().colors[0]
}
},
labels: {
format: '{value}',
style: {
color: Highcharts.getOptions().colors[0]
}
},
opposite: true
}],
series: [{
name: 'REQUEST COUNT',
type: 'column',
yAxis: 1,
data: [
[1551420000000, 49.9],
[1549000800000, 71.5],
[1546322400000, 106.4],
[1543644000000, 129.2],
[1541052000000, 144.0],
[1538373600000, 176.0],
[1535781600000, 135.6],
[1533103200000, 148.5],
[1530424800000, 49.9],
[1527832800000, 71.5],
[1525154400000, 106.4],
[1522562400000, 129.2],
[1519884000000, 144.0],
[1517464800000, 176.0],
[1514786400000, 135.6]
],
tooltip: {
valueSuffix: ''
}
}, {
name: 'AVERAGE CT_HOURS',
type: 'spline',
data: [[1551420000000, 56.6],
[1549000800000, 46.3],
[1546322400000, 32.8],
[1543644000000, 43.4],
[1541052000000, 40.8],
[1538373600000, 43.0],
[1535781600000, 43.1],
[1533103200000, 44.6],
[1530424800000, 45.7],
[1527832800000, 27.8],
[1525154400000, 39.9],
[1522562400000, 29.3],
[1519884000000, 27.9],
[1517464800000, 27.4],
[1514786400000, 17.6]],
tooltip: {
valueSuffix: 'h'
}
}]
});
});
Just comment the tickInterval for the xAxis
//tickInterval : 2,
Fiddle
First of all, you have unsorted data. If you want to invert your data, use reversed option.
Also, the rangeSelector and the tickInterval are wrong. If you use datetime axis, then the basic unit is one millisecond.
However, to show dates only from the categories array, use the tickPositions option and formatter function for labels:
xAxis: {
reversed: true,
minRange: 1,
type: 'datetime',
tickPositions: categories,
labels: {
formatter: function() {
return Highcharts.dateFormat('%Y-%m', this.value);
}
}
},
Live demo: http://jsfiddle.net/BlackLabel/a6Lphq4k/
API Reference:
https://api.highcharts.com/highcharts/xAxis.reversed
https://api.highcharts.com/highcharts/xAxis.tickPositions
https://api.highcharts.com/highcharts/xAxis.labels.formatter
(1) First always make sure that you are injecting timestamps in your categories, and formatting them in :
(1-1) xAxis.labels.formatter function [for x axis labels]
(1-2) navigator.xAxis.labels.formatter function [for navigation labels format)
(2) Second make sure that you are clearing your (xAxis.categories) if you push data into it. because highcharts don't sort your array. if you just assign new array that's ok.
(3) Note : Based on values on your categories array, navigation gets some values like xAxis min and xAxis Max. when you change your data these values remain and that's why your navigation collapses. so when changing data make sure to update. you can use 0 for minimum of navigator and categories.length for maximum value of navigator.
you can access updated values also in dataMin and dataMax.
Hope this answer help you.
I looked around a bit but can't seem to find the exact answer for this.
I'm currently adding some data to highcharts. Essentially, I am using the HighStock column and candlestick chart, and it should suffice for my testing.
The issue is this. I've set up ONE of the two series' to have IDs. I would now like to retrieve an individual point object by calling [something].get("point_0"), which seems like it should be possible but doesn't seem to work. Here is the fiddle for it:
http://jsfiddle.net/mr3ezgh9/
and here is the code:
var chart = null;
$(function () {
$.getJSON('http://www.highcharts.com/samples/data/jsonp.php?filename=aapl-ohlcv.json&callback=?', function (data) {
// split the data set into ohlc and volume
var ohlc = [],
volume = [],
dataLength = data.length,
// set the allowed units for data grouping
groupingUnits = [[
'week', // unit name
[1] // allowed multiples
], [
'month',
[1, 2, 3, 4, 6]
]],
i = 0;
for (i; i < dataLength; i += 1) {
ohlc.push([
data[i][0], // the date
data[i][1], // open
data[i][2], // high
data[i][3], // low
data[i][4] // close
]);
volume.push(
{
name: data[i][0],
x: data[i][0], // the date
y: data[i][5], // the volume
color: "red",
id: "point_" + i
}
);
}
// create the chart
$('#container').highcharts('StockChart', {
rangeSelector: {
selected: 1
},
title: {
text: 'AAPL Historical'
},
yAxis: [{
labels: {
align: 'right',
x: -3
},
title: {
text: 'OHLC'
},
height: '60%',
lineWidth: 2
}, {
labels: {
align: 'right',
x: -3
},
title: {
text: 'Volume'
},
top: '65%',
height: '35%',
offset: 0,
lineWidth: 2
}],
series: [{
type: 'candlestick',
name: 'AAPL',
data: ohlc,
dataGrouping: {
units: groupingUnits
}
}, {
type: 'column',
name: 'Volume',
data: volume,
yAxis: 1,
turboThreshold: Number.MAX_VALUE,
dataGrouping: {
units: groupingUnits
}
}]
});
alert(Highcharts.charts[0].get("point_0"));
});
});
I have tried a few variations on .get("point_0") like getting a series first (but the series doesn't have a get function), setting the chart to a variable and then getting it, and other similar changes, but nothing quite seems to work. Any insight on this?
The general problem is that in the highstock you have enabled datagrouping, so points are groupped and ids are skipped. Disable it and option will work.
plotOptions: {
series: {
dataGrouping: {
enabled: false
}
}
}
Example: http://jsfiddle.net/mr3ezgh9/1/
I've got a simple chart showing candlesticks with volume columns underneath: http://jsfiddle.net/T83Xy/
Basically, I want to use black and red for the columns depending on whether it closes higher than the open or not. I've seen some samples by pushing Y: data, color: '#000000' as the parameter. The problem is I'm pushing a date and a volume number. I attempted to push X: date, Y: data, color: '#000000' but it's throwing errors and not giving me the expected result.
At first, you need to set series.turboThreshold to 0 if you have a big amount of points. This will disable the input data format check.
Then, to apply column colors depending on candles, I suggest you this piece of code:
Highcharts.seriesTypes.column.prototype.pointAttribs = (function(func) {
return function(point, state) {
var attribs = func.apply(this, arguments);
var candleSeries = this.chart.series[0]; // Probably you'll need to change the index
var candlePoint = candleSeries.points.filter(function(p) { return p.index == point.index; })[0];
var color = (candlePoint.open < candlePoint.close) ? '#FF0000' : '#000000'; // Replace with your colors
attribs.fill = state == 'hover' ? Highcharts.Color(color).brighten(0.3).get() : color;
return attribs;
};
}(Highcharts.seriesTypes.column.prototype.pointAttribs));
Be careful as this code will affect ALL of your charts that currently on page. But you can easily add some conditions to run this only on specific chart. Here is a default Highstock demo with the code above.
This worked perfectly for me:
$(function () {
jQuery.getJSON('https://www.highcharts.com/samples/data/jsonp.php?filename=aapl-ohlcv.json&callback=?', function (data) {
// split the data set into ohlc and volume
var volumeColor = '';
var ohlc = [],
volume = [],
dataLength = data.length,
// set the allowed units for data grouping
groupingUnits = [[
'week', // unit name
[1] // allowed multiples
], [
'month',
[1, 2, 3, 4, 6]
]],
i = 0;
for (i; i < dataLength; i += 1) {
ohlc.push([
data[i][0], // the date
data[i][1], // open
data[i][2], // high
data[i][3], // low
data[i][4] // close
]);
if (i==0) {
volumeColor = '#CCCCCC';
} else {
if (data[i][1] >= data[i-1][1]) {
volumeColor = '#006633';
} else {
volumeColor = '#CC0033';
}
}
volume.push({
x: data[i][0], // the date
y: data[i][5],
color: volumeColor
});
}
// create the chart
$('#container').highcharts('StockChart', {
rangeSelector: {
selected: 1
},
title: {
text: 'AAPL Historical'
},
yAxis: [{
labels: {
align: 'right',
x: -3
},
title: {
text: 'OHLC'
},
height: '60%',
lineWidth: 2
}, {
labels: {
align: 'right',
x: -3
},
title: {
text: 'Volume'
},
top: '65%',
height: '35%',
offset: 0,
lineWidth: 2
}],
series: [{
type: 'candlestick',
name: 'AAPL',
data: ohlc,
dataGrouping: {
units: groupingUnits
}
}, {
type: 'column',
name: 'Volume',
data: volume,
yAxis: 1,
turboThreshold: Number.MAX_VALUE,
dataGrouping: {
enabled: false,
units: groupingUnits
}
}]
});
});
});
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<script src="https://code.highcharts.com/stock/highstock.js"></script>
<script src="https://code.highcharts.com/stock/modules/exporting.js"></script>
<div id="container" style="height:400px;min-width:310px"></div>
The current (HighCharts 7+) solution for this, which doesn't require overriding any methods, is to simply set the color attribute for the volume point according to the comparison between the current candlestick point's open and its close: green if <, red if >, and yellow if equal.
Here is a minimal example.
// Return a color matching the candle by comparing the open (1) and close (4)
function volumeBarColor(point) {
if (point[1] < point[4])
return 'green';
if (point[1] > point[4])
return 'red';
return 'yellow';
}
Highcharts.getJSON('https://www.highcharts.com/samples/data/aapl-ohlcv.json', data => {
// Split the data set into ohlc and volume
const ohlc = [],
volume = [];
for (let i = 0; i < data.length; i += 1) {
ohlc.push([
data[i][0], // the date
data[i][1], // open
data[i][2], // high
data[i][3], // low
data[i][4], // close
]);
volume.push({
x: data[i][0], // the date
y: data[i][5], // the volume
color: volumeBarColor(data[i]),
});
}
// Create the chart
Highcharts.stockChart('container', {
title: {
text: 'AAPL Historical'
},
yAxis: [{
labels: {
align: 'right',
x: -3
},
height: '60%',
}, {
labels: {
align: 'right',
x: -3
},
top: '65%',
height: '35%',
offset: 0,
}],
series: [{
type: 'candlestick',
name: 'AAPL',
data: ohlc,
}, {
type: 'column',
name: 'Volume',
data: volume,
yAxis: 1,
}]
});
});
<script src="https://code.highcharts.com/stock/highstock.js"></script>
<script src="https://code.highcharts.com/stock/modules/data.js"></script>
<div id="container"></div>