I am trying to add 'Page number x of y' to a PDF generated using jspdf and jspdf-autotable. I have used the code from the examples.js file on jspdf-autotable example site and also used the jspdf.debug.js file from this website which contains the putTotalPages function in.
The result I am getting on each page is 'Page 1 of {total_pages_count_string}' on first page and 'Page 2 of {total_pages_count_string}' on second page i.e. the total_pages_count_string does not appear to be updating correctly.
My entire code is as follows:
$('#print').click(function() {
$('#html-table table').remove();
var table = $("#amu-whiteboard").tabulator("getHtml");
$('#html-table').append(table);
$('#html-table>table').attr("id", "table");
$('#table th:not(:nth-child(1), :nth-child(2)), #table td:not(:nth-child(1), :nth-child(2))').remove();
var columns = ["Bed", "Name", "Diagnoses", "Jobs"];
var doc = new jsPDF('l', 'pt');
doc.setFont('Helvetica', 'normal');
doc.setTextColor(40);
var dateTime = moment().format('HH:mm on MMMM Do, YYYY');
var printedOn = "Printed at " + dateTime;
var totalPagesExp = "{total_pages_count_string}";
var pageContent = function(data) {
doc.setFontSize(14);
doc.text(21, 30, "AMU Handover Sheet");
doc.setFontSize(10);
doc.text(printedOn, doc.internal.pageSize.width / 2, 30, 'center');
var str = "Page " + data.pageCount;
if (typeof doc.putTotalPages === 'function') {
str = str + " of " + totalPagesExp;
}
doc.text(str, doc.internal.pageSize.width - 20, 30, 'right');
};
if (typeof doc.putTotalPages === 'function') {
doc.putTotalPages(totalPagesExp);
}
var elem = document.getElementById("table");
var res = doc.autoTableHtmlToJson(elem);
doc.autoTable(columns, res.data, {
addPageContent: pageContent,
theme: 'grid',
tableLineWidth: 0,
bodyStyles: {
halign: 'center',
valign: 'middle',
fillColor: 250,
lineWidth: 0.5,
lineColor: 180,
cellPadding: 6,
fontSize: 11
},
margin: {
horizontal: 20,
bottom: 40,
top: 40
},
drawRow: function(row, data) {
doc.setFontSize(12);
doc.setFontStyle('bold');
if (row.index === 0) {
doc.setTextColor(30);
doc.rect(data.settings.margin.left, row.y, data.table.width, 30, 'S');
doc.autoTableText("A BAY", data.settings.margin.left + 5, row.y + 16, {
halign: 'left',
valign: 'middle'
});
data.cursor.y += 30;
} else if (row.index === 6) {
doc.setTextColor(30);
doc.rect(data.settings.margin.left, row.y, data.table.width, 30, 'S');
doc.autoTableText("B BAY", data.settings.margin.left + 5, row.y + 16, {
halign: 'left',
valign: 'middle'
});
data.cursor.y += 30;
} else if (row.index === 17) {
doc.setTextColor(30);
doc.rect(data.settings.margin.left, row.y, data.table.width, 30, 'S');
doc.autoTableText("C BAY", data.settings.margin.left + 5, row.y + 16, {
halign: 'left',
valign: 'middle'
});
data.cursor.y += 30;
} else if (row.index === 28) {
doc.setTextColor(30);
doc.rect(data.settings.margin.left, row.y, data.table.width, 30, 'S');
doc.autoTableText("SIDE ROOMS", data.settings.margin.left + 5, row.y + 16, {
halign: 'left',
valign: 'middle'
});
data.cursor.y += 30;
} else if (row.index === 30) {
doc.setTextColor(30);
doc.rect(data.settings.margin.left, row.y, data.table.width, 30, 'S');
doc.autoTableText("FAIRFAX", data.settings.margin.left + 5, row.y + 16, {
halign: 'left',
valign: 'middle'
});
data.cursor.y += 30;
}
},
headerStyles: {
fillColor: 120,
halign: 'center',
valign: 'middle',
fontSize: 12,
},
alternateRowStyles: {
fillColor: 255
},
columnStyles: {
0: {
columnWidth: 40
},
1: {
columnWidth: 180,
halign: 'left',
},
2: {
columnWidth: 240
},
}
});
doc.save("table.pdf");
})
Can anybody suggest where I am going wrong with this?
I think putTotalPages() has to be called after autotable.
Related
I am using the Organization Chart and want to change the start of a line to be from a different place of the node. An example fiddle is at https://jsfiddle.net/markjjordan/oL19jfwv/70/.
The source code is as follows:
var nodes = [
{
id: '001.b001.b004',
//column: 1,
//width: 200,
offset: '-30%',
}
,
{
id: '001.b001.b003',
//column: 2,
//width: 200,
offset: '-30%',
}
,
{
id: '001.b001.b002',
//column: 3,
//width: 200,
offset: '-30%',
}
,
{
id: '001.b001.b001.b004',
//column: 4,
//width: 200,
offset: '-15%',
}
,
{
id: '001.b001.b001.b003',
//column: 5,
//width: 200,
offset: '-15%',
}
,
{
id: '001.b001.b001.b002',
//column: 6,
//width: 200,
offset: '-15%',
}
,
{
id: '001.b001.b001.b001',
//column: 7,
//width: 200,
offset: '-15%',
}
,
{
id: '001.b001.b001',
//column: 8,
//width: 200,
offset: '-30%',
}
,
{
id: '001.b001.b005',
//column: 0,
//width: 200,
offset: '-30%',
}
,
{
id: '001.b001',
//column: 9,
//width: 200,
offset: '-45%',
}
,
{
id: '001',
//column: 10,
//width: 200,
offset: '-60%',
color: 'orange'
}
,
{
id: '001.001',
//column: 11,
//width: 200,
offset: '-45%',
}
,
{
id: '001.001.005',
//column: 12,
//width: 200,
offset: '-30%',
}
,
{
id: '001.001.001',
//column: 13,
//width: 200,
offset: '-30%',
}
,
{
id: '001.001.001.001',
//width: 200,
//column: 14,
offset: '-15%',
}
,
{
id: '001.001.001.002',
//width: 200,
//column: 15,
offset: '-15%',
}
,
{
id: '001.001.001.003',
//width: 200,
//column: 16,
offset: '-15%',
}
,
{
id: '001.001.001.004',
//width: 200,
//column: 17,
offset: '-15%',
}
,
{
id: '001.001.002',
//width: 200,
//column: 18,
offset: '-30%',
}
,
{
id: '001.001.003',
//width: 200,
//column: 19,
offset: '-30%',
}
,
{
id: '001.001.004',
//width: 200,
//column: 20,
offset: '-30%',
}
]
;
var counter = 0;
nodes.forEach(function(element) {
//console.log(element);
element.width = 200;
element.column = counter++;
});
Highcharts.chart('container', {
chart: {
height: 2000,
//width: 800,
inverted: true
},
title: {
text: 'Highcharts Org Chart'
},
series: [{
type: 'organization',
name: 'Highsoft',
keys: ['from', 'to'],
nodePadding: 5,
hangingIndent: 10,
data: [
['001', '001.001'],
['001.001', '001.001.005'],
['001.001', '001.001.001'],
['001.001.001', '001.001.001.001'],
['001.001.001', '001.001.001.002'],
['001.001.001', '001.001.001.003'],
['001.001.001', '001.001.001.004'],
['001.001', '001.001.002'],
['001.001', '001.001.003'],
['001.001', '001.001.004'],
['001', '001.b001'],
['001.b001', '001.b001.b001'],
['001.b001.b001', '001.b001.b001.b001'],
['001.b001.b001', '001.b001.b001.b002'],
['001.b001.b001', '001.b001.b001.b003'],
['001.b001.b001', '001.b001.b001.b004'],
['001.b001', '001.b001.b002'],
['001.b001', '001.b001.b003'],
['001.b001', '001.b001.b004'],
['001.b001', '001.b001.b005'],
],
nodes: nodes,
colorByPoint: false,
color: '#007ad0',
dataLabels: {
color: 'white'
},
borderColor: 'white',
nodeWidth: 65
}],
tooltip: {
outside: true
},
exporting: {
allowHTML: true,
sourceWidth: 800,
sourceHeight: 600
}
});
All blue nodes above the orange one have a "from" reference for the orange node and a "to" reference for the blue node in the data parameter of HighCharts… I needed to do this because I want everything above the orange node to have multiple parents.
What I'd like as far as the lines go is to have lines coming from or to a blue node to be on the left side instead of the top or bottom as in the jsfiddle.
You can achieve it simply by wrapping the Highcharts.seriesTypes.organization.prototype.translateLink method and changing the way links path is created. I've prepared an example for you where a new layout = "custom" is added.
Code:
(function(H) {
H.seriesTypes.organization.prototype.translateLink = function(point) {
var fromNode = point.fromNode,
toNode = point.toNode,
series = point.series,
layout = toNode.layout,
crisp = Math.round(this.options.linkLineWidth) % 2 / 2,
x1 = Math.floor(
fromNode.shapeArgs.x + fromNode.shapeArgs.width
) + crisp,
y1 = Math.floor(
fromNode.shapeArgs.y + fromNode.shapeArgs.height / 2
) + crisp,
x2 = Math.floor(toNode.shapeArgs.x) + crisp,
y2 = Math.floor(
toNode.shapeArgs.y + toNode.shapeArgs.height / 2
) + crisp,
xMiddle,
hangingIndent = this.options.hangingIndent,
toOffset = toNode.options.offset,
percentOffset = /%$/.test(toOffset) && parseInt(toOffset, 10),
inverted = this.chart.inverted,
isEven = fromNode.linksFrom.length % 2 === 0,
lastToNodeId =
fromNode.linksFrom[fromNode.linksFrom.length - 1].to,
linkBranchOffset = H.defined(fromNode.linkBranchOffset) ?
fromNode.linkBranchOffset : undefined,
prevOffset = 'prevLinkBranchOffset' + fromNode.column,
middleNode1,
middleNode2,
directionIndicator,
linkDirection,
linkCorrection,
branchOffset,
d;
if (inverted) {
x1 -= fromNode.shapeArgs.width;
x2 += toNode.shapeArgs.width;
}
xMiddle = Math.floor(
x2 +
(inverted ? 1 : -1) *
(this.colDistance - this.nodeWidth) / 2
) + crisp;
// Put the link on the side of the node when an offset is given. HR
// node in the main demo.
if (
percentOffset &&
(percentOffset >= 50 || percentOffset <= -50)
) {
xMiddle = x2 = Math.floor(
x2 + (inverted ? -0.5 : 0.5) * toNode.shapeArgs.width
) + crisp;
y2 = toNode.shapeArgs.y;
if (percentOffset > 0) {
y2 += toNode.shapeArgs.height;
}
}
if (toNode.hangsFrom === fromNode) {
if (this.chart.inverted) {
y1 = Math.floor(
fromNode.shapeArgs.y +
fromNode.shapeArgs.height -
hangingIndent / 2
) + crisp;
y2 = toNode.shapeArgs.y + toNode.shapeArgs.height;
} else {
y1 = Math.floor(
fromNode.shapeArgs.y +
hangingIndent / 2
) + crisp;
}
xMiddle = x2 = Math.floor(
toNode.shapeArgs.x + toNode.shapeArgs.width / 2
) + crisp;
}
if (layout === 'custom') {
d = this.curvedPath([
[x1, y1],
[xMiddle - toNode.nodeHeight / 2 - 10, y1],
[xMiddle - toNode.nodeHeight / 2 - 10, y2]
], this.options.linkRadius);
} else {
d = this.curvedPath([
[x1, y1],
[xMiddle, y1],
[xMiddle, y2],
[x2, y2]
], this.options.linkRadius);
}
point.plotY = 1;
point.shapeType = 'path';
point.shapeArgs = {
d: d
};
}
})(Highcharts)
Demo: (open on screen width > 800px)
https://jsfiddle.net/BlackLabel/02raLmuo/
I am using Highcharts to show BoxPlot Chart.
Here is an example of this chart: http://jsfiddle.net/tLucL6mq/3/.
$('#container').highcharts({
chart: {
type: 'boxplot',
inverted: true
},
title: {
text: 'Sample Base Salary Range'
},
legend: {
enabled: false
},
xAxis: {
categories: ['4', '3', '2', '1', '0'],
title: {
text: 'Job Level'
}
},
yAxis: {
title: {
text: 'Base Salary'
}
},
plotOptions: {
boxplot: {
fillColor: '#F0F0E0',
lineWidth: 2,
medianColor: '#0C5DA5',
medianWidth: 3
}
},
series: [{
name: "Observation Data",
data: [
['0', 68, 75, 79, 82, 84, 89], //level 4 - category 0
['1', 53, 63, 68, 72, 75, 79], //level 3 - category 1
['2', 47, 52, 59, 64, 67, 68], //level 2 - category 2
['3', 35, 37, 39, 42, 46, 51], //level 1 - category 3
['4', 32, 33, 34, 38, 40, 45] //level 0 - category 4
],
tooltip: {
headerFormat: '<b>{point.series.name}</b><br/><em>Job Level: {point.x}</em><br/>',
pointFormat: '- Max: {point.high}<br/>' +
'- Q3: {point.q3}<br/>' +
'- Median: {point.median}<br/>' +
'- Q1: {point.q1}<br/>' +
'- Min: {point.low}<br/>'
}
}]
});
I want to add border radius, but I did not find this option.
I try to add it in a lot of positions. But no succees.
Any help?
Border radius is not supported by default in Highcharts boxplot series. The element, which you want to modify is a path, so it can not be done in a simple way.
However, by using Highcharts.SVGRenderer you can replace the path element by a rect with border radius, example:
events: {
render: function() {
var points = this.series[0].points,
pathBBox,
path;
Highcharts.each(points, function(p) {
path = p.graphic.element.children[2];
pathBBox = path.getBBox();
if (!p.additionalElement) {
p.additionalElement = this.renderer.rect(pathBBox.x + this.plotLeft, pathBBox.y + this.plotTop, pathBBox.width, pathBBox.height, 5)
.attr({
stroke: '#7cb5ec',
'stroke-width': 1,
zIndex: 4
})
.add();
} else {
p.additionalElement.attr({
x: pathBBox.x + this.plotLeft,
y: pathBBox.y + this.plotTop,
width: pathBBox.width,
height: pathBBox.height
});
}
path.setAttribute('stroke', 'transparent');
}, this);
}
}
Live demo: http://jsfiddle.net/BlackLabel/y9umo52w/
If this helps, you can also directly set the attribute 'd' of the current graphic.
function roundCornerBox(pathBBox: { x: number; y: number; width: number; height: number;}, radius: number) {
const { x, y, width, height } = pathBBox;
const eightPoints = [
{ x, y: y + radius },
{ x: x + radius, y },
{ x: x - radius + width, y },
{ x: x + width, y: y + radius },
{ x: x + width, y: y + height - radius },
{ x: x + width - radius, y: y + height },
{ x: x + radius, y: y + height },
{ x, y: y + height - radius }
];
const controlPoints = [
{ x, y },
{ x: x + width, y },
{ x: x + width, y: y + height },
{ x, y: y + height }
];
let controlPointIndex = 0,
lastCommand = 'Q',
controlPoint = controlPoints[0];
let d = '';
eightPoints.forEach((point, index) => {
if (index === 0) {
d += `M ${point.x} ${point.y} `;
return;
}
if (lastCommand === 'Q') {
controlPoint = controlPoints[controlPointIndex];
d += `${lastCommand} ${controlPoint.x} ${controlPoint.y} ${point.x} ${point.y}`;
lastCommand = 'L';
controlPointIndex++;
} else {
d += `${lastCommand} ${point.x} ${point.y} `;
lastCommand = 'Q';
}
});
d += 'z';
return d;
};
events: {
render: function() {
var points = this.series[0].points,
pathBBox,
path;
var radius = 5;
Highcharts.each(points, function(p) {
path = p.graphic.element.children[2];
pathBBox = path.getBBox();
path.setAttribute('d', roundCornerBox(pathBBox, radius));
}, this);
}
}
I am working in an company as a trainee front end developer. I have been asked to research on how to gather or collect some datapoints on a particular spot in Google Maps and visualize them nicely on a graph.
Actually he liked one of my ideas. But he wants me to do this graph by cumulative distribution function.
Please see the codes below:
<!DOCTYPE HTML>
<html>
<head>
<script type="text/javascript">
window.onload = function () {
var chart = new CanvasJS.Chart("chartContainer", {
animationEnabled: true,
theme: "dark1",
title:{
text: "Network Technology on a Particular Spot"
},
axisY: {
title: "Movement Category(Avg.)",
suffix: "%"
},
legend: {
cursor:"pointer",
itemclick : toggleDataSeries
},
toolTip: {
shared: true,
content: toolTipFormatter,
suffix: "%"
},
data: [{
type: "bar",
showInLegend: true,
name: "2G",
color: "blue",
dataPoints: [
{ y: 23, label: "STANDSTILL" },
{ y: 36, label: "ON FOOT" },
{ y: 43, label: "ON VEHICLE" },
{isCumulativeSum : true}
]
},
{
type: "bar",
showInLegend: true,
name: "3G",
color: "yellow",
dataPoints: [
{ y: 12, label: "STANDSTILL" },
{ y: 86, label: "ON FOOT" },
{ y: 72, label: "ON VEHICLE" },
{isCumulativeSum : true}
]
},
{
type: "bar",
showInLegend: true,
name: "4G",
color: "red",
dataPoints: [
{ y: 22, label: "STANDSTILL" },
{ y: 16, label: "ON FOOT" },
{ y: 22, label: "ON VEHICLE" },
{isCumulativeSum : true}
]
},
{
type: "bar",
showInLegend: true,
name: "LTE",
color: "green",
dataPoints: [
{ y: 36, label: "STANDSTILL" },
{ y: 12, label: "ON FOOT" },
{ y: 39, label: "ON VEHICLE" },
{isCumulativeSum : true}
]
}]
});
chart.render();
function toolTipFormatter(e) {
var str = "";
var total = 0 ;
var str3;
var str2 ;
for (var i = 0; i < e.entries.length; i++){
var str1 = "<span style= \"color:"+e.entries[i].dataSeries.color + "\">" + e.entries[i].dataSeries.name + "</span>: <strong>"+ e.entries[i].dataPoint.y + "</strong> <br/>" ;
total = e.entries[i].dataPoint.y + total;
str = str.concat(str1);
}
str2 = "<strong>" + e.entries[0].dataPoint.label + "</strong> <br/>";
str3 = "<span style = \"color:Tomato\">Total: </span><strong>" + total + "</strong><br/>";
return (str2.concat(str)).concat(str3);
}
function toggleDataSeries(e) {
if (typeof (e.dataSeries.visible) === "undefined" || e.dataSeries.visible) {
e.dataSeries.visible = false;
}
else {
e.dataSeries.visible = true;
}
chart.render();
}
}
</script>
</head>
<body>
<div id="chartContainer" style="height: 500px; width: 100%;"></div>
<script src="https://canvasjs.com/assets/script/canvasjs.min.js"></script>
</body>
</html>
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);
});
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 '';
}
}