在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

}

}

});

},

相关推荐
iOS阿玮2 小时前
社交的本质是价值交换,请不要浪费别人的时间。
uni-app·app·apple
monika_yu2 小时前
uniapp 开发ios, xcode 提交app store connect 和 testflight内测
uni-app
大阳光男孩4 小时前
Vue3 + UniApp 蓝牙连接与数据发送(稳定版)
uni-app
八月林城19 小时前
echarts在uniapp中使用安卓真机运行时无法显示的问题
android·uni-app·echarts
哈贝#19 小时前
vue和uniapp聊天页面右侧滚动条自动到底部
javascript·vue.js·uni-app
iOS阿玮21 小时前
苹果2024透明报告看似更加严格的背后是利好!
uni-app·app·apple
邹荣乐1 天前
微信小程序动态tabBar实现:基于自定义组件,灵活支持不同用户角色与超过5个tab自由组合
前端·微信小程序·uni-app
不吃糖葫芦31 天前
App使用webview套壳引入h5(三)——解决打包为app后在安卓机可物理返回但是在苹果手机无法测滑返回的问题
uni-app·webview
半兽先生1 天前
uniapp微信小程序视频实时流+pc端预览方案
微信小程序·uni-app·音视频
胡斌附体2 天前
uniapp路由跳转toolbar页面
小程序·uni-app·switch·路由·type·uview-ui