在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);

uChartsInstanceid = 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

}

}

});

},

相关推荐
anyup3 小时前
uni-app 没有根组件?仅需几行代码实现全局 Toast 和 Modal
前端·架构·uni-app
2501_916007473 小时前
Python实现HTTPS爬虫的完整指南:使用requests、BeautifulSoup、Selenium和Scrapy
爬虫·python·ios·小程序·https·uni-app·iphone
AI_AGENT_DEV_AI4 小时前
原生 APP(iOS / Android)的开发与上线
uni-app
小徐_233317 小时前
Wot UI 2.3.0 发布:二维码组件来了,Open Wot 与 wot-starter 同步更新
前端·微信小程序·uni-app
skiyee21 小时前
🔥 oiyo & unibest = 又新又好的 uniapp 模板
前端·uni-app
结网的兔子3 天前
【前端开发】Web端迁移至 uni-app 及鸿蒙扩展方案对比
前端·uni-app·harmonyos
2501_915909063 天前
iOS 应用反调试技详解术 检测调试器的原理与防护实践
android·ios·小程序·https·uni-app·iphone·webview
AI多Agent协作实战派3 天前
AI多Agent协作系统实战(二十八):顶栏统一战争——从1个页面异常到31个页面全量对齐
数据库·人工智能·uni-app
00后程序员张3 天前
iOS加固技术路线全面解析:Bitcode模式、源码模式与汇编模式对比及爱加密优势
android·汇编·ios·小程序·uni-app·cocoa·iphone
2501_916008894 天前
iOS IPA文件反编译与打包操作方法,拆包分析防护和加固打包
android·macos·ios·小程序·uni-app·cocoa·iphone