import 'bootstrap.css';
import '@mescius/wijmo.styles/wijmo.css';
import './styles.css';
import * as core from '@mescius/wijmo';
import * as input from '@mescius/wijmo.input';
import * as finance from '@mescius/wijmo.chart.finance';
import { getData } from './data';
//
document.readyState === 'complete' ? init() : window.onload = init;
//
function init() {
// create the chart
let data = getData();
let theChart = new finance.FinancialChart('#theChart', {
itemsSource: data,
bindingX: 'date',
chartType: 'Kagi',
series: [
{
binding: 'high,low,open,close',
style: {
stroke: 'rgb(136, 189, 230)'
},
altStyle: {
stroke: 'rgb(136, 189, 230)'
},
name: 'Facebook'
}
],
options: {
kagi: {
reversalAmount: 1,
rangeMode: 'Fixed',
fields: 'Close'
}
},
legend: {
position: 'None'
},
tooltip: {
content: function (ht) {
var date = ht.item && ht.item.date ? ht.item.date : null, content = '';
if (core.isDate(date)) {
date = core.Globalize.formatDate(date, 'MM/dd/yy');
}
if (ht && ht.item) {
content =
'<b>' + ht.name + '</b><br/>' +
'Date: ' + date + '<br/>' +
'Open: ' + core.Globalize.format(ht.item.open, 'n2') + '<br/>' +
'High: ' + core.Globalize.format(ht.item.high, 'n2') + '<br/>' +
'Low: ' + core.Globalize.format(ht.item.low, 'n2') + '<br/>' +
'Close: ' + core.Globalize.format(ht.item.close, 'n2') + '<br/>' +
'Volume: ' + core.Globalize.format(ht.item.volume, 'n0');
}
return content;
}
}
});
//
let revAmount = new input.InputNumber('#inputRevAmount', {
step: 1,
min: 0,
value: 1,
format: 'n0',
valueChanged: function (sender) {
if (sender == null || sender.value < sender.min) {
return;
}
theChart.options.kagi.reversalAmount = sender.value;
theChart.invalidate();
}
});
//
let rangeMode = new input.Menu('#selRangeMode', {
selectedValue: 'Fixed',
itemClicked: function (sender) {
theChart.options.kagi.rangeMode = sender.selectedValue;
var reversalInput = revAmount;
if (sender.selectedValue === 'Percentage') {
reversalInput.format = 'p0';
reversalInput.min = 0;
reversalInput.max = 1;
reversalInput.value = core.clamp(reversalInput.value, 0, .05);
reversalInput.step = 0.05;
}
else if (sender.selectedValue === 'ATR') {
reversalInput.format = 'n0';
reversalInput.min = 2;
reversalInput.max = data.length - 2;
reversalInput.value = core.clamp(reversalInput.value, 14, data.length - 2);
reversalInput.step = 1;
}
else {
reversalInput.format = 'n0';
reversalInput.min = 1;
reversalInput.max = null;
reversalInput.value = 1;
reversalInput.step = 1;
}
updateMenuHeader(rangeMode, 'Range Mode');
theChart.invalidate();
}
});
updateMenuHeader(rangeMode, 'Range Mode');
//
let dataFields = new input.Menu('#selDataFields', {
selectedValue: 'Close',
itemClicked: function (sender) {
theChart.options.kagi.fields = sender.selectedValue;
updateMenuHeader(dataFields, 'Data Fields');
theChart.invalidate();
}
});
updateMenuHeader(dataFields, 'Data Fields');
//
let series = theChart.series[0];
let stroke = new input.InputColor('#inputStroke', {
value: 'rgb(136, 189, 230)',
valueChanged: function (sender) {
let color = sender.value;
series.style.stroke = color;
theChart.invalidate();
}
});
let altStroke = new input.InputColor('#inputAltStroke', {
value: 'rgb(136, 189, 230)',
valueChanged: function (sender) {
let color = sender.value;
series.altStyle.stroke = color;
theChart.invalidate();
}
});
}
// show menu header and current value
function updateMenuHeader(menu, header) {
menu.header = header
? header + ': <b>' + menu.text + '</b>'
: menu.text;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>MESCIUS Wijmo FlexChart Kagi</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- SystemJS -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.21.5/system.src.js" integrity="sha512-skZbMyvYdNoZfLmiGn5ii6KmklM82rYX2uWctBhzaXPxJgiv4XBwJnFGr5k8s+6tE1pcR1nuTKghozJHyzMcoA==" crossorigin="anonymous"></script>
<script src="systemjs.config.js"></script>
<script>
System.import('./src/app');
</script>
</head>
<body>
<div class="container-fluid">
<div id="theChart"></div>
<!-- Settings -->
<div class="panel-group" id="settings">
<div class="panel panel-default">
<div class="panel-collapse collapse in">
<div class="panel-body">
<ul class="list-inline">
<li>
<label>Reversal Amount</label>
<input id="inputRevAmount" />
</li>
<li>
<select id="selRangeMode">
<option value="Fixed">Fixed</option>
<option value="ATR">Average True Range</option>
<option value="Percentage">Percentage</option>
</select>
</li>
<li>
<select id="selDataFields">
<option value="High">High</option>
<option value="Low">Low</option>
<option value="Open">Open</option>
<option value="Close">Close</option>
<option value="HighLow">High/Low</option>
<option value="HL2">HL Avg.</option>
<option value="HLC3">HLC Avg.</option>
<option value="HLOC4">HLOC Avg.</option>
</select>
</li>
</ul>
<ul class="list-inline">
<li>
<label>Stroke</label>
<input id="inputStroke" />
</li>
<li>
<label>Alt. Stroke</label>
<input id="inputAltStroke" />
</li>
</ul>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
// some stock data from Google Finance
export function getData() {
return [
{ "date": "05/18/12", "open": 42.05, "high": 45, "low": 38, "close": 38.23, "volume": 580587742 },
{ "date": "05/21/12", "open": 36.53, "high": 36.66, "low": 33, "close": 34.03, "volume": 168309831 },
{ "date": "05/22/12", "open": 32.61, "high": 33.59, "low": 30.94, "close": 31, "volume": 102053826 },
{ "date": "05/23/12", "open": 31.37, "high": 32.5, "low": 31.36, "close": 32, "volume": 73721135 },
{ "date": "05/24/12", "open": 32.95, "high": 33.21, "low": 31.77, "close": 33.03, "volume": 50275879 },
{ "date": "05/25/12", "open": 32.9, "high": 32.95, "low": 31.11, "close": 31.91, "volume": 37189630 },
{ "date": "05/29/12", "open": 31.48, "high": 31.69, "low": 28.65, "close": 28.84, "volume": 78060799 },
{ "date": "05/30/12", "open": 28.7, "high": 29.55, "low": 27.86, "close": 28.19, "volume": 57267867 },
{ "date": "05/31/12", "open": 28.54, "high": 29.67, "low": 26.83, "close": 29.6, "volume": 111639200 },
{ "date": "06/01/12", "open": 28.89, "high": 29.15, "low": 27.39, "close": 27.72, "volume": 41855500 },
{ "date": "06/04/12", "open": 27.2, "high": 27.65, "low": 26.44, "close": 26.9, "volume": 35230290 },
{ "date": "06/05/12", "open": 26.7, "high": 27.76, "low": 25.75, "close": 25.87, "volume": 42473262 },
{ "date": "06/06/12", "open": 26.07, "high": 27.17, "low": 25.52, "close": 26.81, "volume": 61487019 },
{ "date": "06/07/12", "open": 27, "high": 27.35, "low": 26.15, "close": 26.31, "volume": 26167757 },
{ "date": "06/08/12", "open": 26.55, "high": 27.76, "low": 26.44, "close": 27.1, "volume": 38033420 },
{ "date": "06/11/12", "open": 27.18, "high": 28.07, "low": 26.84, "close": 27, "volume": 28225887 },
{ "date": "06/12/12", "open": 27.48, "high": 27.77, "low": 26.96, "close": 27.4, "volume": 15822414 },
{ "date": "06/13/12", "open": 27.66, "high": 28.1, "low": 27.1, "close": 27.27, "volume": 17118672 },
{ "date": "06/14/12", "open": 27.65, "high": 28.32, "low": 27.38, "close": 28.29, "volume": 16854124 },
{ "date": "06/15/12", "open": 28.5, "high": 30.1, "low": 28.35, "close": 30.01, "volume": 43563739 },
{ "date": "06/18/12", "open": 29.96, "high": 32.08, "low": 29.41, "close": 31.41, "volume": 42978209 },
{ "date": "06/19/12", "open": 31.54, "high": 32.18, "low": 30.7, "close": 31.91, "volume": 30848913 },
{ "date": "06/20/12", "open": 31.92, "high": 31.93, "low": 31.15, "close": 31.6, "volume": 15558921 },
{ "date": "06/21/12", "open": 31.67, "high&