|
|
@@ -5,12 +5,18 @@ var host = app.globalData.host;
|
|
|
Page({
|
|
|
data: {
|
|
|
ec: {
|
|
|
- onInit: initChart
|
|
|
+ // onInit: initChart
|
|
|
+ lazyLoad: true
|
|
|
},
|
|
|
+ timer: '',
|
|
|
datas:{},
|
|
|
userInfo:{}
|
|
|
+ },
|
|
|
+ onReady: function () { //这一步是一定要注意的
|
|
|
+
|
|
|
},
|
|
|
onLoad(){
|
|
|
+
|
|
|
wx.showNavigationBarLoading()
|
|
|
/**获取token */
|
|
|
wx.getStorage({
|
|
|
@@ -47,6 +53,7 @@ Page({
|
|
|
}
|
|
|
},
|
|
|
getData(){
|
|
|
+ this.oneComponent = this.selectComponent('#mychart');
|
|
|
wx.request({
|
|
|
url: host + '/api/wx/index',
|
|
|
header: {
|
|
|
@@ -58,6 +65,16 @@ Page({
|
|
|
datas: res.data.data
|
|
|
})
|
|
|
wx.hideNavigationBarLoading()
|
|
|
+ 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])
|
|
|
+ ydata.push(records[i].today_fund)
|
|
|
+ }
|
|
|
+ xdata = xdata.reverse()
|
|
|
+ ydata = ydata.reverse()
|
|
|
+ this.init_one(xdata, ydata)
|
|
|
+
|
|
|
},
|
|
|
fail: error => {
|
|
|
//跳转到登陆页面
|
|
|
@@ -67,7 +84,16 @@ Page({
|
|
|
}
|
|
|
})
|
|
|
},
|
|
|
- onReady() {
|
|
|
+ init_one: function (xdata, ydata) { //初始化第一个图表
|
|
|
+ this.oneComponent.init((canvas, width, height) => {
|
|
|
+ const chart = echarts.init(canvas, null, {
|
|
|
+ width: width,
|
|
|
+ height: height
|
|
|
+ });
|
|
|
+ setOption(chart, xdata, ydata)
|
|
|
+ this.chart = chart;
|
|
|
+ return chart;
|
|
|
+ });
|
|
|
},
|
|
|
});
|
|
|
|
|
|
@@ -160,3 +186,60 @@ function initChart(canvas, width, height, dpr) {
|
|
|
|
|
|
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+function setOption(chart, xdata, ydata) {
|
|
|
+ var option = {
|
|
|
+ legend: {
|
|
|
+ show: false
|
|
|
+ },
|
|
|
+ grid: {
|
|
|
+ x: 35,
|
|
|
+ y: 40,
|
|
|
+ x2: 10,
|
|
|
+ y2: 35
|
|
|
+ },
|
|
|
+ tooltip: {
|
|
|
+ show: true,
|
|
|
+ trigger: 'axis'
|
|
|
+ },
|
|
|
+ xAxis: {
|
|
|
+ type: 'category',
|
|
|
+ data: xdata,
|
|
|
+ axisLabel: {
|
|
|
+ interval: 0,
|
|
|
+ rotate: 40,
|
|
|
+ color: '#999999'
|
|
|
+ }
|
|
|
+ },
|
|
|
+ yAxis: {
|
|
|
+ axisLine: {
|
|
|
+ show: true
|
|
|
+ },
|
|
|
+ type: 'value',
|
|
|
+ name: '收益曲线',
|
|
|
+ },
|
|
|
+ series: [{
|
|
|
+ name: 'A',
|
|
|
+ type: 'line',
|
|
|
+ smooth: true,
|
|
|
+ symbolSize: 8,
|
|
|
+ lineStyle: {
|
|
|
+ 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)
|
|
|
+}
|