123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252 |
- <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>
|