123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177 |
- import * as echarts from '../../ec-canvas/echarts';
- const app = getApp();
- var host = app.globalData.host;
- var id, record_id;
- Page({
- data: {
- ec: {
- onInit: initChart
- }
- },
- onLoad(options) {
- id = options.id, record_id = options.record_id
- this.setData({
- id:id,
- record_id: record_id
- })
- wx.showNavigationBarLoading()
- /**获取token */
- wx.getStorage({
- key: 'userInfo',
- success: res => {
- this.setData({
- userInfo: res.data
- })
- this.getData(id, record_id);
- },
- fail: error => {
- //跳转到登陆页面
- wx.switchTab({
- url: '../user/user',
- })
- }
- })
- },
- getData(id, record_id) {
- var data={}
- if(id){
- data.id=id
- }
- if (record_id) {
- data.record_id = record_id
- }
- wx.request({
- url: host + '/api/wx/player/match',
- data: data,
- header: {
- 'Authorization': this.data.userInfo.token
- },
- success: res => {
- console.log(res)
- this.setData({
- datas: res.data.data
- })
- wx.hideNavigationBarLoading()
- },
- fail: error => {
- //跳转到登陆页面
- wx.switchTab({
- url: '../user/user',
- })
- }
- })
- },
- });
- /**折线图 */
- function initChart(canvas, width, height, dpr) {
- var data = {}
- if (id) {
- data.id = id
- }
- if (record_id) {
- data.record_id = record_id
- }
- wx.getStorage({
- key: 'userInfo',
- success: res => {
- var info = res.data
- wx.request({
- url: host + '/api/wx/player/match',
- data: data,
- header: {
- 'Authorization': info.token
- },
- success: res => {
- var records = res.data.data.records, xdata = [], ydata = [];
- for (let i = 0; i < records.length; i++) {
- let date = records[i].stock_date.split('-');
- xdata.push(date[1] + '/' + date[2])
- let y = records[i].total_income.replace('%', '')
- ydata.push(Number(y))
- }
- xdata = xdata.reverse()
- ydata = ydata.reverse()
- const chart = echarts.init(canvas, null, {
- width: width,
- height: height,
- devicePixelRatio: dpr // new
- });
- canvas.setChart(chart);
- var option = {
- legend: {
- show: false
- },
- grid: {
- x: 50,
- y: 40,
- x2: 10,
- y2: 35
- },
- tooltip: {
- show: true,
- trigger: 'axis',
- formatter: '{b0}: {c0}%'
- },
- xAxis: {
- type: 'category',
- data: xdata,
- axisLabel: {
- interval: 0,
- rotate: 40,
- color: '#999999',
- interval:2
- }
- },
- yAxis: {
- axisLine: {
- show: true
- },
- type: 'value',
- name: '收益曲线',
- axisLabel: {
- formatter: function (value, index) {//隐藏 0
- let texts = [];
- texts.push(value + '%')
- return texts;
- },
- show: true
- },
- },
- series: [{
- name: 'A',
- type: 'line',
- smooth: true,
- symbolSize: 8,
- lineStyle: {
- color: '#FF2D68'
- // color: new echarts.graphic.LinearGradient(1, 0, 0, 0, [{
- // offset: 0,
- // color: '#FF2D68'
- // }, {
- // offset: 1,
- // color: '#4C4BFF'
- // }]),
- },
- itemStyle: {
- borderWidth: 5,
- borderColor: '#FFAD52',
- color: '#FFAD52'
- },
- data: ydata
- }]
- };
- chart.setOption(option);
- return chart;
- }
- })
- },
- })
- }
|