jqwidgets-framework
Version:
jQWidgets is an advanced Angular, Vue, Blazor, React, Web Components, jquery, ASP .NET MVC, Custom Elements and HTML5 UI framework.
247 lines (233 loc) • 11.5 kB
HTML
<html lang="en">
<head>
<title id='Description'>JavaScript Chart with Tabs Example</title>
<meta name="description" content="This is an example of Javascript Chart with Tabs." />
<link rel="stylesheet" href="../../../jqwidgets/styles/jqx.base.css" type="text/css" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta name="viewport" content="width=device-width, initial-scale=1 maximum-scale=1 minimum-scale=1" />
<script type="text/javascript" src="../../../scripts/jquery-1.12.4.min.js"></script>
<script type="text/javascript" src="../../../jqwidgets/jqxcore.js"></script>
<script type="text/javascript" src="../../../jqwidgets/jqxtabs.js"></script>
<script type="text/javascript" src="../../../jqwidgets/jqxdata.js"></script>
<script type="text/javascript" src="../../../jqwidgets/jqxchart.core.js"></script>
<script type="text/javascript" src="../../../scripts/demos.js"></script>
<script type="text/javascript" src="../../../jqwidgets/jqxdraw.js"></script>
<script type="text/javascript">
$(document).ready(function () {
var initFinancialChart = function () {
var source =
{
datatype: "tsv",
datafields: [
{ name: 'Date' },
{ name: 'SPOpen' },
{ name: 'SPHigh' },
{ name: 'SPLow' },
{ name: 'SPClose' },
{ name: 'SPVolume' },
{ name: 'SPAdjClose' }
],
url: '../../sampledata/nasdaq_vs_sp500_detailed.txt'
};
var dataAdapter = new $.jqx.dataAdapter(source, { async: false, autoBind: true, loadError: function (xhr, status, error) { alert('Error loading "' + source.url + '" : ' + error); } });
var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
var toolTipCustomFormatFn = function (value, itemIndex, serie, group, categoryValue, categoryAxis) {
var dataItem = dataAdapter.records[itemIndex];
var volume = dataItem.SPVolume;
return '<DIV style="text-align:left"><b>Date: ' +
categoryValue.getDate() + '-' + months[categoryValue.getMonth()] + '-' + categoryValue.getFullYear() +
'</b><br />Open price: $' + value.open +
'</b><br />Close price: $' + value.close +
'</b><br />Low price: $' + value.low +
'</b><br />High price: $' + value.high +
'</b><br />Daily volume: ' + volume
'</DIV>';
};
// prepare jqxChart settings
var settings = {
title: "S&P 500 Candlestick Chart",
description: "(January 2017 - November 2018)",
enableAnimations: true,
animationDuration: 1500,
enableCrosshairs: true,
padding: { left: 5, top: 5, right: 5, bottom: 5 },
source: dataAdapter,
xAxis:
{
dataField: 'Date',
formatFunction: function (value) {
return value.getDate() + '-' + months[value.getMonth()] + '\'' + value.getFullYear().toString().substring(2);
},
type: 'date',
valuesOnTicks: true
},
colorScheme: 'scheme17',
seriesGroups:
[
{
type: 'candlestick',
columnsMinWidth: 4,
//skipOverlappingPoints: false,
toolTipFormatFunction: toolTipCustomFormatFn,
valueAxis:
{
title: { text: 'S&P 500<br>' },
minValue: 1500
},
series: [
{
dataFieldClose: 'SPClose',
displayTextClose: 'S&P Close price',
dataFieldOpen: 'SPOpen',
displayTextOpen: 'S&P Open price',
dataFieldHigh: 'SPHigh',
displayTextHigh: 'S&P High price',
dataFieldLow: 'SPLow',
displayTextLow: 'S&P Low price',
displayText: 'S&P 500',
lineWidth: 1
}
]
},
{
type: 'line',
valueAxis:
{
position: 'right',
title: { text: '<br>Daily Volume' },
gridLines: { visible: false },
tickMarks: { visible: false },
labels: {
formatFunction: function (value) {
return value / 1000000 + 'M';
}
}
},
series: [
{
dataField: 'SPVolume',
displayText: 'Volume',
lineWidth: 1
}
]
}
]
};
$('#financialChart').jqxChart(settings);
}
var initChart = function () {
// prepare the data
var source =
{
datatype: "csv",
datafields: [
{ name: 'Date' },
{ name: 'S&P 500' },
{ name: 'NASDAQ' }
],
url: '../../sampledata/nasdaq_vs_sp500.txt'
};
var dataAdapter = new $.jqx.dataAdapter(source, { async: false, autoBind: true, loadError: function (xhr, status, error) { alert('Error loading "' + source.url + '" : ' + error); } });
var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
// prepare jqxChart settings
var settings = {
title: "U.S. Stock Market Index Performance (2018)",
description: "NASDAQ Composite compared to S&P 500",
enableAnimations: true,
showLegend: true,
padding: { left: 10, top: 5, right: 10, bottom: 5 },
titlePadding: { left: 90, top: 0, right: 0, bottom: 10 },
source: dataAdapter,
xAxis:
{
dataField: 'Date',
type: 'date',
baseUnit: 'month',
unitInterval: 1,
valuesOnTicks: true,
labels: {
formatFunction: function (value) {
return months[value.getMonth()];
}
},
toolTipFormatFunction: function (value) {
return value.getDate() + '-' + months[value.getMonth()] + '-' + value.getFullYear();
},
tickMarks: { visible: true, unitInterval: 1 },
gridLines: { visible: true, unitInterval: 3 }
},
colorScheme: 'scheme04',
seriesGroups:
[
{
type: 'line',
valueAxis:
{
unitInterval: 500,
visible: true,
title: { text: 'Daily Closing Price' }
},
series: [
{ dataField: 'S&P 500', displayText: 'S&P 500' },
{ dataField: 'NASDAQ', displayText: 'NASDAQ' }
]
}
]
};
// setup the chart
$('#chart').jqxChart(settings);
}
// init widgets.
var initWidgets = function (tab) {
switch (tab) {
case 0:
initFinancialChart();
break;
case 1:
initChart();
break;
}
}
$('#jqxTabs').jqxTabs({ width: 750, height: 560, initTabContent: initWidgets });
});
</script>
</head>
<body class='default'>
<div id='jqxTabs'>
<ul>
<li style="margin-left: 30px;">
<div style="height: 20px; margin-top: 5px;">
<div style="margin-left: 4px; vertical-align: middle; text-align: center; float: left;">
Candlestick Chart
</div>
</div>
</li>
<li>
<div style="height: 20px; margin-top: 5px;">
<div style="margin-left: 4px; vertical-align: middle; text-align: center; float: left;">
Line Chart
</div>
</div>
</li>
</ul>
<div style="overflow: hidden;">
<div id='financialChart' style="width: 100%; height: 100%">
</div>
</div>
<div style="overflow: hidden;">
<div id='chart' style="width: 100%; height: 100%">
</div>
</div>
</div>
<div class="example-description">
<br />
<h2>Description</h2>
<br />
This is an example of Javascript Chart with Tabs. You can see how to integrate jqxChart with jqxTabs.
</div>
<div style="position: absolute; bottom: 5px; right: 5px;">
<a href="https://www.jqwidgets.com/" alt="https://www.jqwidgets.com/"><img alt="https://www.jqwidgets.com/" title="https://www.jqwidgets.com/" src="https://www.jqwidgets.com/wp-content/design/i/logo-jqwidgets.png"/></a>
</div>
</body>
</html>