kline.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847
  1. var myChart;
  2. var app = new Vue({
  3. el: '#app',
  4. data: {
  5. MA5: '',
  6. MA10: '',
  7. MA30: '',
  8. volMA5: '',
  9. volMA10: '',
  10. current: "15m",
  11. tabs: [{
  12. 'label': '1分鐘',
  13. 'value': "1m"
  14. },
  15. {
  16. 'label': '15分鐘',
  17. 'value': "15m"
  18. },
  19. {
  20. 'label': '30分鐘',
  21. 'value': "30m"
  22. },
  23. {
  24. 'label': '1小時',
  25. 'value': "1H"
  26. },
  27. {
  28. 'label': '4小時',
  29. 'value': "4H"
  30. },
  31. {
  32. 'label': '1日',
  33. 'value': "1D"
  34. },
  35. ],
  36. category: 2,
  37. categoryList: [{
  38. 'label': '深度',
  39. 'value': 1
  40. },
  41. {
  42. 'label': '成交',
  43. 'value': 2
  44. },
  45. {
  46. 'label': '简介',
  47. 'value': 3
  48. },
  49. ],
  50. txData: {
  51. lastPrice: '',
  52. high: '',
  53. volume: '',
  54. low: '',
  55. upRate: '',
  56. }, //交易数据统计
  57. buyList: [],
  58. sellList: [],
  59. dealHis: [],
  60. tokenInfo: {},
  61. page: 1,
  62. // 保存商品id
  63. typeId: '',
  64. // 保存socket对象
  65. webSocket: '',
  66. // 保存当前k线数据
  67. dataKLine: {
  68. data: [],
  69. dates: [],
  70. volumes: [],
  71. },
  72. // 保存初始未处理的时间数据
  73. oldDataKLine: ''
  74. },
  75. created() {
  76. // this.getTxData()
  77. // this.getDepth()
  78. // 保存商品id
  79. this.typeId = getQueryString('type');
  80. // 简历长连接
  81. this.scoketInit()
  82. },
  83. mounted() {
  84. myChart = echarts.init(document.getElementById('main'));
  85. this.draw()
  86. this.getKline((new Date()).getTime());
  87. // 获取成交记录
  88. this.getDealHis();
  89. },
  90. methods: {
  91. // 返回上一页
  92. back(url) {
  93. console.log('cf', url);
  94. uni.navigateTo({
  95. url
  96. })
  97. uni.postMessage({
  98. data: {
  99. action: 'message'
  100. }
  101. });
  102. },
  103. scoketInit() {
  104. const that = this;
  105. // 初始化websocket
  106. that.webSocket = new WebSocket("wss://wsaws.okx.com:8443/ws/v5/public");
  107. that.webSocket.onopen = function(event) {
  108. console.log('打开链接成功');
  109. const requestKData = JSON.stringify({
  110. "op": "subscribe",
  111. "args": [{
  112. "channel": "candle" + that.current,
  113. "instId": that.typeId
  114. }]
  115. })
  116. const requestNewData = JSON.stringify({
  117. "op": "subscribe",
  118. "args": [{
  119. "channel": "tickers",
  120. "instId": that.typeId
  121. }]
  122. })
  123. // 获取k线数据
  124. that.webSocket.send(requestKData)
  125. // 获取当前行情数据
  126. that.webSocket.send(requestNewData)
  127. }
  128. // 监听socket回复事件
  129. that.webSocket.addEventListener('message', function(event) {
  130. const item = JSON.parse(event.data);
  131. try {
  132. // 判断是否为
  133. if (item.arg.channel == ("candle" + that.current) && item.data) {
  134. const daytime = new Date(+item.data[0][0]);
  135. item.data[0][0] = that.initDay(daytime, "YYYY-mm-dd HH:MM:SS")
  136. if (item.data[0][0] != that.dataKLine.dates[that.dataKLine.dates.length - 1]) {
  137. // console.log(item.data[0][0], 'jiange', that.dataKLine.dates[that.dataKLine
  138. // .dates.length - 1]);
  139. const itemi = item.data[0]
  140. that.dataKLine.dates.push(itemi[0])
  141. that.dataKLine.data.push([+itemi[1], +itemi[2], +itemi[3], +itemi[4], +
  142. itemi[5]
  143. ])
  144. that.dataKLine.volumes.push([that.dataKLine.volumes.length, +itemi[5], +
  145. itemi[1] > +itemi[2] ? 1 : -1
  146. ])
  147. that.setKline()
  148. }
  149. // that.txData.lastPrice = data.data[0][]
  150. }
  151. //
  152. if (item.arg.channel == ("tickers") && item.data[0]) {
  153. // console.log('tickers');
  154. const data = item.data[0]
  155. that.txData.name = data.instId
  156. that.txData.lastPrice = +data.last
  157. that.txData.high = +data.high24h
  158. that.txData.volume = +data.open24h
  159. that.txData.low = +data.low24h
  160. that.txData.upRate = ((that.txData.lastPrice - that.txData.volume) / that.txData
  161. .volume * 100).toFixed(2)
  162. txData.upFlag = +that.txData.upRate > 0 ? 1 : 2;
  163. }
  164. } catch (e) {
  165. console.log("item: " + JSON.stringify(item));
  166. }
  167. });
  168. that.webSocket.onclose = function(event) {
  169. that.$nextTick(() => {
  170. that.scoketInit()
  171. that.dataKLine = {
  172. data: [],
  173. dates: [],
  174. volumes: [],
  175. };
  176. that.getKline((new Date()).getTime())
  177. })
  178. };
  179. },
  180. // 获取24小时交易数据统计
  181. getTxData() {
  182. this.txData = txData;
  183. },
  184. // 初始化数据结构
  185. dataInit(data, type) {
  186. let items;
  187. if (type == 1) {
  188. items = data.map(function(item) {
  189. return item[0];
  190. });
  191. }
  192. if (type == 2) {
  193. items = data.map(function(item) {
  194. // console.log(
  195. // `[${+item[1]},${+item[2]},${+item[3]},${+item[4]},${+item[5]}, ${+item[1] > +item[2] ? 1 : -1}]`,
  196. // '数据结果');
  197. return [+item[1], +item[4], +item[3], +item[2], +item[5]];
  198. });
  199. }
  200. if (type == 3) {
  201. items = data.map(function(item, index) {
  202. // console.log(`[${index},${+item[1]},${+item[2]},${+item[3]},${+item[4]},${+item[5]}, ${+item[1] > +item[2] ? 1 : -1}]`,'数据结果');
  203. return [index, +item[5], +item[1] > +item[4] ? 1 : -1];
  204. });
  205. }
  206. return items
  207. },
  208. // 初始化时间
  209. initDay(time, fmt) {
  210. let ret;
  211. const opt = {
  212. "Y+": time.getFullYear().toString(), //年
  213. "m+": (time.getMonth() + 1).toString(), //月
  214. "d+": time.getDate().toString(), //日
  215. "H+": time.getHours().toString(), //小时
  216. "M+": time.getMinutes().toString(), //分
  217. "S+": time.getSeconds().toString() //秒
  218. };
  219. for (let k in opt) {
  220. ret = new RegExp("(" + k + ")").exec(fmt)
  221. if (ret) {
  222. fmt = fmt.replace(ret[1], (ret[1].length == 1) ? (opt[k]) : (opt[k].padStart(ret[1].length,
  223. "0")));
  224. }
  225. }
  226. return fmt;
  227. },
  228. // 获取k线数据,生成k线
  229. getKline(time) {
  230. console.log('qq');
  231. const that = this;
  232. // const tiemt = (new Date()).getTime() - (1000*60*60*24*6);
  233. // console.log(tiemt,'k闲时间')
  234. axiosGet('/index/history', {
  235. // axiosGet('/api/v5/market/history-candles', {
  236. after: time,
  237. instId: that.typeId,
  238. bar: that.current,
  239. }).then((res) => {
  240. // 保存初始返回res对象
  241. that.oldDataKLine = res[res.length-1][0];
  242. // console.log(that.initDay(new Date(+that.oldDataKLine), "YYYY-mm-dd HH:MM:SS"))
  243. // console.log(that.initDay(new Date(+res[0][0]), "YYYY-mm-dd HH:MM:SS"))
  244. const ar = res.map((e) => {
  245. let dateTime = new Date(+e[0]);
  246. e[0] = that.initDay(dateTime, "YYYY-mm-dd HH:MM:SS");
  247. return e
  248. }).reverse()
  249. that.dataKLine.dates.unshift(...that.dataInit(ar, 1))
  250. that.dataKLine.data.unshift(...that.dataInit(ar, 2))
  251. that.dataKLine.volumes.unshift(...that.dataInit(ar, 3))
  252. // that.dataKLine = {
  253. // dates: that.dataInit(ar, 1),
  254. // data: that.dataInit(ar, 2),
  255. // volumes: that.dataInit(ar, 3),
  256. // }
  257. that.setKline()
  258. }).catch((e) => {
  259. console.log(e, '2222');
  260. })
  261. },
  262. // 设置线条数据
  263. setKline() {
  264. const that = this;
  265. var dataMA5 = that.calculateMA(5, that.dataKLine.data);
  266. var dataMA10 = that.calculateMA(10, that.dataKLine.data);
  267. var dataMA30 = that.calculateMA(30, that.dataKLine.data);
  268. var volumeMA5 = that.calculateMA(5, that.dataKLine.volumes);
  269. var volumeMA10 = that.calculateMA(10, that.dataKLine.volumes);
  270. myChart.setOption({
  271. xAxis: [{
  272. data: that.dataKLine.dates
  273. },
  274. {
  275. data: that.dataKLine.dates
  276. },
  277. ],
  278. series: [{
  279. name: '日K',
  280. data: that.dataKLine.data
  281. },
  282. {
  283. name: 'MA5',
  284. data: dataMA5
  285. },
  286. {
  287. name: 'MA10',
  288. data: dataMA10
  289. },
  290. {
  291. name: 'MA30',
  292. data: dataMA30
  293. },
  294. {
  295. name: 'Volume',
  296. data: that.dataKLine.volumes
  297. },
  298. {
  299. name: 'VolumeMA5',
  300. data: volumeMA5
  301. },
  302. {
  303. name: 'VolumeMA10',
  304. data: volumeMA10
  305. },
  306. ]
  307. })
  308. },
  309. // 列表条数不足补全
  310. addItem(list, type) {
  311. // type: 1开头加,2末尾加
  312. list = list || [];
  313. let len = 20 - list.length;
  314. if (len > 0) {
  315. for (let i = 0; i < len; i++) {
  316. if (type == 1) {
  317. list.unshift({})
  318. } else {
  319. list.push({})
  320. }
  321. }
  322. }
  323. return list;
  324. },
  325. // 获取深度数据
  326. // getDepth() {
  327. // this.buyList = this.addItem(depthList().buyList || []);
  328. // this.sellList = this.addItem(depthList().sellList || []);
  329. // },
  330. // 获取成交记录
  331. getDealHis() {
  332. const that = this;
  333. axiosGet('/index/deal', {
  334. // axiosGet('/api/v5/market/trades', {
  335. instId: that.typeId,
  336. limit: 150
  337. }).then((res) => {
  338. // 处理返回数据
  339. this.dealHis = res.map((e) => {
  340. const dateTime = new Date(+e.ts)
  341. return {
  342. "date": that.initDay(dateTime, "mm-dd HH:MM:SS"),
  343. // 1买入 2卖出
  344. "takerFlag": e.side == 'buy' ? "1" : '2',
  345. "price": e.px,
  346. "amount": e.sz
  347. }
  348. })
  349. }).catch((e) => {
  350. console.log("e: " + JSON.stringify(e));
  351. console.log(e);
  352. })
  353. },
  354. // 获取项目简介信息
  355. getTokenInfo() {
  356. this.tokenInfo = tokenInfo;
  357. },
  358. // 切换tab
  359. switchTab(val) {
  360. const that = this;
  361. if (that.current == val) {
  362. return
  363. };
  364. that.current = val;
  365. that.webSocket.close()
  366. },
  367. // 切换类目
  368. switchCategory(val) {
  369. if (this.category == val) return;
  370. this.category = val;
  371. if (this.category == 1) {
  372. this.getDepth()
  373. } else if (this.category == 2) {
  374. this.getDealHis()
  375. } else {
  376. this.getTokenInfo()
  377. }
  378. },
  379. // 截取数字字符串 保留precision小数
  380. formatterNum(value, precision) {
  381. // console.log(value)
  382. let reg = new RegExp('^\\d+(?:\\.\\d{0,' + precision + '})?')
  383. // return value.toString().match(reg)
  384. return value.toString()
  385. },
  386. // 计算MA
  387. calculateMA(dayCount, data) {
  388. var result = [];
  389. for (var i = 0, len = data.length; i < len; i++) {
  390. if (i < dayCount) {
  391. result.push('-');
  392. continue;
  393. }
  394. var sum = 0;
  395. for (var j = 0; j < dayCount; j++) {
  396. sum += data[i - j][1];
  397. }
  398. // console.log(sum, dayCount)
  399. result.push((sum / dayCount));
  400. // result.push((sum / dayCount).toFixed(2));
  401. }
  402. return result;
  403. },
  404. // 绘制(配置项)
  405. draw() {
  406. let that = this;
  407. var upColor = '#03ad91';
  408. var downColor = '#dd345b';
  409. var colorList = ['#c23531', '#2f4554', '#61a0a8', '#d48265', '#91c7ae', '#749f83', '#ca8622',
  410. '#bda29a', '#6e7074',
  411. '#546570', '#c4ccd3'
  412. ];
  413. var labelFont = 'bold 12px Sans-serif';
  414. var option = {
  415. backgroundColor: '#0d1723',
  416. title: {
  417. show: false
  418. },
  419. legend: {
  420. show: false
  421. },
  422. visualMap: {
  423. show: false,
  424. seriesIndex: 4,
  425. dimension: 2,
  426. pieces: [{
  427. value: 1,
  428. color: downColor
  429. }, {
  430. value: -1,
  431. color: upColor
  432. }]
  433. },
  434. grid: [{
  435. top: '5%',
  436. left: 20,
  437. right: 20,
  438. height: '70%'
  439. },
  440. {
  441. top: '80%',
  442. left: 20,
  443. right: 20,
  444. height: '16%'
  445. },
  446. ],
  447. axisPointer: { //坐标轴指示器配置项
  448. link: {
  449. xAxisIndex: 'all'
  450. },
  451. label: {
  452. backgroundColor: '#0d1723',
  453. color: '#fff',
  454. borderColor: 'rgb(99, 117, 139)',
  455. borderWidth: 1,
  456. borderRadius: 2,
  457. fontSize: 10
  458. }
  459. },
  460. xAxis: [{
  461. type: 'category', //坐标轴类型。(value:数值轴,适用于连续数据。,category:类目轴,适用于离散的类目数据,time: 时间轴,适用于连续的时序数据,log:对数轴。适用于对数数据)
  462. data: [], //类目数据,在类目轴(type: 'category')中有效。
  463. scale: true,
  464. boundaryGap: false, //坐标轴两边留白策略,类目轴和非类目轴的设置和表现不一样。
  465. axisLine: {
  466. show: false
  467. }, //坐标轴轴线相关设置
  468. axisTick: {
  469. show: false
  470. }, //坐标轴刻度相关设置。
  471. axisLabel: {
  472. show: false,
  473. }, //坐标轴刻度标签的相关设置。
  474. splitLine: {
  475. show: false,
  476. lineStyle: {
  477. color: 'rgba(255,255,255, 0.1)'
  478. }
  479. }, //坐标轴在 grid 区域中的分隔线。
  480. min: 'dataMin', //坐标轴刻度最小值。可以设置成特殊值 'dataMin',此时取数据在该轴上的最小值作为最小刻度。
  481. max: 'dataMax', //坐标轴刻度最大值。可以设置成特殊值 'dataMax',此时取数据在该轴上的最大值作为最大刻度。
  482. axisPointer: {
  483. label: {
  484. margin: 200
  485. }
  486. },
  487. }, {
  488. type: 'category',
  489. gridIndex: 1, //x 轴所在的 grid 的索引,默认位于第一个 grid。
  490. data: [], //类目数据,在类目轴(type: 'category')中有效。
  491. scale: true,
  492. boundaryGap: false, //坐标轴两边留白策略,类目轴和非类目轴的设置和表现不一样。
  493. axisLine: {
  494. show: false,
  495. lineStyle: {
  496. color: 'rgba(255,255,255,1)',
  497. width: 1
  498. }
  499. }, //坐标轴轴线相关设置
  500. axisTick: {
  501. show: false
  502. }, //坐标轴刻度相关设置。
  503. axisLabel: { //坐标轴刻度标签的相关设置。
  504. show: true,
  505. margin: 6,
  506. fontSize: 10,
  507. color: 'rgba(99, 117, 139, 1.0)',
  508. formatter: function(value) {
  509. // console.log(value,'mmdd');
  510. return echarts.format.formatTime('MM-dd', value);
  511. }
  512. },
  513. splitNumber: 20,
  514. splitLine: {
  515. show: false,
  516. lineStyle: {
  517. color: 'rgba(255,255,255, 0.1)'
  518. }
  519. }, //坐标轴在 grid 区域中的分隔线。
  520. min: 'dataMin', //坐标轴刻度最小值。可以设置成特殊值 'dataMin',此时取数据在该轴上的最小值作为最小刻度。
  521. max: 'dataMax', //坐标轴刻度最大值。可以设置成特殊值 'dataMax',此时取数据在该轴上的最大值作为最大刻度。
  522. // axisPointer: { show: true, type: 'none', label: { show: false }},
  523. }],
  524. yAxis: [{
  525. type: 'value', //坐标轴类型。(value:数值轴,适用于连续数据。,category:类目轴,适用于离散的类目数据,time: 时间轴,适用于连续的时序数据,log:对数轴。适用于对数数据)
  526. position: 'right', //y 轴的位置。'left','right'
  527. scale: true, //是否是脱离 0 值比例。设置成 true 后坐标刻度不会强制包含零刻度。在双数值轴的散点图中比较有用。(在设置 min 和 max 之后该配置项无效。)
  528. axisLine: {
  529. show: true
  530. }, //坐标轴轴线相关设置。
  531. axisTick: {
  532. show: true,
  533. inside: true
  534. }, //坐标轴刻度相关设置。
  535. axisLabel: { //坐标轴刻度标签的相关设置。
  536. show: true,
  537. color: 'rgba(99, 117, 139, 1.0)',
  538. inside: true,
  539. fontSize: 10,
  540. formatter: function(value) {
  541. return Number(value)
  542. // return Number(value).toFixed(2)
  543. }
  544. },
  545. splitLine: {
  546. show: false,
  547. lineStyle: {
  548. color: 'rgba(255,255,255, 0.1)'
  549. }
  550. }, //坐标轴在 grid 区域中的分隔线。
  551. }, {
  552. type: 'value',
  553. position: 'right',
  554. scale: true,
  555. gridIndex: 1,
  556. axisLine: {
  557. show: false
  558. },
  559. axisTick: {
  560. show: false
  561. },
  562. axisLabel: {
  563. show: false
  564. },
  565. splitLine: {
  566. show: false
  567. }
  568. }],
  569. animation: false, //是否开启动画。
  570. color: colorList,
  571. tooltip: {
  572. show: true, //是否显示提示框组件,包括提示框浮层和 axisPointer。
  573. trigger: 'axis', //触发类型。item,axis,none
  574. formatter(params) {
  575. console.log("params: " + JSON.stringify(params));
  576. let tooltip = '';
  577. let time = '',
  578. open = 0,
  579. high = 0,
  580. low = 0,
  581. close = 0,
  582. amount = 0;
  583. for (var i = 0; i < params.length; i++) {
  584. if (params[i].seriesName === '日K') {
  585. time = params[i].name;
  586. open = params[i].data.length > 1 ? Number(that.formatterNum(params[i].data[
  587. 1], 2)) : 0;
  588. close = params[i].data.length > 1 ? Number(that.formatterNum(params[i].data[
  589. 2], 2)) : 0;
  590. low = params[i].data.length > 1 ? Number(that.formatterNum(params[i].data[
  591. 3], 2)) : 0;
  592. high = params[i].data.length > 1 ? Number(that.formatterNum(params[i].data[
  593. 4], 2)) : 0;
  594. amount = params[i].data.length > 1 ? Number(that.formatterNum(params[i]
  595. .data[5], 2)) : 0;
  596. // console.log(time,open,close,low,high,amount)
  597. tooltip = '<div class="charts-tooltip">' +
  598. '<div class="charts-tooltip-row"><div class="ctr-label">' + '时间' +
  599. '</div><div class="ctr-value">' + time + '</div></div>' +
  600. '<div class="charts-tooltip-row"><div class="ctr-label">' + '开' +
  601. '</div><div class="ctr-value">' + open + '</div></div>' +
  602. '<div class="charts-tooltip-row"><div class="ctr-label">' + '高' +
  603. '</div><div class="ctr-value">' + high + '</div></div>' +
  604. '<div class="charts-tooltip-row"><div class="ctr-label">' + '低' +
  605. '</div><div class="ctr-value">' + low + '</div></div>' +
  606. '<div class="charts-tooltip-row"><div class="ctr-label">' + '收' +
  607. '</div><div class="ctr-value">' + close + '</div></div>' +
  608. '<div class="charts-tooltip-row"><div class="ctr-label">' + '数量' +
  609. '</div><div class="ctr-value">' + amount + '</div></div></div>';
  610. }
  611. if (params[i].seriesName === 'MA5') {
  612. that.MA5 = params[i].data !== 'NAN' ? Number(that.formatterNum(params[i]
  613. .data, 2)) : 0
  614. }
  615. if (params[i].seriesName === 'MA10') {
  616. that.MA10 = params[i].data !== 'NAN' ? Number(that.formatterNum(params[i]
  617. .data, 2)) : 0
  618. }
  619. if (params[i].seriesName === 'MA30') {
  620. that.MA30 = params[i].data !== 'NAN' ? Number(that.formatterNum(params[i]
  621. .data, 2)) : 0
  622. }
  623. if (params[i].seriesName === 'VolumeMA5') {
  624. that.volMA5 = params[i].data !== 'NAN' ? Number(that.formatterNum(params[i]
  625. .data, 2)) : 0
  626. }
  627. if (params[i].seriesName === 'VolumeMA10') {
  628. that.volMA10 = params[i].data !== 'NAN' ? Number(that.formatterNum(params[i]
  629. .data, 2)) : 0
  630. }
  631. }
  632. return tooltip;
  633. },
  634. triggerOn: 'click', //提示框触发的条件 'mousemove','click','mousemove|click','none'
  635. textStyle: {
  636. fontSize: 10
  637. }, //提示框浮层的文本样式
  638. backgroundColor: 'rgba(30,42,66,0.8);', //提示框浮层的背景颜色。
  639. borderColor: '#2f3a56', //提示框浮层的边框颜色。
  640. borderWidth: 2,
  641. position: function(pos, params, el, elRect, size) { //提示框浮层的位置,默认不设置时位置会跟随鼠标的位置。
  642. var obj = {
  643. top: 20
  644. };
  645. obj[['left', 'right'][+(pos[0] < size.viewSize[0] / 2)]] = 10;
  646. return obj;
  647. },
  648. axisPointer: { //坐标轴指示器配置项。
  649. label: {
  650. color: 'rgba(255,255,255,.87)',
  651. fontSize: 9,
  652. backgroundColor: '#020204',
  653. borderColor: "#9c9fa4",
  654. shadowBlur: 0,
  655. borderWidth: 0.5,
  656. padding: [4, 2, 3, 2],
  657. },
  658. animation: false,
  659. type: 'cross',
  660. lineStyle: {
  661. color: {
  662. type: 'linear',
  663. x: 0,
  664. y: 0,
  665. x2: 0,
  666. y2: 1,
  667. colorStops: [{
  668. offset: 0,
  669. color: 'rgba(30, 42, 66, 0.1)' // 0% 处的颜色
  670. }, {
  671. offset: 0.7,
  672. color: 'rgba(30, 42, 66,0.9)' // 100% 处的颜色
  673. }, {
  674. offset: 1,
  675. color: 'rgba(30, 42, 66,0.2)' // 100% 处的颜色
  676. }]
  677. },
  678. width: 10,
  679. shadowColor: 'rgba(30, 42, 66,0.7)',
  680. shadowBlur: 0,
  681. shadowOffsetY: 68,
  682. }
  683. }
  684. },
  685. dataZoom: [{ //用于区域缩放
  686. type: 'inside',
  687. xAxisIndex: [0, 1],
  688. realtime: false,
  689. start: 50,
  690. end: 100,
  691. }],
  692. series: [{
  693. type: 'candlestick',
  694. name: '日K',
  695. data: [],
  696. itemStyle: {
  697. color: upColor,
  698. color0: downColor,
  699. borderColor: upColor,
  700. borderColor0: downColor
  701. },
  702. markPoint: {
  703. symbol: 'rect',
  704. symbolSize: [-10, 0.5],
  705. symbolOffset: [-5, 0],
  706. itemStyle: {
  707. color: 'rgba(255,255,255,.87)'
  708. },
  709. label: {
  710. color: 'rgba(255,255,255,.87)',
  711. offset: [3, 0],
  712. fontSize: 10,
  713. position: "left",
  714. align: 'right',
  715. formatter: function(params) {
  716. // console.log(params.value,'传入的处理数值');
  717. // return Number(params.value).toFixed(2)
  718. return Number(params.value)
  719. }
  720. },
  721. data: [{
  722. name: 'max',
  723. type: 'max',
  724. valueDim: 'highest'
  725. },
  726. {
  727. name: 'min',
  728. type: 'min',
  729. valueDim: 'lowest'
  730. }
  731. ]
  732. },
  733. },
  734. {
  735. name: 'MA5',
  736. type: 'line',
  737. data: [],
  738. symbol: 'none', //去除圆点
  739. smooth: true,
  740. lineStyle: {
  741. normal: {
  742. opacity: 1,
  743. width: 1,
  744. color: "#eef4ba"
  745. }
  746. },
  747. z: 5
  748. },
  749. {
  750. name: 'MA10',
  751. type: 'line',
  752. data: [],
  753. symbol: 'none', //去除圆点
  754. smooth: true,
  755. lineStyle: {
  756. normal: {
  757. opacity: 1,
  758. width: 1,
  759. color: '#83c1c5'
  760. }
  761. },
  762. z: 4
  763. },
  764. {
  765. name: 'MA30',
  766. type: 'line',
  767. data: [],
  768. symbol: 'none', //去除圆点
  769. smooth: true,
  770. lineStyle: {
  771. normal: {
  772. opacity: 1,
  773. width: 1,
  774. color: '#b39cd8'
  775. }
  776. },
  777. z: 3
  778. },
  779. {
  780. name: 'Volume',
  781. type: 'bar',
  782. xAxisIndex: 1,
  783. yAxisIndex: 1,
  784. data: []
  785. },
  786. {
  787. name: 'VolumeMA5',
  788. type: 'line',
  789. xAxisIndex: 1,
  790. yAxisIndex: 1,
  791. data: [],
  792. symbol: 'none', //去除圆点
  793. smooth: true,
  794. lineStyle: {
  795. normal: {
  796. opacity: 1,
  797. width: 1,
  798. color: "#eef4ba"
  799. }
  800. },
  801. z: 5
  802. },
  803. {
  804. name: 'VolumeMA10',
  805. type: 'line',
  806. xAxisIndex: 1,
  807. yAxisIndex: 1,
  808. data: [],
  809. symbol: 'none', //去除圆点
  810. smooth: true,
  811. lineStyle: {
  812. normal: {
  813. opacity: 1,
  814. width: 1,
  815. color: '#83c1c5'
  816. }
  817. },
  818. z: 4
  819. },
  820. ]
  821. };
  822. myChart.setOption(option);
  823. // 加载上一页数据
  824. myChart.on('datazoom', function(params) {
  825. let num = params.batch[0]['start'];
  826. if (num == 0) {
  827. console.log('到最左边了')
  828. // console.log(that.initDay(new Date(+that.oldDataKLine), "YYYY-mm-dd HH:MM:SS"));
  829. // that.getKline(that.oldDataKLine)
  830. }
  831. })
  832. window.addEventListener('resize', () => {
  833. myChart.resize()
  834. })
  835. }
  836. }
  837. })