I have this multiple series line highchart which has a fixed tooltip and a crosshair. As the crosshair moves along the x-axis, the y-axis points are perfectly rendered in the fixed tooltip. However, one additional feature that I would like to add is that after adding a vertical plotline (chart.xAxis[0].addPlotLine
) I also want to display the corresponding y-axis points and the datetime value (xAxis
) in the fixed tooltip.
I somehow followed this Highchart demo to add a vertical plotline. But, I can't seem to find any related demo or samples that adds a vertical plotline and correspondingly display the x-axis and y-axis points. Is this doable in Highchart?
Note: Adding the vertical plotline is invoked via a button and, a value is passed to the chart.
Highchart configuration code
function plotChartData(seriesData, xTitle)
{
myChart = new Highcharts.Chart({
chart: {
renderTo: 'container',
type: 'line',
zoomType: 'xy',
panning: true,
panKey: 'shift',
plotBorderWidth: 1
},
title: {
text: ''
},
legend: {
layout: 'horizontal',
align: 'left',
itemDistance: 10,
borderWidth: 0,
itemMarginTop: 0,
itemMarginBottom: 0,
padding: 20
},
plotOptions: {
series: {
states: {
hover: {
enabled: false
}
},
dataLabels: {
enabled: false,
format: '{y}'
},
allowPointSelect: false
}
},
xAxis: {
type: 'datetime',
labels: {
rotation: -65,
style: {
fontSize: '9px',
fontFamily: 'Verdana, sans-serif'
}
},
crosshair: true,
dateTimeLabelFormats: {
day: '%d %b %Y %I:%M %P'
}
},
yAxis: {
gridLineColor: '#DDDDDD',
gridLineWidth: 0.5
},
tooltip: {
positioner: function () {
return {
x: this.chart.plotLeft,
y: this.chart.plotTop
}
},
useHTML: true,
pointFormat: '<small><font color="{series.color}"><strong>{series.name}</strong></font>: <strong>{point.y}</strong></small><br/>',
headerFormat: '<span style="font-size: 8px">{point.key}</span><br/>',
xDateFormat: '%d-%m-%Y %H:%M:%S',
shared: true,
valueDecimals: 2,
shadow: false,
borderWidth: 0,
backgroundColor: 'rgba(255,255,255,0.8)'
},
series: [{
name: xTitle,
data: seriesData
}]
});
}
Code that add plot line in x-Axis. fixedLineDateTime
is the value passed after clicking the button.
if (myChart.xAxis[0].plotLinesAndBands.length === 0 || myChart.xAxis[0].plotLinesAndBands.length === null) {
myChart.xAxis[0].addPlotLine({
value: +moment(fixedLineDateTime),
color: 'red',
width: 1,
id: 'plot-vertical-id'
});
}
Any help is greatly appreciated.
;` I get the calculated datetime value in my x-axis (ex. 1484641900000). Is there a way to convert this into an exact datetime (eg. 10-05-2017 02:39 PM)? – Junius May 11 '17 at 02:39