Getting StartedPerformance !!!Chart DataBar and Column ChartsLine and Area ChartsPie ChartsScatter and Bubble ChartsRadar and Polar ChartsFinancial ChartsCombinational ChartsDynamic ChartsWorking with Chart AxesChart FeaturesCustomizing ChartClient-Side Events |
Price Index
Open:
High:
Low: Close:Volume:
This sample demonstrates the Candlestick chart type.
For detailed implementation, please take a look at the HTML code tab.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>
Candlestick Chart with Volume Example - HTML5 jQuery Chart Plugin by jqChart
</title>
<link rel="stylesheet" type="text/css" href="../css/jquery.jqChart.css" />
<link rel="stylesheet" type="text/css" href="../css/jquery.jqRangeSlider.css" />
<link rel="stylesheet" type="text/css" href="../themes/le-frog/jquery-ui-1.8.20.css" />
<script src="../js/jquery-1.5.2.min.js" type="text/javascript"></script>
<script src="../js/jquery.jqChart.min.js" type="text/javascript"></script>
<script src="../js/jquery.jqRangeSlider.min.js" type="text/javascript"></script>
<!--[if IE]><script lang="javascript" type="text/javascript" src="../js/excanvas.js"></script><![endif]-->
<script lang="javascript" type="text/javascript">
function round(d) {
return Math.round(100 * d) / 100;
}
var ohlcData = [];
var volumeData = [];
var date = new Date(2010, 0, 1);
var high = Math.random() * 40;
var close = high - Math.random();
var low = close - Math.random();
var open = (high - low) * Math.random() + low;
ohlcData.push([date, round(high), round(low), round(open), round(close)]);
var volume = 100 + 15 * Math.random();
volumeData.push([date, round(volume)]);
for (var day = 2; day <= 60; day++) {
date = new Date(2010, 0, day);
high = open + Math.random();
close = high - Math.random();
low = close - Math.random();
var oldOpen = open;
open = (high - low) * Math.random() + low;
if (low > oldOpen) {
low = oldOpen;
}
ohlcData.push([date, round(high), round(low), round(open), round(close)]);
volume = volume + 10 * Math.random() - 5;
volumeData.push([date, round(volume)]);
}
$(document).ready(function () {
$('#jqChart').jqChart({
legend: { visible: false },
border: { lineWidth: 0, padding: 0 },
tooltips: {
type: 'shared',
disabled: true
},
crosshairs: {
enabled: true,
hLine: false
},
animation: { duration: 1 },
axes: [
{
type: 'linear',
location: 'left',
width: 30
}
],
series: [
{
title: 'Price Index',
type: 'candlestick',
data: ohlcData,
priceUpFillStyle: 'white',
priceDownFillStyle: 'black',
strokeStyle: 'black'
}
]
});
$('#jqChartVolume').jqChart({
legend: { visible: false },
border: { lineWidth: 0, padding: 0 },
tooltips: {
type: 'shared',
disabled: true
},
crosshairs: {
enabled: true,
hLine: false
},
animation: { duration: 1 },
axes: [
{
type: 'dateTime',
location: 'bottom'
},
{
type: 'linear',
location: 'left',
width: 30
}
],
series: [
{
type: 'column',
data: volumeData,
fillStyle: 'black'
}
]
});
var isHighlighting = false;
$('#jqChart').bind('dataHighlighting', function (event, data) {
if (!data) {
$('#jqChartVolume').jqChart('highlightData', null);
return;
}
$('#open').html(data.open);
$('#high').html(data.high);
$('#low').html(data.low);
$('#close').html(data.close);
var date = data.chart.stringFormat(data.x, "mmmm d, yyyy");
$('#date').html(date);
if (!isHighlighting) {
isHighlighting = true;
var index = $.inArray(data.dataItem, ohlcData);
$('#jqChartVolume').jqChart('highlightData', [volumeData[index]]);
}
isHighlighting = false;
});
$('#jqChartVolume').bind('dataHighlighting', function (event, data) {
if (!data) {
$('#jqChart').jqChart('highlightData', null);
return;
}
$('#volume').html(data.y);
if (!isHighlighting) {
isHighlighting = true;
var index = $.inArray(data.dataItem, volumeData);
$('#jqChart').jqChart('highlightData', [ohlcData[index]]);
}
isHighlighting = false;
});
$('#jqChart').jqChart('highlightData', [ohlcData[0]]);
$('#jqChartVolume').jqChart('highlightData', [volumeData[0]]);
});
</script>
</head>
<body>
<h3>
Price Index</h3>
<div style="margin-left: 10px">
<b>Open:</b><span id="open" style="display: inline-block; width: 45px;"> </span>
<b>High:</b><span id="high" style="display: inline-block; width: 45px;"> </span>
<b>Low:</b><span id="low" style="display: inline-block; width: 45px;"> </span><b>Close:</b><span
id="close" style="display: inline-block; width: 45px;"></span><b>Volume: </b>
<span id="volume" style="display: inline-block; width: 45px;"></span><span style="float: right;
font-weight: bolder; width: 150px" id="date"></span>
</div>
<div>
<div>
<div id="jqChart" style="width: 600px; height: 250px;">
</div>
</div>
<div>
<div id="jqChartVolume" style="width: 600px; height: 130px;">
</div>
</div>
</div>
</body>
</html>
|
Follow us on Twitter