var myChart; // post请求封装 // function post(url,data) { // let baseUrl='http://192.168.3.135:8080'; // return new Promise((resolve,reject)=>{ // axios({ // headers:{ // "Content-Type": "application/x-www-form-urlencoded", // }, // method:'post', // url:baseUrl+url, // data:Qs.stringify( data || {}) // }) // .then(res=>{ // console.log(res) // if(res.data.code==1){ // resolve(res.data) // }else{ // reject() // alertError('请求超时') // } // }) // .catch(err=>{ // alertError('请求超时') // }) // }) // } // 弹窗 function alertError(title) { document.addEventListener('plusready',function() { console.log('......') }) try{ plus.nativeUI.toast(title, { icon:'/static/common/toast-error.png', style:'inline', verticalAlign:'top' }); }catch(e){ //TODO handle the exception } } var app = new Vue({ el:'#app', data:{ MA5:'', MA10:'', MA30:'', volMA5:'', volMA10:'', current:1, tabs:[ {'label':'1分钟','value':1}, {'label':'15分钟','value':2}, {'label':'30分钟','value':3}, {'label':'1小时','value':4}, {'label':'4小时','value':5}, {'label':'1天','value':6}, ], category:1, categoryList:[ {'label':'深度','value':1}, {'label':'成交','value':2}, {'label':'简介','value':3}, ], txData:{},//交易数据统计 buyList:[], sellList:[], dealHis:[], tokenInfo:{}, page:1, }, created() { this.getTxData() this.getDepth() }, mounted() { myChart = echarts.init(document.getElementById('main')); this.draw() this.getKline() }, methods:{ // 返回上一页 back(){ uni.navigateBack() }, // 获取24小时交易数据统计 getTxData(){ this.txData=txData; }, // 获取k线数据,生成k线 getKline(){ var dataMA5 = this.calculateMA(5, data); var dataMA10 = this.calculateMA(10, data); var dataMA30 = this.calculateMA(30, data); var volumeMA5 = this.calculateMA(5, volumes); var volumeMA10 = this.calculateMA(10, volumes); myChart.setOption({ xAxis: [ { data: dates }, { data: dates }, ], series: [ { name: '日K', data: data }, { name: 'MA5', data: dataMA5 }, { name: 'MA10', data: dataMA10 }, { name: 'MA30', data: dataMA30 }, { name: 'Volume', data: volumes }, { name: 'VolumeMA5', data: volumeMA5 }, { name: 'VolumeMA10', data: volumeMA10 }, ] }) }, // 列表条数不足补全 addItem(list,type){ // type: 1开头加,2末尾加 list=list || []; let len=20-list.length; if(len>0){ for(let i=0;i 1 ? Number(that.formatterNum(params[i].data[1], 2)) : 0; close = params[i].data.length > 1 ? Number(that.formatterNum(params[i].data[2], 2)) : 0; low = params[i].data.length > 1 ? Number(that.formatterNum(params[i].data[3], 2)) : 0; high = params[i].data.length > 1 ? Number(that.formatterNum(params[i].data[4], 2)) : 0; amount = params[i].data.length > 1 ? Number(that.formatterNum(params[i].data[5], 2)) : 0; // console.log(time,open,close,low,high,amount) tooltip = '
' + '
' + '时间' + '
' + time + '
' + '
' + '开' + '
' + open + '
' + '
' + '高' + '
' + high + '
' + '
' + '低' + '
' + low + '
' + '
' + '收' + '
' + close + '
' + '
' + '数量' + '
' +amount + '
'; } if (params[i].seriesName === 'MA5') { that.MA5 = params[i].data !== 'NAN' ? Number(that.formatterNum(params[i].data, 2)) : 0 } if (params[i].seriesName === 'MA10') { that.MA10 = params[i].data !== 'NAN' ? Number(that.formatterNum(params[i].data, 2)) : 0 } if (params[i].seriesName === 'MA30') { that.MA30 = params[i].data !== 'NAN' ? Number(that.formatterNum(params[i].data, 2)) : 0 } if (params[i].seriesName === 'VolumeMA5') { that.volMA5 = params[i].data !== 'NAN' ? Number(that.formatterNum(params[i].data, 2)) : 0 } if (params[i].seriesName === 'VolumeMA10') { that.volMA10 = params[i].data !== 'NAN' ? Number(that.formatterNum(params[i].data, 2)) : 0 } } return tooltip; }, triggerOn: 'click', //提示框触发的条件 'mousemove','click','mousemove|click','none' textStyle: { fontSize: 10 }, //提示框浮层的文本样式 backgroundColor: 'rgba(30,42,66,0.8);', //提示框浮层的背景颜色。 borderColor: '#2f3a56', //提示框浮层的边框颜色。 borderWidth:2, position: function(pos, params, el, elRect, size) { //提示框浮层的位置,默认不设置时位置会跟随鼠标的位置。 var obj = { top: 20 }; obj[['left', 'right'][+(pos[0] < size.viewSize[0] / 2)]] = 10; return obj; }, axisPointer: { //坐标轴指示器配置项。 label: { color: 'rgba(255,255,255,.87)', fontSize: 9, backgroundColor: '#020204', borderColor: "#9c9fa4", shadowBlur: 0, borderWidth: 0.5, padding: [4, 2, 3, 2], }, animation: false, type: 'cross', lineStyle: { color: { type: 'linear', x: 0, y: 0, x2: 0, y2: 1, colorStops: [{ offset: 0, color: 'rgba(30, 42, 66, 0.1)' // 0% 处的颜色 }, { offset: 0.7, color: 'rgba(30, 42, 66,0.9)' // 100% 处的颜色 }, { offset: 1, color: 'rgba(30, 42, 66,0.2)' // 100% 处的颜色 }] }, width: 10, shadowColor: 'rgba(30, 42, 66,0.7)', shadowBlur: 0, shadowOffsetY: 68, } } }, dataZoom: [{ //用于区域缩放 type: 'inside', xAxisIndex: [0, 1], realtime: false, start: 50, end: 100, } ], series: [ { type: 'candlestick', name: '日K', data: [], itemStyle: { color: upColor, color0: downColor, borderColor: upColor, borderColor0: downColor }, markPoint: { symbol: 'rect', symbolSize: [-10, 0.5], symbolOffset: [5, 0], itemStyle: { color: 'rgba(255,255,255,.87)' }, label: { color: 'rgba(255,255,255,.87)', offset: [10, 0], fontSize: 10, align: 'left', formatter: function(params) { return Number(params.value).toFixed(2) } }, data: [{ name: 'max', type: 'max', valueDim: 'highest' }, { name: 'min', type: 'min', valueDim: 'lowest' } ] }, }, { name: 'MA5', type: 'line', data: [], symbol: 'none',//去除圆点 smooth: true, lineStyle: { normal: { opacity: 1, width: 1, color: "#eef4ba" } }, z: 5 }, { name: 'MA10', type: 'line', data: [], symbol: 'none',//去除圆点 smooth: true, lineStyle: { normal: { opacity: 1, width: 1, color: '#83c1c5' } }, z: 4 }, { name: 'MA30', type: 'line', data: [], symbol: 'none',//去除圆点 smooth: true, lineStyle: { normal: { opacity: 1, width: 1, color: '#b39cd8' } }, z: 3 }, { name: 'Volume', type: 'bar', xAxisIndex: 1, yAxisIndex: 1, data: [] }, { name: 'VolumeMA5', type: 'line', xAxisIndex: 1, yAxisIndex: 1, data: [], symbol: 'none',//去除圆点 smooth: true, lineStyle: { normal: { opacity: 1, width: 1, color: "#eef4ba" } }, z: 5 }, { name: 'VolumeMA10', type: 'line', xAxisIndex: 1, yAxisIndex: 1, data: [], symbol: 'none',//去除圆点 smooth: true, lineStyle: { normal: { opacity: 1, width: 1, color: '#83c1c5' } }, z: 4 }, ] }; myChart.setOption(option); // 加载上一页数据 myChart.on('datazoom',function(params){ let num=params.batch[0]['start']; if(num==0){ console.log('到最左边了') } }) window.addEventListener('resize', () => { myChart.resize()}) } } })