微信小程序中使用echars
1、微信小程序中使用echars效果展示:
2、下载引入ec-canvas组件
将下载好的ec-canvas组件文件 放到 components文件夹下 (三个下载地址都可以使用,选其一即可)
3、log.json文件中声明注册使用ec-canvas组件
{
"navigationBarTitleText": "查看启动日志",
"usingComponents": {
"ec-canvas": "../../components/ec-canvas/ec-canvas"
}
}
4、log.wxml 页面引入ec-canvas组件
<!-- 使用echar记得先嵌套一层设置宽高 -->
<view class="echart-box">
<ec-canvas class="ec-canvas" ec="{{ ec }}"></ec-canvas>
</view>
.echart-box{
width: 100%;
height: 500px;
}
.ec-canvas{
width: 100%;
height: 100%;
}
5、log.js 页面
import * as echarts from '../../components/ec-canvas/echarts';
function initChart (canvas, width, height) {
console.warn(width, height,'---canvas---',canvas);
const chart = echarts.init(canvas, null, {
width: width,
height: height
});
var option = {
series: [
{
type: 'pie',
data: [
{
value: 335,
name: '直接访问'
},
{
value: 234,
name: '联盟广告'
},
{
value: 1548,
name: '搜索引擎'
}
]
}
]
};
var option2 = {
xAxis: {
data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
},
yAxis: {},
series: [
{
type: 'bar',
data: [23, 24, 18, 25, 27, 28, 25]
}
]
};
chart.setOption(option2);
return chart;
}
Page({
data: {
ec: {
onInit: initChart,
},
},
})
6、知识扩展:
|