onLoad() {
_self = this;
this.cWidth = uni.upx2px(750);
this.cHeight = uni.upx2px(500);
this.loadChartData();
},
methods: {
loadChartData() {
let url = "...";
console.log("服务器地址: " + url);
let params = null;
uni.request({
url: url,
method: 'POST',
data: params,
dataType: 'json',
success: function(res) {
console.log(res.data.data);
let lineData = {
categories: [],
series: []
};
lineData.categories = (res.data.data)["categories"];
lineData.series = (res.data.data)["series"];
_self.showLineChart('canvasLine', lineData);
},
fail: function(res) {
this.tips = "网络错误";
}
});
},
showLineChart(canvasId, chartData) {
console.log("显示图表: canvasId=" + canvasId + ", chartData=" + chartData);
canvasLine = new uCharts({
$this: _self,
canvasId: canvasId,
type: 'line',
fontSize: 11,
legend: {
show: true,
padding: 5,
lineHeight: 11,
margin: 0
},
dataLabel: false,
dataPointShape: true,
background: '#FFFFFF',
pixelRatio: _self.pixelRatio,
categories: chartData.categories,
series: chartData.series,
animation: true,
xAxis: {
type: 'grid',
gridColor: '#CCCCCC',
gridType: 'dash',
dashLength: 8,
scrollShow: true
},
yAxis: {
gridType: 'dash',
gridColor: '#CCCCCC',
dashLength: 8
// ,splitNumber: 5,
// min: 0,
// max: 20,
// format: (val) => {
// return val.toFixed(0) + '点'
// }
},
width: _self.cWidth * _self.pixelRatio,
height: _self.cHeight * _self.pixelRatio,
extra: {
line: {
type: 'straight'
}
}
});
}
}
ArisHu
- 发布:2019-11-04 09:19
- 更新:2019-11-04 09:19
- 阅读:1377