## **图表示例**
:-: 
## **标准数据格式**
```
chartData: {
categories: [{
value: 0.2,
color: '#2fc25b'
}, {
value: 0.8,
color: '#f04864'
}, {
value: 1,
color: '#1890ff'
}],
series: [{
name: '完成率',
data: 0.85
}]
}
```
## **调用方法**
```
canvaGauge = new uCharts({
$this:this,
canvasId: canvasId,
type: 'gauge',
fontSize:11,
legend:false,
title: {
name: Math.round(chartData.series[0].data*100)+'%',
color: chartData.categories[1].color,
fontSize: 25,
offsetY:50,
},
subtitle: {
name: chartData.series[0].name,
color: '#666666',
fontSize: 15,
offsetY:-50,
},
extra: {
gauge:{
type:'default',
width:10,//仪表盘背景的宽度
startAngle:0.75,
endAngle:0.25,
startNumber:0,
endNumber:100,
splitLine:{
fixRadius:0,
splitNumber:10,
width: 10,//仪表盘背景的宽度
color:'#FFFFFF',
childNumber:5,
childWidth:4,//仪表盘背景的宽度
},
pointer:{
width: 8,//指针宽度
color:'auto'
}
}
},
background:'#FFFFFF',
pixelRatio:1,
categories: chartData.categories,
series: chartData.series,
animation: true,
width: this.cWidth,
height: this.cHeight,
dataLabel: true,
});
```
## **完整代码示例**
```
<template>
<view class="qiun-columns">
<view class="qiun-bg-white qiun-title-bar qiun-common-mt" >
<view class="qiun-title-dot-light">仪表盘</view>
</view>
<view class="qiun-charts" >
<canvas canvas-id="canvasGauge" id="canvasGauge" class="charts"></canvas>
</view>
</view>
</template>
<script>
import uCharts from '@/components/u-charts/u-charts.js';
var _self;
var canvaGauge=null;
export default {
data() {
return {
cWidth:'',
cHeight:'',
pixelRatio:1,
gaugeWidth:15
}
},
onLoad() {
_self = this;
this.cWidth=uni.upx2px(750);
this.cHeight=uni.upx2px(500);
this.getServerData();
},
methods: {
getServerData(){
uni.request({
url: 'https://www.ucharts.cn/data.json',
data:{
},
success: function(res) {
console.log(res.data.data)
let Gauge={categories:[],series:[]};
//这里我后台返回的是数组,所以用等于,如果您后台返回的是单条数据,需要push进去
Gauge.categories=res.data.data.Gauge.categories;
Gauge.series=res.data.data.Gauge.series;
_self.showGauge("canvasGauge",Gauge);
},
fail: () => {
_self.tips="网络错误,小程序端请检查合法域名";
},
});
},
showGauge(canvasId,chartData){
canvaGauge = new uCharts({
$this:_self,
canvasId: canvasId,
type: 'gauge',
fontSize:11,
legend:false,
title: {
name: Math.round(chartData.series[0].data*100)+'%',
color: chartData.categories[1].color,
fontSize: 25*_self.pixelRatio,
offsetY:50*_self.pixelRatio,//新增参数,自定义调整Y轴文案距离
},
subtitle: {
name: chartData.series[0].name,
color: '#666666',
fontSize: 15*_self.pixelRatio,
offsetY:-50*_self.pixelRatio,//新增参数,自定义调整Y轴文案距离
},
extra: {
gauge:{
type:'default',
width: _self.gaugeWidth*_self.pixelRatio,//仪表盘背景的宽度
startAngle:0.75,
endAngle:0.25,
startNumber:0,
endNumber:100,
splitLine:{
fixRadius:0,
splitNumber:10,
width: _self.gaugeWidth*_self.pixelRatio,//仪表盘背景的宽度
color:'#FFFFFF',
childNumber:5,
childWidth:_self.gaugeWidth*0.4*_self.pixelRatio,//仪表盘背景的宽度
},
pointer:{
width: _self.gaugeWidth*0.8*_self.pixelRatio,//指针宽度
color:'auto'
}
}
},
background:'#FFFFFF',
pixelRatio:_self.pixelRatio,
categories: chartData.categories,
series: chartData.series,
animation: true,
width: _self.cWidth*_self.pixelRatio,
height: _self.cHeight*_self.pixelRatio,
dataLabel: true,
});
}
}
}
</script>
<style>
/*样式的width和height一定要与定义的cWidth和cHeight相对应*/
.qiun-charts {
width: 750upx;
height: 500upx;
background-color: #FFFFFF;
}
.charts {
width: 750upx;
height: 500upx;
background-color: #FFFFFF;
}
</style>
```
- uCharts简介
- 图表预览
- 快速上手
- 常见问题
- API参数
- 通用基础配置项
- 数据列表配置项
- 标题配置项
- 坐标轴配置项
- 图例配置项
- 扩展配置项
- 圆弧进度图
- 仪表盘
- 雷达图
- 柱状图
- 饼图圆环图
- 玫瑰图
- 折线图
- 区域图
- K线图
- 词云图
- 漏斗图
- 地图
- 条状图
- 标记线
- ToolTip
- 其他配置
- 方法 & 事件
- 更新图表数据
- 图例点击交互
- 停止动画效果
- 添加移除事件监听
- 获取图表点击序列编号
- 获取图例点击序列编号
- ToolTip方法
- 图表拖拽事件
- 放大或缩小图表
- 图表渲染完成事件
- 入门配置示例
- 图表区域详解
- 绘制X坐标轴网格
- 绘制Y坐标轴网格
- 隐藏X轴(不含网格)
- 隐藏Y轴(不含网格)
- 启用X轴滚动条及拖拽
- 绘制Y轴标题
- 隐藏X轴下方图例
- 隐藏数据点标识
- 隐藏数据点标签
- 进阶配置示例
- ToolTip配置
- uni-app示例
- 饼图
- 饼图基本用法
- 饼图右侧图例
- 圆环图
- 圆环图基本用法
- 玫瑰图
- 玫瑰图基本用法
- 线图
- 线图基本用法
- 柱状图
- 基本柱状图
- 温度计式图表
- 堆叠柱状图
- 横屏模式
- 区域图
- 区域图基本用法
- 雷达图
- 雷达图基本用法
- 圆弧进度图
- 圆弧进度图基本用法
- 整圆进度图基本用法
- 仪表盘
- 仪表盘基本用法
- K线图
- K线图基本用法
- 条状图
- 条状图基本用法
- 混合图
- 混合图基本用法
- 词云图
- 词云图基本用法
- 漏斗图
- 漏斗图基本用法
- 地图
- 地图基本用法
- 更新记录
- 改造uCharts打造专属图表
- uni-app实战教程