鍍金池/ 問答/HTML/ 小程序使用echarts-for-weixin,怎么動態(tài)獲取數(shù)據(jù),wx,requ

小程序使用echarts-for-weixin,怎么動態(tài)獲取數(shù)據(jù),wx,request是異步的

有沒有做過的,官方的demo都是死數(shù)據(jù),動態(tài)獲取異步一直拿不到值

回答
編輯回答
深記你

import * as echarts from '../../ec-canvas/echarts';
var app = getApp();
var demo = require('../jspackage/album.js');
var dataChange = new demo();
let chart = null;
var demo2={
//設(shè)置背景色
backgroundColor: '#fff',
//設(shè)置文本樣式 默認(rèn)字和線于圖的顏色相同
textStyle: {

color: 'rgba(0, 0, 0, 1)'

},
//顏色明暗度
visualMap: {

// 不顯示 visualMap 組件,只用于明暗度的映射
show: false,
// 映射的最小值為 80
min: 20,
// 映射的最大值為 600
max:365,
inRange: {
  // 明暗度的范圍是 0 到 1
  colorLightness: [0, 1]
}

},
//餅圖
series: [

{

  name: '訪問來源',
  type: 'pie',
  //加上為南定爾圖
  roseType: 'angle',
  radius: '55%',
  data: [
          { value: 30, name: '45545' },
          { value: 35, name: '聯(lián)盟廣告' },
          { value: 40, name: '郵件營銷' },
          { value: 45, name: '直接訪問' },
          {value: 50, name: '搜索引擎'}
    ],
    //emphasis是鼠標(biāo) hover 時候的高亮樣式。
    itemStyle: {
      emphasis: {
        shadowBlur: 20,
        shadowOffsetX: 0,
        // 陰影垂直方向上的偏移
        shadowOffsetY: 0,
        // 陰影顏色
        shadowColor: 'rgba(0, 0, 0, 0.5)'
      },
      // 設(shè)置扇形的顏色
      color: '#c23531',
      // shadowBlur: 200,
      // shadowColor: 'rgba(0, 0, 0, 0.5)',

    },

}

]
};
function initChart(canvas, width, height) {
chart = echarts.init(canvas, null, {

width: width,
height: height

});
canvas.setChart(chart);

var option = demo2;
chart.setOption(option);
return chart;
}

Page({
onShareAppMessage: function (res) {

return {
  title: 'ECharts 可以在微信小程序中使用啦!',
  path: '/pages/index/index',
  success: function () { },
  fail: function () { }
}

},

data: {

ec: {
  onInit: initChart
}

},
onLoad:function() {
},

onShow:function() {

// var messiones = app.globalData.messiones;
if (app.globalData.messiones!=null){
  var  dataArray=[];
  dataArray.splice(0);
  for (var pos in app.globalData.messiones) {
  //   console.log("hhh:"+app.globalData.messiones[pos].albumName);
  //  console.log(demo2.series[0].data[pos].name);
    var temp = {
      name: app.globalData.messiones[pos].albumName,
      value: app.globalData.messiones[pos].time
    }
    dataArray.push(temp);
  }
  demo2.series[0].data = dataArray;
  setTimeout(function () { 
    console.log(chart);
    chart.setOption(demo2);
  }, 2000);

}

}
})

2017年7月7日 01:09