kline.js 20 KB

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