kline.js 21 KB

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