252 lines
10 KiB
HTML
252 lines
10 KiB
HTML
<html>
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
<script src="esl.js"></script>
|
|
<script src="config.js"></script>
|
|
<script src="lib/facePrint.js"></script>
|
|
</head>
|
|
<body>
|
|
<style>
|
|
html, body, #main {
|
|
width: 100%;
|
|
height: 100%;
|
|
}
|
|
</style>
|
|
<div id="info"></div>
|
|
<div id="main"></div>
|
|
<script>
|
|
|
|
/**
|
|
* @see <https://en.wikipedia.org/wiki/Michelson%E2%80%93Morley_experiment>
|
|
* @see <http://bl.ocks.org/mbostock/4061502>
|
|
*/
|
|
var chart;
|
|
var data;
|
|
|
|
require([
|
|
'echarts',
|
|
'data/security-sh-2013.json',
|
|
'echarts/chart/candlestick',
|
|
'echarts/chart/line',
|
|
'echarts/component/title',
|
|
'echarts/component/legend',
|
|
'echarts/component/grid',
|
|
'echarts/component/tooltip',
|
|
'echarts/component/dataZoom',
|
|
'echarts/component/markPoint',
|
|
'echarts/component/markLine'
|
|
], function (echarts, rawData) {
|
|
|
|
chart = echarts.init(document.getElementById('main'), null, {
|
|
renderer: 'canvas'
|
|
});
|
|
data = splitData(rawData);
|
|
|
|
update();
|
|
|
|
chart.on('click', function (info) {
|
|
console.log(info);
|
|
if (info.data && info.data.length === 4) {
|
|
alert([
|
|
'clicked on: ',
|
|
'DATA: ' + info.name,
|
|
'OPEN: ' + info.data[0],
|
|
'CLOSE: ' + info.data[1],
|
|
'LOWEST: ' + info.data[2],
|
|
'HIGHEST: ' + info.data[3]
|
|
].join('\n'));
|
|
}
|
|
else if (info.data && info.data.length === 2) {
|
|
// Markpoint
|
|
alert('mark point');
|
|
}
|
|
});
|
|
})
|
|
|
|
function splitData(rawData) {
|
|
var categoryData = [];
|
|
var values = []
|
|
for (var i = 0; i < rawData.length; i++) {
|
|
categoryData.push(rawData[i].splice(0, 1)[0]);
|
|
values.push(rawData[i])
|
|
}
|
|
return {
|
|
categoryData: categoryData,
|
|
values: values
|
|
};
|
|
}
|
|
|
|
function parseDate(timestamp) {
|
|
var date = new Date(timestamp);
|
|
return date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate();
|
|
}
|
|
|
|
function update() {
|
|
|
|
chart.setOption({
|
|
legend: {
|
|
data: ['上证指数', '开盘']
|
|
},
|
|
tooltip: {
|
|
trigger: 'axis',
|
|
axisPointer: {
|
|
type: 'line'
|
|
}
|
|
},
|
|
grid: {
|
|
left: '10%',
|
|
right: '10%',
|
|
bottom: '15%'
|
|
},
|
|
xAxis: {
|
|
type: 'category',
|
|
data: data.categoryData,
|
|
scale: true,
|
|
boundaryGap : false,
|
|
axisLine: {onZero: false},
|
|
splitLine: {show: false},
|
|
splitNumber: 20,
|
|
min: 'dataMin',
|
|
max: 'dataMax'
|
|
},
|
|
yAxis: {
|
|
scale: true,
|
|
splitArea: {
|
|
show: true
|
|
}
|
|
},
|
|
dataZoom: [
|
|
{
|
|
type: 'inside',
|
|
start: 50,
|
|
end: 100
|
|
},
|
|
{
|
|
show: true,
|
|
type: 'slider',
|
|
y: '90%',
|
|
start: 50,
|
|
end: 100
|
|
}
|
|
],
|
|
series: [
|
|
{
|
|
name: '开盘',
|
|
type: 'line',
|
|
data: (function () {
|
|
opens = [];
|
|
for (var i = 0, len = data.values.length; i < len; i++) {
|
|
opens.push(data.values[i][0]);
|
|
}
|
|
return opens;
|
|
})(),
|
|
smooth: true,
|
|
lineStyle: {
|
|
normal: {color: '#aaa'}
|
|
}
|
|
},
|
|
{
|
|
name: '上证指数',
|
|
type: 'candlestick',
|
|
data: data.values,
|
|
tooltip: {
|
|
formatter: function (param) {
|
|
var param = param[0];
|
|
return [
|
|
'日期:' + param.name + '<hr size=1 style="margin: 3px 0">',
|
|
'开盘:' + param.data[0] + '<br/>',
|
|
'收盘:' + param.data[1] + '<br/>',
|
|
'日最低:' + param.data[2] + '<br/>',
|
|
'日最高:' + param.data[3] + '<br/>'
|
|
].join('')
|
|
}
|
|
},
|
|
markPoint: {
|
|
data: [
|
|
{
|
|
name: '某个坐标',
|
|
coord: ['2013/5/21', 2300]
|
|
},
|
|
{
|
|
name: '某个屏幕坐标',
|
|
x: 100,
|
|
y: 200,
|
|
label: {
|
|
normal: {
|
|
show: false
|
|
},
|
|
emphasis: {
|
|
show: true,
|
|
position: 'top',
|
|
formatter: 'zxcv'
|
|
}
|
|
}
|
|
},
|
|
{
|
|
name: 'max value (default)',
|
|
type: 'max'
|
|
},
|
|
{
|
|
name: 'min value (default)',
|
|
type: 'min'
|
|
},
|
|
{
|
|
name: 'max value (dim:close)',
|
|
type: 'max',
|
|
valueDim: 'close'
|
|
},
|
|
{
|
|
name: 'average value (dim:close)',
|
|
type: 'average',
|
|
valueDim: 'close'
|
|
}
|
|
],
|
|
tooltip: {
|
|
formatter: function (param) {
|
|
return param.name + '<br>' + (param.data.coord || '');
|
|
}
|
|
}
|
|
},
|
|
markLine: {
|
|
data: [
|
|
[
|
|
{name: '两个坐标之间的标线', coord: ['2013/4/25', 2130]},
|
|
{coord: ['2013/5/27', 2220]}
|
|
],
|
|
[
|
|
{name: '两个屏幕坐标之间的标线', x: 100, y: 100},
|
|
{x: 250, y: 130}
|
|
],
|
|
[
|
|
{name: 'max - min', type: 'max'},
|
|
{type: 'min'}
|
|
],
|
|
{
|
|
name: 'min line',
|
|
type: 'min'
|
|
},
|
|
{
|
|
name: 'max line on dim:open',
|
|
type: 'max',
|
|
valueDim: 'open'
|
|
}
|
|
]
|
|
}
|
|
}
|
|
]
|
|
});
|
|
|
|
// setTimeout(function () {
|
|
// chart.setOption({
|
|
// dataZoom: {
|
|
// startValue: '2013/1/28',
|
|
// endValue: '2013/1/30'
|
|
// }
|
|
// });
|
|
// }, 1000);
|
|
}
|
|
|
|
</script>
|
|
</body>
|
|
</html> |