kline.js 22 KB

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