小程序使用 ECharts 画图表怎么动态的修改数据呀

2018-07-14 16:30:44 +08:00
 Afishtail

后面会用到雷达图,如何下载了 echarts 组件后发现不会动态修改。。 之前做小程序一直是写 page 里的内容,引入这个组件真的有点懵。。复制下 js 代码。。求大神指点下 下面就是组件源码了,网上也有其他相关的,但是比较杂,代码格式也不太一样,echarts 这么写肯定有他道理。 import * as echarts from '../../ec-canvas/echarts';

const app = getApp();

function initChart(canvas, width, height) { const chart = echarts.init(canvas, null, { width: width, height: height }); canvas.setChart(chart);

var option = { backgroundColor: "#ffffff", color: ["#37A2DA", "#FF9F7F"], tooltip: {}, xAxis: { show: false }, yAxis: {
show: false }, radar: { // shape: 'circle', indicator: [{ name: '食品', max:500 }, { name: '玩具', max: 500 }, { name: '服饰', max: 500 }, { name: '绘本', max: 500 }, { name: '医疗', max: 500 }, { name: '门票', max: 500 } ] }, series: [{ name: '预算 vs 开销', type: 'radar', data: [{ value: [430, 340, 500, 300, 490, 400], name: '预算' }, { value: [300, 430, 150, 300, 420, 250], name: '开销' } ] }] };

chart.setOption(option); return chart; }

Page({ onShareAppMessage: function (res) { return { title: 'ECharts 可以在微信小程序中使用啦!', path: '/pages/index/index', success: function () { }, fail: function () { } } }, data: { ec: { onInit: initChart } },

onReady() {

} });

10002 次点击
所在节点    JavaScript
4 条回复
s609926202
2018-07-14 16:41:55 +08:00
你去他的代码库看看案例,多看几遍
shuax
2018-07-14 20:01:06 +08:00
你找官方示例会动态改变的就行了
des
2018-07-14 20:03:32 +08:00
chart.setOption(option) 就完了,他会自动合并
alvin666
2018-07-14 21:20:59 +08:00
二楼三楼正解,我就是改的官方 demo,自动合并数据

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/470895

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX