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: 'Renko',
series: [
{
binding: 'high,low,open,close',
style: {
stroke: 'rgb(136, 189, 230)',
fill: 'rgba(136, 189, 230, 0.701961)'
},
altStyle: {
stroke: 'rgb(136, 189, 230)',
fill: 'transparent'
},
name: 'Facebook'
}
],
options: {
renko: {
boxSize: 2,
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 boxSize = new input.InputNumber('#inputBoxSize', {
step: 1,
min: 0,
value: 2,
format: 'n0',
valueChanged: function (sender) {
if (sender == null || sender.value < sender.min) {
return;
}
theChart.options.renko.boxSize = sender.value;
theChart.invalidate();
}
});
//
let rangeMode = new input.Menu('#selRangeMode', {
selectedValue: 'Fixed',
itemClicked: function (sender) {
theChart.options.renko.rangeMode = sender.selectedValue;
if (sender.selectedValue === 'ATR') {
boxSize.min = 2;
boxSize.max = data.length - 2;
let size = core.clamp(boxSize.value, 14, data.length - 2);
boxSize.value = size;
theChart.options.renko.boxSize = size;
}
else {
boxSize.min = 1;
boxSize.max = null;
}
updateMenuHeader(rangeMode, 'Range Mode');
theChart.invalidate();
}
});
updateMenuHeader(rangeMode, 'Range Mode');
let dataFields = new input.Menu('#selDataFields', {
selectedValue: 'Close',
itemClicked: function (sender) {
theChart.options.renko.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 fill = new input.InputColor('#inputFill', {
value: 'rgba(136, 189, 230, 0.701961)',
valueChanged: function (sender) {
let color = sender.value;
series.style.fill = 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();
}
});
let altFill = new input.InputColor('#inputAltFill', {
value: 'transparent',
valueChanged: function (sender) {
let color = sender.value;
series.altStyle.fill = 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 Renko</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>Box Size</label>
<input id="inputBoxSize" />
</li>
<li>
<select id="selRangeMode">
<option value="Fixed">Fixed</option>
<option value="ATR">Average True Range</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="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>
<ul class="list-inline">
<li>
<label>Fill</label>
<input id="inputFill" />
</li>
<li>
<label>Alt. Fill</label>
<input id="inputAltFill" />
</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": 32.5, "low": 31.51, "close": 31.84, "volume": 21875228 },
{ "date": "06/22/12", "open": 32.41, "high": 33.45, "low": 32.06, "close": 33.05, "volume": 74833976 },
{ "date": "06/25/12", "open": 32.86, "high": 33.02, "low": 31.55, "close": 32.06, "volume": 24352818 },
{ "date": "06/26/12", "open": 32.69, "high": 33.44, "low": 32.5, "close": 33.1, "volume": 24858611 },
{ "date": "06/27/12", "open": 32.46, "high": 32.9, "low": 31.9, "close": 32.23, "volume": 28599506 },
{ "date": "06/28/12", "open": 31.96, "high": 32.19, "low": 30.9, "close": 31.36, "volume": 17713292 },
{ "date": "06/29/12", "open": 31.92, "high": 31.99, "low": 30.76, "close": 31.1, "volume": 19526823 },
{ "date": "07/02/12", "open": 31.25, "high": 31.73, "low": 30.55, "close": 30.77, "volume": 14131476 },
{ "date": "07/03/12", "open": 30.91, "high": 31.44, "low": 30.8, "close": 31.2, "volume": 8765498 },
{ "date": "07/05/12", "open": 31.32, "high": 31.62, "low": 31.02, "close": 31.47, "volume": 10036688 },
{ "date": "07/06/12", "open": 31.44, "high": 31.9, "low": 31.26, "close": 31.73, "volume": 10949006 },
{ "date": "