kline.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833
  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: 100
  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. },
  378. // 计算MA
  379. calculateMA(dayCount, data) {
  380. var result = [];
  381. for (var i = 0, len = data.length; i < len; i++) {
  382. if (i < dayCount) {
  383. result.push('-');
  384. continue;
  385. }
  386. var sum = 0;
  387. for (var j = 0; j < dayCount; j++) {
  388. sum += data[i - j][1];
  389. }
  390. // console.log(sum, dayCount)
  391. result.push((sum / dayCount).toFixed(2));
  392. }
  393. return result;
  394. },
  395. // 绘制(配置项)
  396. draw() {
  397. let that = this;
  398. var upColor = '#03ad91';
  399. var downColor = '#dd345b';
  400. var colorList = ['#c23531', '#2f4554', '#61a0a8', '#d48265', '#91c7ae', '#749f83', '#ca8622',
  401. '#bda29a', '#6e7074',
  402. '#546570', '#c4ccd3'
  403. ];
  404. var labelFont = 'bold 12px Sans-serif';
  405. var option = {
  406. backgroundColor: '#0d1723',
  407. title: {
  408. show: false
  409. },
  410. legend: {
  411. show: false
  412. },
  413. visualMap: {
  414. show: false,
  415. seriesIndex: 4,
  416. dimension: 2,
  417. pieces: [{
  418. value: 1,
  419. color: downColor
  420. }, {
  421. value: -1,
  422. color: upColor
  423. }]
  424. },
  425. grid: [{
  426. top: '5%',
  427. left: 20,
  428. right: 20,
  429. height: '70%'
  430. },
  431. {
  432. top: '80%',
  433. left: 20,
  434. right: 20,
  435. height: '16%'
  436. },
  437. ],
  438. axisPointer: { //坐标轴指示器配置项
  439. link: {
  440. xAxisIndex: 'all'
  441. },
  442. label: {
  443. backgroundColor: '#0d1723',
  444. color: '#fff',
  445. borderColor: 'rgb(99, 117, 139)',
  446. borderWidth: 1,
  447. borderRadius: 2,
  448. fontSize: 10
  449. }
  450. },
  451. xAxis: [{
  452. type: 'category', //坐标轴类型。(value:数值轴,适用于连续数据。,category:类目轴,适用于离散的类目数据,time: 时间轴,适用于连续的时序数据,log:对数轴。适用于对数数据)
  453. data: [], //类目数据,在类目轴(type: 'category')中有效。
  454. scale: true,
  455. boundaryGap: false, //坐标轴两边留白策略,类目轴和非类目轴的设置和表现不一样。
  456. axisLine: {
  457. show: false
  458. }, //坐标轴轴线相关设置
  459. axisTick: {
  460. show: false
  461. }, //坐标轴刻度相关设置。
  462. axisLabel: {
  463. show: false,
  464. }, //坐标轴刻度标签的相关设置。
  465. splitLine: {
  466. show: false,
  467. lineStyle: {
  468. color: 'rgba(255,255,255, 0.1)'
  469. }
  470. }, //坐标轴在 grid 区域中的分隔线。
  471. min: 'dataMin', //坐标轴刻度最小值。可以设置成特殊值 'dataMin',此时取数据在该轴上的最小值作为最小刻度。
  472. max: 'dataMax', //坐标轴刻度最大值。可以设置成特殊值 'dataMax',此时取数据在该轴上的最大值作为最大刻度。
  473. axisPointer: {
  474. label: {
  475. margin: 200
  476. }
  477. },
  478. }, {
  479. type: 'category',
  480. gridIndex: 1, //x 轴所在的 grid 的索引,默认位于第一个 grid。
  481. data: [], //类目数据,在类目轴(type: 'category')中有效。
  482. scale: true,
  483. boundaryGap: false, //坐标轴两边留白策略,类目轴和非类目轴的设置和表现不一样。
  484. axisLine: {
  485. show: false,
  486. lineStyle: {
  487. color: 'rgba(255,255,255,1)',
  488. width: 1
  489. }
  490. }, //坐标轴轴线相关设置
  491. axisTick: {
  492. show: false
  493. }, //坐标轴刻度相关设置。
  494. axisLabel: { //坐标轴刻度标签的相关设置。
  495. show: true,
  496. margin: 6,
  497. fontSize: 10,
  498. color: 'rgba(99, 117, 139, 1.0)',
  499. formatter: function(value) {
  500. // console.log(value,'mmdd');
  501. return echarts.format.formatTime('MM-dd', value);
  502. }
  503. },
  504. splitNumber: 20,
  505. splitLine: {
  506. show: false,
  507. lineStyle: {
  508. color: 'rgba(255,255,255, 0.1)'
  509. }
  510. }, //坐标轴在 grid 区域中的分隔线。
  511. min: 'dataMin', //坐标轴刻度最小值。可以设置成特殊值 'dataMin',此时取数据在该轴上的最小值作为最小刻度。
  512. max: 'dataMax', //坐标轴刻度最大值。可以设置成特殊值 'dataMax',此时取数据在该轴上的最大值作为最大刻度。
  513. // axisPointer: { show: true, type: 'none', label: { show: false }},
  514. }],
  515. yAxis: [{
  516. type: 'value', //坐标轴类型。(value:数值轴,适用于连续数据。,category:类目轴,适用于离散的类目数据,time: 时间轴,适用于连续的时序数据,log:对数轴。适用于对数数据)
  517. position: 'right', //y 轴的位置。'left','right'
  518. scale: true, //是否是脱离 0 值比例。设置成 true 后坐标刻度不会强制包含零刻度。在双数值轴的散点图中比较有用。(在设置 min 和 max 之后该配置项无效。)
  519. axisLine: {
  520. show: true
  521. }, //坐标轴轴线相关设置。
  522. axisTick: {
  523. show: true,
  524. inside: true
  525. }, //坐标轴刻度相关设置。
  526. axisLabel: { //坐标轴刻度标签的相关设置。
  527. show: true,
  528. color: 'rgba(99, 117, 139, 1.0)',
  529. inside: true,
  530. fontSize: 10,
  531. formatter: function(value) {
  532. return Number(value).toFixed(2)
  533. }
  534. },
  535. splitLine: {
  536. show: false,
  537. lineStyle: {
  538. color: 'rgba(255,255,255, 0.1)'
  539. }
  540. }, //坐标轴在 grid 区域中的分隔线。
  541. }, {
  542. type: 'value',
  543. position: 'right',
  544. scale: true,
  545. gridIndex: 1,
  546. axisLine: {
  547. show: false
  548. },
  549. axisTick: {
  550. show: false
  551. },
  552. axisLabel: {
  553. show: false
  554. },
  555. splitLine: {
  556. show: false
  557. }
  558. }],
  559. animation: false, //是否开启动画。
  560. color: colorList,
  561. tooltip: {
  562. show: true, //是否显示提示框组件,包括提示框浮层和 axisPointer。
  563. trigger: 'axis', //触发类型。item,axis,none
  564. formatter(params) {
  565. console.log("params: " + JSON.stringify(params));
  566. let tooltip = '';
  567. let time = '',
  568. open = 0,
  569. high = 0,
  570. low = 0,
  571. close = 0,
  572. amount = 0;
  573. for (var i = 0; i < params.length; i++) {
  574. if (params[i].seriesName === '日K') {
  575. time = params[i].name;
  576. open = params[i].data.length > 1 ? Number(that.formatterNum(params[i].data[
  577. 1], 2)) : 0;
  578. close = params[i].data.length > 1 ? Number(that.formatterNum(params[i].data[
  579. 2], 2)) : 0;
  580. low = params[i].data.length > 1 ? Number(that.formatterNum(params[i].data[
  581. 3], 2)) : 0;
  582. high = params[i].data.length > 1 ? Number(that.formatterNum(params[i].data[
  583. 4], 2)) : 0;
  584. amount = params[i].data.length > 1 ? Number(that.formatterNum(params[i]
  585. .data[5], 2)) : 0;
  586. // console.log(time,open,close,low,high,amount)
  587. tooltip = '<div class="charts-tooltip">' +
  588. '<div class="charts-tooltip-row"><div class="ctr-label">' + '时间' +
  589. '</div><div class="ctr-value">' + time + '</div></div>' +
  590. '<div class="charts-tooltip-row"><div class="ctr-label">' + '开' +
  591. '</div><div class="ctr-value">' + open + '</div></div>' +
  592. '<div class="charts-tooltip-row"><div class="ctr-label">' + '高' +
  593. '</div><div class="ctr-value">' + high + '</div></div>' +
  594. '<div class="charts-tooltip-row"><div class="ctr-label">' + '低' +
  595. '</div><div class="ctr-value">' + low + '</div></div>' +
  596. '<div class="charts-tooltip-row"><div class="ctr-label">' + '收' +
  597. '</div><div class="ctr-value">' + close + '</div></div>' +
  598. '<div class="charts-tooltip-row"><div class="ctr-label">' + '数量' +
  599. '</div><div class="ctr-value">' + amount + '</div></div></div>';
  600. }
  601. if (params[i].seriesName === 'MA5') {
  602. that.MA5 = params[i].data !== 'NAN' ? Number(that.formatterNum(params[i]
  603. .data, 2)) : 0
  604. }
  605. if (params[i].seriesName === 'MA10') {
  606. that.MA10 = params[i].data !== 'NAN' ? Number(that.formatterNum(params[i]
  607. .data, 2)) : 0
  608. }
  609. if (params[i].seriesName === 'MA30') {
  610. that.MA30 = params[i].data !== 'NAN' ? Number(that.formatterNum(params[i]
  611. .data, 2)) : 0
  612. }
  613. if (params[i].seriesName === 'VolumeMA5') {
  614. that.volMA5 = params[i].data !== 'NAN' ? Number(that.formatterNum(params[i]
  615. .data, 2)) : 0
  616. }
  617. if (params[i].seriesName === 'VolumeMA10') {
  618. that.volMA10 = params[i].data !== 'NAN' ? Number(that.formatterNum(params[i]
  619. .data, 2)) : 0
  620. }
  621. }
  622. return tooltip;
  623. },
  624. triggerOn: 'click', //提示框触发的条件 'mousemove','click','mousemove|click','none'
  625. textStyle: {
  626. fontSize: 10
  627. }, //提示框浮层的文本样式
  628. backgroundColor: 'rgba(30,42,66,0.8);', //提示框浮层的背景颜色。
  629. borderColor: '#2f3a56', //提示框浮层的边框颜色。
  630. borderWidth: 2,
  631. position: function(pos, params, el, elRect, size) { //提示框浮层的位置,默认不设置时位置会跟随鼠标的位置。
  632. var obj = {
  633. top: 20
  634. };
  635. obj[['left', 'right'][+(pos[0] < size.viewSize[0] / 2)]] = 10;
  636. return obj;
  637. },
  638. axisPointer: { //坐标轴指示器配置项。
  639. label: {
  640. color: 'rgba(255,255,255,.87)',
  641. fontSize: 9,
  642. backgroundColor: '#020204',
  643. borderColor: "#9c9fa4",
  644. shadowBlur: 0,
  645. borderWidth: 0.5,
  646. padding: [4, 2, 3, 2],
  647. },
  648. animation: false,
  649. type: 'cross',
  650. lineStyle: {
  651. color: {
  652. type: 'linear',
  653. x: 0,
  654. y: 0,
  655. x2: 0,
  656. y2: 1,
  657. colorStops: [{
  658. offset: 0,
  659. color: 'rgba(30, 42, 66, 0.1)' // 0% 处的颜色
  660. }, {
  661. offset: 0.7,
  662. color: 'rgba(30, 42, 66,0.9)' // 100% 处的颜色
  663. }, {
  664. offset: 1,
  665. color: 'rgba(30, 42, 66,0.2)' // 100% 处的颜色
  666. }]
  667. },
  668. width: 10,
  669. shadowColor: 'rgba(30, 42, 66,0.7)',
  670. shadowBlur: 0,
  671. shadowOffsetY: 68,
  672. }
  673. }
  674. },
  675. dataZoom: [{ //用于区域缩放
  676. type: 'inside',
  677. xAxisIndex: [0, 1],
  678. realtime: false,
  679. start: 50,
  680. end: 100,
  681. }],
  682. series: [{
  683. type: 'candlestick',
  684. name: '日K',
  685. data: [],
  686. itemStyle: {
  687. color: upColor,
  688. color0: downColor,
  689. borderColor: upColor,
  690. borderColor0: downColor
  691. },
  692. markPoint: {
  693. symbol: 'rect',
  694. symbolSize: [-10, 0.5],
  695. symbolOffset: [5, 0],
  696. itemStyle: {
  697. color: 'rgba(255,255,255,.87)'
  698. },
  699. label: {
  700. color: 'rgba(255,255,255,.87)',
  701. offset: [10, 0],
  702. fontSize: 10,
  703. align: 'left',
  704. formatter: function(params) {
  705. return Number(params.value).toFixed(2)
  706. }
  707. },
  708. data: [{
  709. name: 'max',
  710. type: 'max',
  711. valueDim: 'highest'
  712. },
  713. {
  714. name: 'min',
  715. type: 'min',
  716. valueDim: 'lowest'
  717. }
  718. ]
  719. },
  720. },
  721. {
  722. name: 'MA5',
  723. type: 'line',
  724. data: [],
  725. symbol: 'none', //去除圆点
  726. smooth: true,
  727. lineStyle: {
  728. normal: {
  729. opacity: 1,
  730. width: 1,
  731. color: "#eef4ba"
  732. }
  733. },
  734. z: 5
  735. },
  736. {
  737. name: 'MA10',
  738. type: 'line',
  739. data: [],
  740. symbol: 'none', //去除圆点
  741. smooth: true,
  742. lineStyle: {
  743. normal: {
  744. opacity: 1,
  745. width: 1,
  746. color: '#83c1c5'
  747. }
  748. },
  749. z: 4
  750. },
  751. {
  752. name: 'MA30',
  753. type: 'line',
  754. data: [],
  755. symbol: 'none', //去除圆点
  756. smooth: true,
  757. lineStyle: {
  758. normal: {
  759. opacity: 1,
  760. width: 1,
  761. color: '#b39cd8'
  762. }
  763. },
  764. z: 3
  765. },
  766. {
  767. name: 'Volume',
  768. type: 'bar',
  769. xAxisIndex: 1,
  770. yAxisIndex: 1,
  771. data: []
  772. },
  773. {
  774. name: 'VolumeMA5',
  775. type: 'line',
  776. xAxisIndex: 1,
  777. yAxisIndex: 1,
  778. data: [],
  779. symbol: 'none', //去除圆点
  780. smooth: true,
  781. lineStyle: {
  782. normal: {
  783. opacity: 1,
  784. width: 1,
  785. color: "#eef4ba"
  786. }
  787. },
  788. z: 5
  789. },
  790. {
  791. name: 'VolumeMA10',
  792. type: 'line',
  793. xAxisIndex: 1,
  794. yAxisIndex: 1,
  795. data: [],
  796. symbol: 'none', //去除圆点
  797. smooth: true,
  798. lineStyle: {
  799. normal: {
  800. opacity: 1,
  801. width: 1,
  802. color: '#83c1c5'
  803. }
  804. },
  805. z: 4
  806. },
  807. ]
  808. };
  809. myChart.setOption(option);
  810. // 加载上一页数据
  811. myChart.on('datazoom', function(params) {
  812. let num = params.batch[0]['start'];
  813. if (num == 0) {
  814. console.log('到最左边了')
  815. }
  816. })
  817. window.addEventListener('resize', () => {
  818. myChart.resize()
  819. })
  820. }
  821. }
  822. })