这个是插件主页
https://ext.dcloud.net.cn/plugin?id=271
导入项目之后,项目就会出现uni_modules目录
在这里可以生成代码
https://demo.ucharts.cn/
代码
<template>
<view class="qiun-columns">
<view class="qiun-charts" >
<canvas canvas-id="canvasLineA" id="canvasLineA" class="charts" @touchstart="touchLineA"></canvas>
</view>
</view>
</template>
<script>
// 引入uCharts 方法组件。
import uCharts from '@/uni_modules/qiun-data-charts/js_sdk/u-charts/u-charts.js';
// 定义全局变量
var _self;
var canvaLineA=null;
var chartData = {
"categories": [
"2016",
"2017",
"2018",
"2019",
"2020",
"2021"
],
"series": [
{
"name": "成交量A",
"data": [
35,
8,
25,
37,
4,
20
]
},
{
"name": "成交量B",
"data": [
26,
10,
65,
160,
44,
68
]
}
]
};
export default {
data() {
return {
cWidth:'',
cHeight:'',
pixelRatio:1,
}
},
// 页面加载执行的函数
onLoad() {
_self = this;
// uni.upx2px(750) 这是uni-app自带的自适应,以750的尺寸为基准。动态变化
this.cWidth=uni.upx2px(750);
this.cHeight=uni.upx2px(500);
this.showLineA("canvasLineA",chartData);
},
methods: {
// 展示图标的函数 接收参数,一个块的id,一个数据
showLineA(canvasId,chartData){
canvaLineA=new uCharts({
$this:_self,
canvasId: canvasId,
context: uni.createCanvasContext(canvasId, _self),
// 图标类型
type: 'line',
fontSize:11,
legend:{show:true},
dataLabel:false,
dataPointShape:true,
background:'#FFFFFF',
pixelRatio:_self.pixelRatio,
categories: chartData.categories,
series: chartData.series,
animation: true,
// x轴显示的内容
xAxis: {
type:'grid',
gridColor:'#CCCCCC',
gridType:'dash',
dashLength:8
},
// y轴显示的内容
yAxis: {
gridType:'dash',
gridColor:'#CCCCCC',
dashLength:8,
splitNumber:5,
min:10,
max:180,
format:(val)=>{return val.toFixed(0)+'元'}
},
width: _self.cWidth*_self.pixelRatio,
height: _self.cHeight*_self.pixelRatio,
extra: {
line:{
type: 'straight'
}
}
});
},
// 点击图表显示的内容
touchLineA(e) {
// 使用声明的变量canvaLineA
canvaLineA.showToolTip(e, {
format: function (item, category) {
return category + ' ' + item.name + ':' + item.data
}
});
}
}
}
</script>
<style scoped>
/*样式的width和height一定要与定义的cWidth和cHeight相对应*/
.qiun-charts {
width: 750upx;
height: 500upx;
background-color: #FFFFFF;
}
.charts {
width: 750upx;
height: 500upx;
background-color: #FFFFFF;
}
</style>