smartmeter-app/echarts-for-weixin-master/pages/tree/index.js

101 lines
1.6 KiB
JavaScript
Raw Normal View History

2023-12-05 16:45:28 +08:00
import * as echarts from '../../ec-canvas/echarts';
const app = getApp();
function initChart(canvas, width, height, dpr) {
const chart = echarts.init(canvas, null, {
width: width,
height: height,
devicePixelRatio: dpr // new
});
canvas.setChart(chart);
var data1 = {
"name": "root",
"children": [{
"name": "a",
"children": [{
"name": "a1"
}, {
"name": "a2"
}, {
"name": "a3"
}, {
"name": "a4"
}]
}, {
"name": "b",
"children": [{
"name": "b1"
}, {
"name": "b2"
}, {
"name": "b3"
}, {
"name": "b4"
}]
}, {
"name": "c",
"children": [{
"name": "c1"
}]
}, {
"name": "d",
"children": [{
"name": "d1"
}]
}]
};
var option = {
series: [{
type: 'tree',
initialTreeDepth: -1,
name: 'tree1',
data: [data1],
top: '5%',
left: '20%',
bottom: '2%',
right: '15%',
symbolSize: 10,
symbol: 'circle',
label: {
normal: {
position: 'left',
verticalAlign: 'middle',
align: 'right',
color: 'black'
}
}
}]
};
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() {
}
});