效果图:
html:(script :echarts.js 自己去官网下载)
<button id="btn_Grid_treediagram" class="md-trigger btn btn-primary btn-sm" data-modal="modal-1">
树图
</button>
<div class="modal fade" id="treediagram" style="height: 900px;background: #00ceff">
<div id="container" style="height:600px;"></div>
</div>
js:(我这是点击按钮出现的)
$('#btn_Grid_treediagram').click(function () {
$('#treediagram').modal();
setTimeout(function () {
drawTree(data);
}, 300)
});
var data = [
{
name: "广东",
value: "01",
sj: "-",
symbol: 'image://http://10.10.36.109:8000/static/echarts/img/yy.png',
children: [{
name: "广州",
value: "0101",
sj: "01",
symbol: 'image://http://10.10.36.109:8000/static/echarts/img/sjk.png',
children: [{
name: "萝岗",
value: "010101",
sj: "0101",
symbol: 'image://http://10.10.36.109:8000/static/echarts/img/fzjh.png'
},
{
name: "天河",
value: "010102",
sj: "0101",
symbol: 'image://http://10.10.36.109:8000/static/echarts/img/fzjh.png'
},
{
name: "黄埔",
value: "010103",
sj: "0101",
symbol: 'image://http://10.10.36.109:8000/static/echarts/img/fzjh.png'
},
{
name: "白云",
value: "010104",
sj: "0101",
symbol: 'image://http://10.10.36.109:8000/static/echarts/img/fzjh.png'
},
{
name: "花都",
value: "010105",
sj: "0101",
symbol: 'image://http://10.10.36.109:8000/static/echarts/img/fzjh.png'
},
{
name: "海珠",
value: "010106",
sj: "0101",
symbol: 'image://http://10.10.36.109:8000/static/echarts/img/fzjh.png'
}]
},
{
name: "潮州",
value: "0102",
sj: "01",
symbol: 'image://http://10.10.36.109:8000/static/echarts/img/sjk.png',
children: [{
name: "枫溪",
value: "010201",
sj: "0102",
symbol: 'image://http://10.10.36.109:8000/static/echarts/img/fzjh.png'
},
{
name: "枫桥",
value: "010202",
sj: "0102",
symbol: 'image://http://10.10.36.109:8000/static/echarts/img/fzjh.png'
}]
},
{
name: "深圳",
value: "0103",
sj: "01",
symbol: 'image://http://10.10.36.109:8000/static/echarts/img/sjk.png',
children: [{
name: "罗湖",
value: "010301",
sj: "0103",
symbol: 'image://http://10.10.36.109:8000/static/echarts/img/fzjh.png'
}]
},
{
name: "茂名",
value: "0104",
sj: "01",
symbol: 'image://http://10.10.36.109:8000/static/echarts/img/sjk.png',
children: []
},
{
name: "揭阳",
value: "0105",
sj: "01",
symbol: 'image://http://10.10.36.109:8000/static/echarts/img/sjk.png',
children: []
}
]
}
];
function drawTree(treeData) {
var myChart = echarts.init(document.getElementById("container"), 'macarons');
myChart.clear();
myChart.setOption({
backgroundColor: 'rgba(255,215,0,0.4)',
tooltip: {
trigger: 'item',
triggerOn: 'mousemove'
},
toolbox: {
show: false,
},
calculable: false,
series: [{
type: 'tree',
name: 'TREE_ECHARTS',
orient: 'vertical',
rootLocation: {x: 'center', y: '10%'},
layerPadding: 5,
nodePadding: 5,
symbol: 'circle',
symbolSize: 40,
data: treeData,
top: '10%',
left: '8%',
bottom: '22%',
right: '20%',
edgeShape: 'polyline',
itemStyle: {
normal: {
label: {
show: true,
position: 'inside',
textStyle: {
color: '#000',
fontSize: 12,
fontWeight: 'bolder'
}
},
color: '#fff',
lineStyle: {
color: '#000',
width: 1,
type: 'broken'
}
},
emphasis: {
label: {
show: false,
textStyle: {
align: 'center',
verticalAlign: 'middle',
color: 'red'
}
},
color: '#fff',
borderWidth: 1
}
},
expandAndCollapse: true,
initialTreeDepth: 2
}]
}, true);
myChart.on('click', function (params) {
var name = params.data.name;
var value = params.data.value;
clickNode(name, value);
});
}
function clickNode(name, value) {
}