在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

}

}

});

},

相关推荐
Rysxt_5 小时前
uni-app 使用教程:从入门到发布
uni-app
homelook1 天前
uniapp蓝牙demo
uni-app
2501_915909062 天前
手机崩溃日志导出的工程化体系,从系统级诊断到应用行为分析的多工具协同方法
android·ios·智能手机·小程序·uni-app·iphone·webview
郑州光合科技余经理2 天前
技术视角:海外版一站式同城生活服务平台源码解析
java·开发语言·uni-app·php·排序算法·objective-c·生活
wangdaoyin20102 天前
UniApp中使用LivePlayer进行视频或在流媒体播放
uni-app·liveplayer·h5播放视频
2501_915106322 天前
App HTTPS 抓包实战解析,从代理调试到真实网络流量观察的完整抓包思路
网络协议·http·ios·小程序·https·uni-app·iphone
游戏开发爱好者82 天前
苹果App Store应用程序上架方式全面指南
android·小程序·https·uni-app·iphone·webview
2501_916008892 天前
深入理解 iPhone 文件管理,从沙盒结构到开发调试的多工具协同实践
android·ios·小程序·https·uni-app·iphone·webview
一室易安2 天前
解决使用 UniApp 搭配 Vue3 小程序开始 使用uview-plus 的返回顶部up-back-top中onPageScroll 不触发的问题
小程序·uni-app
yilan_n2 天前
鸿蒙应用上传
vue.js·华为·uni-app