当前位置: 首页 > news >正文

uni-app:引入echarts(使用renderjs)

效果

代码

<template><view @click="echarts.onClick" :prop="option" :change:prop="echarts.updateEcharts" id="echarts" class="echarts"></view>
</template><script>export default {data() {return {option: '',x: ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"],y: [5, 20, 36, 10, 10, 20]}},onLoad() {this.option = {tooltip: {},xAxis: {data: this.x},yAxis: {},series: [{name: '销量',type: 'bar',data: this.y}]}},methods: {}}
</script><script module="echarts" lang="renderjs">let myChartexport default {mounted() {if (typeof window.echarts === 'function') {this.initEcharts()} else {// 动态引入较大类库避免影响页面展示const script = document.createElement('script')// view 层的页面运行在 www 根目录,其相对路径相对于 www 计算script.src = 'static/js/echarts.js'script.onload = this.initEcharts.bind(this)document.head.appendChild(script)}},methods: {initEcharts() {myChart = echarts.init(document.getElementById('echarts'))// 观测更新的数据在 view 层可以直接访问到myChart.setOption(this.option)},updateEcharts(newValue, oldValue, ownerInstance, instance) {// 监听 service 层数据变更if (myChart != undefined) {myChart.setOption(newValue)}},}}
</script><style>.echarts {width: 100%;height: 300px;}
</style>

参照代码

renderjs-echarts-demo - DCloud 插件市场

参照的效果

<template><view class="content"><!-- #ifdef APP-PLUS || H5 --><view @click="echarts.onClick" :prop="option" :change:prop="echarts.updateEcharts" id="echarts" class="echarts"></view><button @click="changeOption">更新数据</button><!-- #endif --><!-- #ifndef APP-PLUS || H5 --><view>非 APP、H5 环境不支持</view><!-- #endif --></view>
</template><script>export default {data() {return {option: {title: {text: 'ECharts 入门示例'},tooltip: {},legend: {data: ['销量']},xAxis: {data: ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"]},yAxis: {},series: [{name: '销量',type: 'bar',data: [5, 20, 36, 10, 10, 20]}]}}},onLoad() {},methods: {changeOption() {const data = this.option.series[0].data// 随机更新示例数据data.forEach((item, index) => {data.splice(index, 1, Math.random() * 40)})},onViewClick(options) {console.log(options)}}}
</script><script module="echarts" lang="renderjs">let myChartexport default {mounted() {if (typeof window.echarts === 'function') {this.initEcharts()} else {// 动态引入较大类库避免影响页面展示const script = document.createElement('script')// view 层的页面运行在 www 根目录,其相对路径相对于 www 计算script.src = 'static/js/echarts.js'script.onload = this.initEcharts.bind(this)document.head.appendChild(script)}},methods: {initEcharts() {myChart = echarts.init(document.getElementById('echarts'))// 观测更新的数据在 view 层可以直接访问到myChart.setOption(this.option)},updateEcharts(newValue, oldValue, ownerInstance, instance) {// 监听 service 层数据变更if (myChart != undefined) {myChart.setOption(newValue)}},onClick(event, ownerInstance) {// 调用 service 层的方法ownerInstance.callMethod('onViewClick', {test: 'test'})}}}
</script><style>.content {display: flex;flex-direction: column;align-items: center;justify-content: center;}.echarts {margin-top: 100px;width: 100%;height: 300px;}
</style>

http://www.lryc.cn/news/186518.html

相关文章:

  • 使用wireshark解析ipsec esp包
  • linux如何删除最近操作的日志
  • android端MifareClassicTool
  • 设计模式 - 迭代器模式
  • Docker之Dockerfile搭建lnmp
  • 排序算法——选择排序
  • 【数据结构C/C++】双向链表的增删改查
  • Godot 添加Nuget 引用
  • IC工程师职场必备《经典Verilog100多个代码案例》(附下载)
  • springboot项目做成公共项目
  • RTC 时间、闹钟
  • 【yolo系列:yolov7训练添加spd-conv】
  • 面向对象设计-UML六种箭头含义
  • 一本没有任何数学公式的自然语言处理入门书
  • 【数据结构C/C++】多维数组的原理、访问方式以及作用
  • 2023年中国烹饪机器人市场发展概况分析:整体规模较小,市场仍处于培育期[图]
  • Android原生实现控件选择背景变色方案(API28及以上)
  • 为什么要学C语言及C语言存在的意义
  • 数据结构——空间复杂度
  • uniapp:swiper-demo效果
  • Graphviz 作图工具
  • vue、vuex状态管理、vuex的核心概念state状态
  • 【QT】Qt Application Manager启动应用源码分析
  • MyBatisPlus(十)判空查询
  • AIGC(生成式AI)试用 8 -- 曾经的难题
  • 文化主题公园旅游景点3d全景VR交互体验加深了他们对历史文化的认知和印象
  • 京东数据分析平台:2023年8月京东奶粉行业品牌销售排行榜
  • Java 21:虚拟线程介绍
  • Redis-缓存穿透,缓存击穿,缓存雪崩
  • 如何使用Docker实现分布式Web自动化!