kline.js 20 KB

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