在uniapp中使用ucharts

在uniapp中使用echarts,通过document或者ref去渲染元素,打包后在手机app中echarts不会显示。所以需要使用ucharts

下载安装:npm i @qiun/ucharts
然后再组件中引用:import uCharts from '../../uni_modules/qiun-data-charts/js_sdk/u-charts/u-charts.js';

var uChartsInstance = {};
页面组件就使用:<canvas canvas-id="chart" id="chart" style="width: 100%;height:95%;" />

我的写法是按照ucharts中的原生的方法进行的;

官网是:uCharts官网 - 秋云uCharts跨平台图表库 可以进去看下实例;

这个是柱状图的一个数据实例;我们将接口返回的数据,也写成这种格式进行传递

setTimeout(() => {

let resp = {

categories: res.data.name,

series: [{

name: "",

data: arr

}, ]

};

console.info(resp, 'resp')

this.ungetOption('chart', resp);

}, 500);

ungetOption(id, data) {

const ctx = uni.createCanvasContext(id, this);

uChartsInstance[id] = new uCharts({

type: "column",

context: ctx,

padding: [15, 30, 0, 5],

fontSize: 12,

width: this.cWidth,

height: this.cHeight,

categories: data.categories,

series: data.series,

animation: true,

background: "#FFFFFF",

color: ["#1890FF", "#91CB74", "#FAC858", "#EE6666", "#73C0DE", "#3CA272", "#FC8452", "#9A60B4", "#ea7ccc"],

padding: [15, 15, 0, 5],

enableScroll: false,

legend: {},

dataLabel: false,

categoriesStyle: {

fontSize: '7px', // 设置X轴文字大小

},

xAxis: {

disableGrid: true,

rotateLabel: true,

},

yAxis: {

data: [{

min: 0

}]

},

extra: {

column: {

type: "group",

width: 30,

activeBgColor: "#000000",

activeBgOpacity: 0.08

}

}

});

},

相关推荐
喵喵虫7 小时前
uniapp修改封装组件失败 styleIsolation
uni-app
游戏开发爱好者818 小时前
日常开发与测试的 App 测试方法、查看设备状态、实时日志、应用数据
android·ios·小程序·https·uni-app·iphone·webview
2501_9151063220 小时前
app 上架过程,安装包准备、证书与描述文件管理、安装测试、上传
android·ios·小程序·https·uni-app·iphone·webview
2501_9151063220 小时前
使用 Sniffmaster TCP 抓包和 Wireshark 网络分析
网络协议·tcp/ip·ios·小程序·uni-app·wireshark·iphone
宠友信息1 天前
2025社交+IM及时通讯社区APP仿小红书小程序
java·spring boot·小程序·uni-app·web app
“负拾捌”1 天前
python + uniapp 结合腾讯云实现实时语音识别功能(WebSocket)
python·websocket·微信小程序·uni-app·大模型·腾讯云·语音识别
局外人LZ2 天前
Uniapp脚手架项目搭建,uniapp+vue3+uView pro+vite+pinia+sass
前端·uni-app·sass
2501_915918412 天前
在 iOS 环境下查看 App 详细信息与文件目录
android·ios·小程序·https·uni-app·iphone·webview
前端呆头鹅2 天前
Websocket使用方案详解(uniapp版)
websocket·网络协议·uni-app
浮桥2 天前
uniapp+h5 公众号实现分享海报绘制
uni-app·notepad++