报错代码JS:
import uCharts from '../../../components/u-charts/u-charts'
var _self;
var canvaColumn = null;
Page({
/**
* 页面的初始数据
*/
data: {
cWidth: '',
cHeight: '',
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
_self = this;
this.cWidth = wx.getSystemInfoSync().windowWidth;
this.cHeight = 500 / 750 * wx.getSystemInfoSync().windowWidth;
this.getServerData()
},
// 这里 先暂时 应用 ucharts 里面提供的数据 调取他们的接口
getServerData: function () {
wx.request({
url: 'https://www.ucharts.cn/data.json',
data: {},
success: function (res) {
let Column = {
categories: [],
series: []
};
Column.categories = res.data.data.ColumnB.categories;
Column.series = res.data.data.ColumnB.series;
//自定义标签颜色和字体大小
Column.series[1].textColor = 'red';
Column.series[1].textSize = 11;
_self.showColumn("canvasColumn", Column);
},
fail: () => {
console.log("请点击右上角【详情】,启用不校验合法域名");
},
})
},
showColumn(canvasId, chartData) {
canvaColumn = new uCharts({
$this: _self,
canvasId: canvasId,
type: 'line',
legend: true,
fontSize: 11,
background: '#FFFFFF',
pixelRatio: 1,
animation: true,
categories: chartData.categories,
series: chartData.series,
xAxis: {
disableGrid: true,
},
yAxis: {
//disabled:true
},
dataLabel: true,
width: _self.cWidth,
height: _self.cHeight,
extra: {
column: {
type: 'group',
width: _self.cWidth * 0.45 / chartData.categories.length
}
}
});
}
})
报错:
解决:
改进代码:
let ctx = wx.createCanvasContext(canvasId, this);
canvaColumn = new uCharts({
context: ctx,
...
});