Dymanically Update Data in Highchart, Load Event is not Working - highcharts
there's no data in load Event ( chart.series[0].data )
error code : Uncaught TypeError: Cannot read property 'open' of undefined
then put enabled:false like this..
ex)
dataGrouping: {
enabled: false
units: groupingUnits
},
it works, but too slow..
what should i do?
Here's my code:
$(document).ready(function(){
var area = {
chart:{
height:500,
marginRight:30,
backgroundColor:'#F4F4F4',
events: {
load: function() {
var chart = $('#container').highcharts();
var point = chart.series[0].data[chart.series[0].data.length -1];
text = chart.renderer.text(
'',
point.plotX + chart.plotLeft + 10,
point.plotY + chart.plotTop - 10
).attr({
zIndex: 5
}).add(),
box = text.getBBox();
chart.renderer.rect(box.x - 5, box.y - 5, box.width + 10, box.height + 10, 5)
.attr({
fill: '#FFFFEF',
stroke: 'gray',
'stroke-width': 1,
zIndex: 4
})
//.add();
series1 = this.series[0];
series2 = this.series[1];
//dataMax
var price = series1.data[series1.data.length -1].open;
refreshIntervalId = setInterval(function () {
var x = series1.data[series1.data.length -1].x; // current time
var time = (new Date).getTime();
var o = series1.data[series1.data.length -1].open;
var h = series1.data[series1.data.length -1].high;
var l = series1.data[series1.data.length -1].low;
if(time % 2 === 0){
price = o + Math.random() * 3;
}
else {
price = o - Math.random() * 3;
}
if(price > series1.data[series1.data.length -1].high){
h = price;
}
if(price < series1.data[series1.data.length -1].low){
l = price;
}
var c = price;
var y = series2.data[series2.data.length -1].y + Math.round(Math.random() * 1);
series1.data[series1.data.length -1].update({x : x, open : o, high: h, low: l, close: c}, true);
series2.data[series2.data.length -1].update({x : x, y: y}, false);
}, 1000);
}
}
},
credits: {
enabled:true,
position: { align: 'right', x: -10, verticalAlign: 'bottom', y: -5 },
style: { cursor: 'pointer', color: 'black', fontSize: '9px' }
},
scrollbar: {
enabled: false
},
rangeSelector: {
selected: 1,
inputEnabled: false
},
title: {
useHTML: true,
x: -10,
y: 8,
},
xAxis: {
gridLineWidth: 1,
labels: {
format: '{value:%m-%d}',//'{value:%Y-%m-%d}',
}
},
yAxis:[{
crosshair: {
snap: false
},
height: 200,
labels: {
align: 'right',
x: 25,
formatter: function (){
return $.number(Highcharts.numberFormat(this.value, 0,'',''));
}
},
},
/*volume*/
{
labels: {
align: 'right',
x: 20,
},
// lineWidth: 2
top: 280,
height: 113,
offset: 0,
}],
series: [{
type: 'candlestick',
name: 'AAPL Stock Price',
data: data,
dataGrouping: {
units: groupingUnits
},
point:{
events:{
mouseOver: function (){
var chart = this.series.chart;
if (!chart.lbl){
chart.lbl = chart.renderer.label('')
.attr({
padding: 10,
r: 10,
//fill: Highcharts.getOptions().colors[1]
})
.css({color: 'black'})
.add();
}//if OFF
var timeStamp = this.x,
date = new Date(parseFloat(timeStamp)),
currentTime = get_Date(date);
chart.lbl
.show()
.attr({
text: currentTime + ' H: ' + $.number(this.high) + ' L: ' + $.number(this.low) + ' O: ' + $.number(this.open) + ' C: ' + $.number(this.close),
y: 22,
});
},//mouseover OFF
mouseOut: function (){
if (this.series.chart.lbl){
this.series.chart.lbl.hide();
}//if OFF
}//mouseout OFF
},//events OFF
},//point OFF
}, //series[0] OFF
{
type: 'column',
name: 'Volume',
data: volume,
yAxis: 1,
dataGrouping: {
units: groupingUnits
},
}]//series[1] OFF
}
var dataLength = data.length,
i = 0;
groupingUnits = [[
'week', // unit name
[1] // allowed multiples
], [
'month',
[1, 2, 3, 4, 6]
]];
for (i; i < dataLength; i += 1) {
candlestickOhlc.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
]);
}//for OFF
option = candlestick;
option.series[0].data = data;
$('#container').highcharts('StockChart', option);
});
Related
Strange behaviour on highcharts with two Y Axis
Im doing a chart with 2 series. One of the series is 'scatter' type and the other is 'column' type. The problem i have, is that when i only have the scatter series, datetime labels on x axis, starts on the extreme left, but when i add the column series, is like all labels are pushed to the center, and i dont know why. This is my fiddle examen: https://jsfiddle.net/cswpgq8u/7/ Highcharts.chart('container', { chart: { }, xAxis: { type: 'datetime', min: 1633057200000, max: 1634353200000, tickPositioner: function () { var ticklist = []; var extremes = this.getExtremes(); var startDate = extremes.min;//this.min; var endDate = extremes.max; // this.max; var diff = moment.duration(endDate - startDate); if (diff.days() * 1 > 10) increment = moment.duration(2, 'days').asMilliseconds(); else increment = Math.ceil((endDate - startDate) / 10); for (var timeline = startDate; moment(timeline) <= moment(endDate); timeline += increment) { ticklist.push(timeline); } return ticklist; }, maxPadding: 0, minPadding: 0, crosshair: { enabled: true, events: { } }, plotLines: [{ value: 1634266800000, color: 'green', width: 1, dashStyle: 'ShortDash', label: { text: "AHORA", // Content of the label. verticalAlign: 'bottom', rotate: -90, textAlign: 'right', x: -2, y: 30, style: { color: '#6d6d6d', fontSize: '8px', fontWeight: 'bold', backgroundColor: 'white' } }, }], plotBands: null, labels: { formatter: function () { var xMin = this.axis.min; var xMax = this.axis.max; var labeltick = Highcharts.dateFormat('%d. %B', this.value); if ((moment(xMax).diff(moment(xMin), 'days')) < 10) { labeltick = Highcharts.dateFormat('%d. %B %H:%M:%S', this.value); } return labeltick; }, x: -10 } }, yAxis:[ { plotLines: [{ id: 'ln-' + 'idEje1', color: '#9FA0A2', width: 0, value: 0, dashStyle: 'longdashdot' }], labels: { enabled:true, x: -5, y: -3, }, title: { enabled: false, }, lineColor: 'lightgray', lineWidth: 0, tickInterval: 1 }, { title: { enabled: false, }, lineColor: 'lightgray', opposite: true, labels: { enabled: false, x: -15, y: -3, }, lineWidth: 0, tickInterval: 1 } ], plotOptions: { }, series: [ { yAxis: 0, type: 'scatter', minPointLength: 1, allowPointSelect: false, stack: true, data: [{ x: 1634007600000, y: 2, value: 2, marker: { symbol: 'circle', radius: 3, fillColor: 'red', }, type: "ttf" }, { x: 1633748400000, y: 5, value: 2, marker: { symbol: 'circle', radius: 3, fillColor: 'red', }, type: "ttf" }, { x: 1633143600000, y: 2, value: 2, marker: { symbol: 'circle', radius: 3, fillColor: 'red', }, type: "ttf" }, { x: 1633402800000, y: 2, value: 2, marker: { symbol: 'circle', radius: 3, fillColor: 'red', }, type: "ttf" }], name: 'On YAxis 0', tooltip: { pointFormatter: function () { var point = this; return "Valor TTF:" + ' <b>' + point.y + ' Días</b><br/>'; }, } }, { yAxis: 1, type: 'column', allowPointSelect: false, minPointLength: 1, data: [{ x: 1633708800000, y: 5, type: "duracion", value: 5 }, { x: 1633881600000, y: 3, type: "duracion", value: 3 }], name: 'On YAxis1', tooltip: { pointFormatter: function () { var point = this; return "Duración:" + ' <b>' + point.y + ' minutos</b><br/>'; }, }, pointWidth: 1 } ] }); With 2 series With one series I think this is happening because Column Series. But dont know how to solve it.
The additional space is caused by the default calculation of pointRange for column series. You need to define it by yourself: series: [{ type: 'scatter', ... }, { type: 'column', pointRange: 1, ... } ] Live demo: https://jsfiddle.net/BlackLabel/hsrxtjaw/ API Reference: https://api.highcharts.com/highcharts/series.column.pointRange
Select which chart data category to show versus omit
In the following webpage, https://betterbuildingssolutioncenter.energy.gov/energy-data/District%20of%20Columbia , the highchart next to "Portfolio Energy Performance", clicking on the legend icon "Public" omits the public data and only shows the private data. How can I reverse this, so that clicking on the "Public" legend icon omits the private data instead? I have attached the code used for this webpage. // color declarations var colorGreen = '#0b6a39', colorBlue = '#0c4489', colorBlueLight = '#558ed5', colorGray = '#595959', font = 'avenir'; // graph data variables // Portfolio Energy Performance var /* title */ energyPerformanceTitle = 'Average Annual % Improvement by Reporting Period', /* columns */ energyPerformanceCategories = ['2012', '2013', '2014', '2015', '2016', '2017', '2018', '2019'], /* Y max */ energyPerformanceYMax = 9, /* X title */ energyPerformanceXaxis = [''], /* Y title */ energyPerformanceYaxis = ['Average Annual % Improvement'], /* column colors */ energyPerformanceColumns = [colorBlue, colorBlue, colorBlue, colorBlue, colorBlue, colorBlue, colorBlue, colorBlue], /* column data */ energyPerformanceData = [8.53, 3.31, 2.37, 2.91, 2.86, 2.63, 2.4, 0.34], /* goal data */ energyPerformanceGoalData = 2; // Energy Performance by Facility var /* title */ energyFacilityTitle = 'Number of Properties by Cumulative % Improvement', /* columns */ energyFacilityCategories = ['<=0%', '0-2%', '2-6%', '6-10%', '10-15%', '>15%'], /* X title */ energyFacilityXaxis = ['Cumulative % Improvement Category'], /* Y title */ energyFacilityYaxis = ['Number of Properties'], /* Y interval */ energyFacilityYinterval = 10, /* column colors */ energyFacilityColumns = [colorBlue, colorGreen, colorGreen, colorGreen, colorGreen, colorGreen, colorGreen], /* column data */ energyFacilityData = [82, 14, 28, 16, 35, 101]; // Identifying Opportunities for Improvement var /* title */ improvementOpportunityTitle = '% Improvement vs. Baseline EUI', /* columns */ improvementOpportunityCategories = ['0', '200', '400', '600', '800'], /* X min */ improvementOpportunityXMin = 0, /* X max */ improvementOpportunityXMax = 800, /* Y min */ improvementOpportunityYMin = -60, /* Y max */ improvementOpportunityYMax = 100, /* Y interval */ improvementOpportunityYinterval = 20, /* X interval */ improvementOpportunityXinterval = 200, /* X title */ improvementOpportunityXaxis = ['Baseline Source EUI (kBtu/sq.ft.)'], /* Y title */ improvementOpportunityYaxis = ['% Improvement'], /* scatter data */ improvementOpportunityData = [[704,76], [55,-273], [216,10], [205,6], [505,12], [167,4], [147,-7], [254,-14], [307,19], [275,36], [179,-4], [146,-16], [324,17], [225,19], [146,5], [199,18], [162,4], [183,26], [208,20], [187,-13], [187,19], [145,49], [172,24], [206,25], [208,-35], [222,16], [221,19], [145,18], [151,10], [159,-13], [221,20], [150,26], [215,38], [152,11], [158,-17], [174,9], [249,28], [166,12], [231,3], [165,15], [132,16], [217,3], [163,1], [225,3], [151,20], [149,-9], [164,5], [149,-3], [193,30], [177,10], [246,-20], [155,4], [184,17], [200,7], [132,10], [162,12], [149,19], [252,23], [142,-16], [165,10], [230,-2], [180,16], [193,29], [185,5], [61,49], [226,66], [128,46], [141,76], [190,2], [194,24], [217,10], [127,3], [216,15], [89,-23], [137,-9], [162,33], [171,7], [136,19], [190,-6], [155,18], [93,-35], [147,-20], [199,7], [141,14], [177,7], [276,-16], [103,-2], [172,20], [90,-24], [153,17], [184,10], [149,34], [240,-5], [163,-15], [122,-10], [160,-22], [236,16], [139,5], [183,22], [165,12], [141,22], [114,-39], [175,16], [164,26], [141,16], [186,28], [160,-14], [148,14], [231,15], [204,-9], [170,6], [112,-4], [170,27], [191,17], [216,-1], [215,12], [166,19], [131,-13], [109,15], [181,4], [300,28], [210,13], [236,15], [183,19], [144,14], [198,3], [219,-14], [291,12], [169,19], [194,-8], [208,-16], [304,3], [208,0], [195,-5], [175,17], [143,-1], [161,15], [194,-10], [121,-3], [117,21], [189,0], [136,10], [189,-7], [150,-32], [308,-1], [136,-1], [253,-2], [121,25], [427,2], [222,20], [150,-2], [254,33], [284,38], [307,3], [249,26], [178,6], [134,-22], [282,-4], [151,-10], [143,-3], [116,-6], [158,7], [161,16], [260,55], [131,15], [246,3], [113,-3], [209,22], [322,21], [245,39], [197,14], [142,5], [253,23], [197,-9], [184,15], [169,12], [187,12], [132,-21], [195,16], [143,6], [145,-10], [200,35], [142,5], [178,28], [271,21], [140,-29], [125,6], [148,-15], [185,18], [163,36], [173,13], [117,-2], [291,23], [168,-8], [196,26], [202,13], [169,22], [142,-37], [142,-32], [211,22], [165,5], [181,30], [140,0], [126,-15], [410,14], [167,-17], [205,13], [171,-6], [197,24], [167,15], [115,0], [160,31], [164,13], [176,11], [169,23], [153,25], [542,16], [138,-12], [143,-25], [228,-1], [95,10], [147,-14], [200,8], [195,1], [178,12], [192,20], [152,11], [224,1], [150,-2], [247,12], [208,36], [134,-18], [231,-4], [248,-1], [217,-2], [164,22], [288,0], [201,15], [149,26], [206,33], [179,23], [151,22], [168,14], [165,5], [176,12], [145,-15], [103,-40], [163,5], [141,-9], [128,9], [177,30], [238,17], [182,10], [198,23], [147,-8], [205,29], [528,-8], [205,16], [164,15], [163,39], [193,1], [173,-1], [168,30], [233,6], [117,2], [205,13], [110,7], [161,15], [159,4], [197,2], [131,0], [231,-37], [248,0], [140,0], [155,-9], [153,-2],], /* trendline data */ improvementOpportunityTrendLine = [[55, -5], [704, 54]]; // On document ready, call visualize on the datatable. jQuery(document).ready(function () { Highcharts.visualize = function (table, options) { // the categories options.xAxis.categories = energyPerformanceCategories; options.colors = energyPerformanceColumns, options.series = [{ type: 'column', name: ['Public'], data: energyPerformanceData, color: colorBlue, colorByPoint: false, dataLabels: { enabled: false } }, { type: 'column', name: ['Private'], data: [3.3, 4.95, 3.68, 3.31, 2.76, 2.99, 2.3, 1.71], color: colorBlueLight, colorByPoint: false, dataLabels: { enabled: false }, }]; var chart = new Highcharts.Chart(options); } var table = document.getElementById('datatable'), options = { chart: { renderTo: 'energy-performance', type: 'column' }, title: { text: energyPerformanceTitle, style: { color: colorGray, fontFamily: font } }, subtitle: {}, plotOptions: { series: { shadow: false }, column: { borderWidth: 0 } }, xAxis: { title: { text: energyPerformanceXaxis, style: { color: colorGray, fontFamily: font } }, tickLength: 0, lineColor: colorGray, lineWidth: 1 }, yAxis: { title: { text: 'Average Annual % Improvement', style: { color: colorGray, fontFamily: font } }, tickInterval: 1, tickLength: 5, tickWidth: 1, tickColor: colorGray, max: energyPerformanceYMax, lineColor: colorGray, lineWidth: 1, gridLineWidth: 0, plotLines: [{ color: colorGray, width: 2, value: energyPerformanceGoalData, zIndex: 5, label: { text: 'GOAL', align: 'right', x: 11, y: -5, style: { color: colorGray, fontFamily: font, fontWeight: 'bold' } } }], labels: { style: { color: colorGray, fontFamily: font } } }, legend: { enabled: true }, legend: { itemHiddenStyle: { color: colorBlue, colorByPoint: false } }, credits: { enabled: false }, tooltip: { formatter: function () { var raw = ((this.y / energyPerformanceData[0])) * 100, percentage = Math.round(100 - (raw * 100) / 100); if (this.y === energyPerformanceData[0] && this.key === '2012') { return '<strong>' + this.series.name + '</strong><br/>' + '<strong>' + this.x + '</strong>: ' + Highcharts.numberFormat(this.y, 1) + '%'; } else { return '<strong>' + this.series.name + '</strong><br/>' + '<strong>' + this.x + '</strong>: ' + Highcharts.numberFormat(this.y, 1) + '%'; } }, } }; Highcharts.visualize(table, options); }); // On document ready, call visualize on the datatable. jQuery(document).ready(function () { Highcharts.visualize = function (table, options) { // the categories options.xAxis.categories = energyFacilityCategories; options.colors = energyFacilityColumns, options.series = [{ type: 'column', name: energyFacilityYaxis, data: energyFacilityData, color: colorGreen, colorByPoint: true, dataLabels: { enabled: false } }]; var chart = new Highcharts.Chart(options); } var table = document.getElementById('datatable'), options = { chart: { renderTo: 'facility-performance', type: 'column' }, title: { text: energyFacilityTitle, style: { color: colorGray, fontFamily: font } }, subtitle: {}, plotOptions: { series: { shadow: false }, column: { borderWidth: 0 } }, xAxis: { title: { text: energyFacilityXaxis, style: { color: colorGray, fontFamily: font } }, tickLength: 0, lineColor: colorGray, lineWidth: 1, labels: { rotation: -45, y: 30, style: { color: colorGray, fontFamily: font } } }, yAxis: { title: { text: energyFacilityYaxis, style: { color: colorGray, fontFamily: font } }, tickInterval: energyFacilityYinterval, tickLength: 5, tickWidth: 1, tickColor: colorGray, lineColor: colorGray, lineWidth: 1, gridLineWidth: 0, minorTickColor: colorGray, labels: { style: { color: colorGray, fontFamily: font } } }, legend: { enabled: false }, credits: { enabled: false }, tooltip: { formatter: function () { return '<strong>' + this.series.name + '</strong><br/>' + '<strong>' + this.x + '</strong>: ' + this.y; } } }; Highcharts.visualize(table, options); }); // On document ready, call visualize on the datatable. jQuery(document).ready(function () { Highcharts.visualize = function (table, options) { // the categories options.xAxis.categories = improvementOpportunityCategories; options.series = [{ name: improvementOpportunityYaxis, data: improvementOpportunityData, color: colorBlue }, { type: 'line', name: 'Trendline', data: improvementOpportunityTrendLine, color: colorGray, width: 1, marker: { enabled: false } }]; var chart = new Highcharts.Chart(options); } var table = document.getElementById('datatable'), options = { chart: { renderTo: 'improvement-opportunities', type: 'scatter', zoomType: 'xy' }, title: { text: improvementOpportunityTitle, style: { color: colorGray, fontFamily: font } }, subtitle: {}, plotOptions: { series: { shadow: false }, scatter: { marker: { radius: 3, symbol: 'diamond', states: { hover: { enabled: true } } }, states: { hover: { marker: { enabled: false } } } } }, xAxis: { title: { text: improvementOpportunityXaxis, style: { color: colorGray, fontFamily: font } }, lineWidth: 0, min: improvementOpportunityXMin, max: improvementOpportunityXMax, tickInterval: improvementOpportunityXinterval, minTickInterval: 25, tickLength: 0 }, yAxis: { title: { text: improvementOpportunityYaxis, style: { color: colorGray, fontFamily: font } }, min: improvementOpportunityYMin, max: improvementOpportunityYMax, tickInterval: improvementOpportunityYinterval, tickLength: 5, tickWidth: 1, tickColor: colorGray, lineColor: colorGray, lineWidth: 1, gridLineWidth: 0, plotLines: [{ color: colorGray, width: 1, value: 0 }, { color: colorGray, width: 1, value: 0, zIndex: 5 }] }, legend: { enabled: false }, credits: { enabled: false }, tooltip: { formatter: function () { return '<strong>' + this.series.name + ':</strong> ' + this.y; } } }; Highcharts.visualize(table, options); });
Use legendItemClick event and hide/show other series than the clicked one: plotOptions: { series: { events: { legendItemClick: function() { this.chart.series.forEach(function(s) { if (s !== this) { s.setVisible(); } }, this); return false; } } } } Live demo: http://jsfiddle.net/BlackLabel/j0eyc625/ API Reference: https://api.highcharts.com/class-reference/Highcharts.Series#setVisible
Highchart xaxis data decrease when shift
I am creating a chart and populating a random data every 5 minute. I set the xAxis data range to 5 hour and when start with initial data, it's width is full in chart but when continuously add point, the data width is decreasing. How do I do to make it not decrease the series width? I have the following code: $(function () { var current_time = (new Date()).getTime()+300000; var now_time = (new Date()).getTime(); var zone_name = ['A','B','C']; $(document).ready(function() { Highcharts.setOptions({ global: { useUTC: false } }); $('#container').highcharts({ chart: { type: 'spline', animation: Highcharts.svg, marginRight: 10, events: { load: function() { var chartsss = $('#container').highcharts(); setInterval(function() { for(var i=0;i<zone_name.length;i++) { var seriessx = chartsss.series[i]; seriessx.addPoint([current_time, Math.random()], false, true); seriessx.addPoint([current_time, Math.random()], false, true); } chartsss.redraw(); current_time += 300000; }, 1000); } } }, plotOptions: { series: { marker: { enabled: false } }, spline: { lineWidth: 2, states: { hover: { lineWidth:3 } }, marker: { enabled: false, states: { hover: { enabled: false, symbol: 'circle', fillColor: '#ff0000', radius: 4, lineWidth: 1 } } } }, }, title: { text: 'Daily Zone' }, xAxis: { type: 'datetime', dateTimeLabelFormats: { day: '%e of %b', minute: '%H:%M', hour: '%H:%M' }, tickPosition: 'inside', tickInterval: 3600 * 1000, minRange:5 * 3600 * 1000, maxRange:5 * 3600 * 1000 }, yAxis: { title: { text: 'Value' }, plotLines: [{ value: 0, width: 1, color: '#808080' }] }, tooltip: { formatter: function() { return '<b>'+ this.series.name +'</b><br/>'+ Highcharts.dateFormat('%H:%M', this.x) +'<br/>'+ Highcharts.numberFormat(this.y, 2); } }, legend: { enabled: true }, exporting: { enabled: false }, series: (function(){ var seriesx = []; for(var i=0;i<zone_name.length;i++) { var datax = []; var time = (new Date()).getTime(); now_time=current_time; for(var j = -59 ;j <= 0;j++) { datax.push({ x: now_time, y: Math.random() }); now_time+=300000; } seriesx.push({ name:zone_name[i], data: datax }); } current_time=now_time; return seriesx; })() }); }); }); JsFiddle Link: http://jsfiddle.net/jedipalm/YLFhD/4/ Image when started chart: http://i.stack.imgur.com/rE8m3.jpg Image when continuously add point in few second :http://i.stack.imgur.com/J8GtA.jpg sorry for my bad English.
Why you are adding twice the same point? Highcharts doesn't support two points in one series with the same x-value. Removed one of addPoint() and works fine: http://jsfiddle.net/YLFhD/8/
try following code: for(var j = -120 ;j <= 0;j++) { datax.push({ x: now_time, y: Math.random() }); now_time+=300000; } http://jsfiddle.net/YLFhD/6/
Highcharts : labels inside columnrange bar
I am using the columnrange type from Highcharts-more. The default data labels formatter puts the min / max data at both ends of the range, which is nice. Is there a way to attach another label to each point? (for example : the data name, right in the middle of the bar) Please see my work at: JSFiddle This is a family tree with life ranges. I'd like to display the names shown in tooltips at the center of bars. (FYI I tried to overload the chart with text using the renderer : it worked... but the texts were attached to the chart, not to the points, and zooming left them in place, while the points moved around. Is there maybe a way to attach text labels to the each point on the chart onLoad event?) Thank you. $(function () { $('#container').highcharts({ chart: { type: 'columnrange', inverted: true, marginLeft: 40, zoomType: 'xy' }, title: { text: 'My family tree' }, xAxis: { labels: { enabled: false }, min: 0, max: 10 }, yAxis: { type: 'datetime', min: new Date().setYear(1900).valueOf(), max: new Date().valueOf(), title: { text: 'Year' }, endOnTick: false }, legend: { enabled: false }, plotOptions: { columnrange: { grouping: false, pointPadding: 0, dataLabels: { enabled: true, useHTML: true, formatter: function () { if (new Date().setHours(0, 0, 0, 0) !== new Date(this.y).setHours(0, 0, 0, 0)) return '<span style="color:black">' + Highcharts.dateFormat('%Y', this.y) + '</span>'; else return ''; } } } }, tooltip: { headerFormat: '{series.name}<br/>', formatter: function () { var l = this.point.name + '<br/>' + Highcharts.dateFormat('%e/%m/%Y', this.point.low); if (new Date().setHours(0, 0, 0, 0) !== new Date(this.point.high).setHours(0, 0, 0, 0)) l += '<br/>' + Highcharts.dateFormat('%e/%m/%Y', this.point.high); return l; } }, series: [{ color: 'rgb(100,100,255)', pointWidth: 150, data: [{ name: 'Yann B', low: Date.UTC(1976, 1, 27), high: new Date().valueOf(), x: 1 * 10 / 2 }] }, { color: 'rgb(150,150,255)', pointWidth: 70, data: [{ name: 'Jean-Yves B', low: Date.UTC(1947, 3, 26), high: Date.UTC(2006, 2, 10), x: 1 * 10 / 4 }, { name: 'Josiane M', low: Date.UTC(1946, 8, 21), high: Date.UTC(1998, 11, 26), x: 3 * 10 / 4 }] }, { color: 'rgb(200,200,255)', pointWidth: 30, data: [{ name: 'Guillaume B', low: Date.UTC(1907, 7, 4), high: Date.UTC(1988, 1, 11), x: 1 * 10 / 8 }, { name: 'Marie-Jeanne S', low: Date.UTC(1911, 7, 17), high: Date.UTC(1986, 2, 3), x: 3 * 10 / 8 }, { name: 'Joseph M', low: Date.UTC(1921, 3, 11), high: Date.UTC(1996, 4, 23), x: 5 * 10 / 8 }, { name: 'Marie K', low: Date.UTC(1925, 4, 4), high: new Date().valueOf(), x: 7 * 10 / 8 }] }] }); });
The use of the "inside" propriety is indeed relevant here. But I had to bypass the bug inherent to its use (see comment to last answer). Here is a piece of code that works for datalabels. There still is a zIndex issue with the tool tips, and I'll try to post a more complete solution soon. http://jsfiddle.net/SineDie/TREwr/1/ dataLabels: { inside: true, enabled: true, useHTML: true, formatter: function () { if (this.y === this.point.low) { var l = '<div style="text-align:center;color:black;width:' + (this.point.plotLow - this.point.plotHigh) + 'px">' + Highcharts.dateFormat('%Y', this.point.low) + ' - ' + this.point.name; // to avoid marking as dead if still living... if (new Date().setHours(0, 0, 0, 0) !== new Date(this.point.high).setHours(0, 0, 0, 0)) l += ' - ' + Highcharts.dateFormat('%Y', this.point.high); l += '</div>'; return l; } else return ''; } }
I did some modifications on formatter funcution. set datalabels inside property true and attach datanames to point's high values. dataLabels: { inside:true, enabled: true, useHTML: true, formatter: function () { if (new Date().setHours(0, 0, 0, 0) !== new Date(this.y).setHours(0, 0, 0, 0)) { if (this.y == this.point.high){ return '<span style="color:black">' + Highcharts.dateFormat('%Y', this.y) +' - '+ this.point.name + '</span>'; } return '<span style="color:black">' + Highcharts.dateFormat('%Y', this.y) + '</span>'; } else return ''; } }
Highstocks Line Chart: Using fixed tooltips on top of point markers
I am using Area chart with navigator, what I am trying to do is highlight high and Low point markers (only two points ) in the current visible chart, and on top of these markers I want to display fixed tooltips displaying the point information. And as user navigates through navigator these point markers should be recalculated and tooltips should follow them. [This is what I am trying to accomplish][1] So far I have been able to calculate high and low points and highlight corrosponding markers in chart, and I have also been able to display two tooltips, but they are not ACURATELY positioned along with point markers. ![So far this has been accomplished][2] Here is my Code: function customTooltip(point) { console.log(chart); var text = chart.renderer.text( 'Max', point.plotX + chart.plotLeft + 10, point.plotY + chart.plotTop - 10 ).attr({ zIndex: 5 }).add(); var box = text.getBBox(); chart.renderer.rect(box.x - 5, box.y - 5, box.width + 10, box.height + 10, 5) .attr({ fill: '#FFFFEF', stroke: 'gray', 'stroke-width': 1, zIndex: 4 }) .add(); } var labelArr = [], // keeps Tooltips for High and Low chart = $('#container').highcharts('StockChart', { chart: { type: 'line', width: 900 }, scrollbar: { enabled: false }, navigator: { top: -1, height: 25, handles: { backgroundColor: 'transparent', borderColor: 'transparent' } }, rangeSelector: { inputPosition: { align: 'left', x: 10, y: 30 }, buttons: [{ type: 'year', count: 1, text: '' }], buttonTheme: { // styles for the buttons fill: 'none', stroke: 'none', 'stroke-width': 0, states: { hover: { fill: 'none' }, select: { fill: 'none' } } }, inputDateFormat: '%m-%d-%Y', inputStyle: { fontSize: '14px', borderColor: '#FFF' }, selected: 0 }, yAxis: { labels: { align: 'right', x: -5, formatter: function () { return "$" + this.value; } } }, xAxis: { type: 'datetime', tickWidth: 0, labels: { y: 20 }, dateTimeLabelFormats: { month: '%B' }, events: { setExtremes: function () { var pointMax, pointMin, labelLength = labelArr.length; // Flush out Old Tooltips for High and Low if (labelLength > 0) { for (var i = 0; i < labelLength; i++) { var popVal = labelArr.pop(); this.chart.container.firstChild.removeChild(popVal); } } $.each(this.series[0].points, function (i, point) { if (!pointMax && !pointMin) pointMax = pointMin = point; // If marker is enabled for any point, disable it if (typeof point.marker != 'undefined') point.marker.enabled = false; // Calculate Highest point if (pointMax.y < point.y) pointMax = point; // Calculate Lowest point if (pointMin.y > point.y) pointMin = point; }); pointMax.update({ marker: { enabled: true } }, false, false); //customTooltip( pointMax ); pointMin.update({ marker: { enabled: true } }, false, false); //customTooltip( pointMin ); } } }, tooltip: { crosshairs: false /*useHTML: true, borderRadius: 0, backgroundColor: '#000', shadow: false, borderWidth: 0, enabled: true, formatter: function(){ /* Temp Disable Custom tool-Tip var arr = []; $.each(this.points, function(k, obj){ arr.push( "<span style='color:#FFF'>Low price w/o sales charge</span>" ); arr.push( "<br>" ); arr.push( "<span style='font-weight:bold;color:#FFF'>$" + obj.y + "</span>" ); arr.push( "<br>" ); }); return arr.join(' '); } */ }, plotOptions: { area: { marker: { fillColor: '#f7941e', states: { hover: { enabled: false } } } }, series: { point: { events: { update: function (event) { event.target.series.chart.tooltip.refresh([event.target]); var cloneToolTip = event.target.series.chart.tooltip.label.element.cloneNode(true); event.target.series.chart.container.firstChild.appendChild(cloneToolTip); labelArr.push(cloneToolTip); } } } } }, series: [{ name: 'Quarterly Returns w/o sales charge', data: [ [1149120000000, 62.17], [1149206400000, 61.66], [1369699200000, 441.44], [1369785600000, 444.95] ] // pointWidth: 14, }] }).highcharts(); }); Can you please guide me on how to proceed from here?