Demo: http://stevenhollidge.com/blog-source-code/highcharts/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta http-equiv="content-type" content="text/html; charset=UTF-8"> | |
<title>Markers for column type series - HighCharts example</title> | |
<script type='text/javascript' src='./js/jquery-1.9.1.js'></script> | |
<script type='text/javascript'>//<![CDATA[ | |
$(function () { | |
(function (H) { | |
H.wrap(H.Tooltip.prototype, 'refresh', function (proceed, points) { | |
// Run the original proceed method | |
proceed.apply(this, Array.prototype.slice.call(arguments, 1)); | |
// For each point add or update trackball | |
H.each(points, function (point) { | |
// Function variables | |
var series = point.series, | |
chart = series.chart, | |
pointX = point.plotX + series.xAxis.pos, | |
pointY = H.pick(point.plotClose, point.plotY) + series.yAxis.pos; | |
// If trackball functionality does not already exist | |
if (!point.series.options.marker) { | |
// If trackball is not defined | |
if (!series.trackball) { | |
series.trackball = chart.renderer.circle(pointX, pointY, 5).attr({ | |
fill: series.color, | |
stroke: 'white', | |
'stroke-width': 1, | |
zIndex: 5 | |
}).add(); | |
} else { | |
series.trackball.attr({ | |
x: pointX, | |
y: pointY | |
}); | |
} | |
} | |
}); | |
}); | |
H.wrap(H.Tooltip.prototype, 'hide', function (proceed) { | |
var series = this.chart.series; | |
// Run original proceed method | |
proceed.apply(this); | |
// For each series destroy trackball | |
H.each(series, function (serie) { | |
var trackball = serie.trackball; | |
if (trackball) { | |
serie.trackball = trackball.destroy(); | |
} | |
}); | |
}); | |
}(Highcharts)); | |
$.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; | |
for (i = 0; i < dataLength; i++) { | |
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 | |
]); | |
} | |
// set the allowed units for data grouping | |
var groupingUnits = [ | |
[ | |
'week', // unit name | |
[1] // allowed multiples | |
], | |
[ | |
'month', [1, 2, 3, 4, 6]] | |
]; | |
// create the chart | |
$('#container').highcharts('StockChart', { | |
rangeSelector: { | |
selected: 1 | |
}, | |
title: { | |
text: 'AAPL Historical' | |
}, | |
yAxis: [{ | |
title: { | |
text: 'OHLC' | |
}, | |
height: 200, | |
lineWidth: 2 | |
}, { | |
title: { | |
text: 'Volume' | |
}, | |
top: 300, | |
height: 100, | |
offset: 0, | |
lineWidth: 2 | |
}], | |
series: [{ | |
type: 'candlestick', | |
name: 'AAPL', | |
data: ohlc, | |
dataGrouping: { | |
units: groupingUnits | |
} | |
}, { | |
type: 'column', | |
name: 'Volume', | |
data: volume, | |
yAxis: 1, | |
dataGrouping: { | |
units: groupingUnits | |
} | |
}] | |
}); | |
}); | |
}); | |
//]]> | |
</script> | |
</head> | |
<body> | |
<script src="./js/highstock.js"></script> | |
<script src="./js/exporting.js"></script> | |
<div id="container" style="height: 500px; min-width: 500px"></div> | |
</body> | |
</html> | |
No comments:
Post a Comment