<!DOCTYPE html>
<head>
<meta charset="utf-8">
<title>ECharts</title>
<script>
function onAndroid(obj){
window.demo.jsClick(obj);
}
</script>
</head>
<body>
<!-- 为ECharts准备一个具备大小(宽高)的Dom -->
<div id="pie" style="height:200px"></div>
<div id="cpu" style="height:400px"></div>
<div id="oneminute" style="height:400px"></div>
<input id="test" type="button" value="test" onClick="onAndroid('我来了')"/>
<!-- ECharts单文件引入 -->
<script src="./js/echarts-all.js"></script>
<script type="text/javascript">
// 基于准备好的dom,初始化echarts图表
var pieChart = echarts.init(document.getElementById('pie'));
var cpuChart = echarts.init(document.getElementById('cpu'));
var oneMinuteChart = echarts.init(document.getElementById('oneminute'));
var cpuOption = {
title:{
text:"CPU走势图"
},
tooltip: {
show: true
},
toolbox: {
show : true,
padding: 30,
feature : {
restore : {show: true},
}
},
calculable : true,
grid:{
x:30,
x2:30
},
xAxis : [
{
boundaryGap : false,
type : 'category',
data : ["9.05","9.05","9.05","9.05","9.05","9.05","9.05","9.05","9.05","9.05"]
}
],
yAxis : [
{
min:1,
max:300,
type : 'value'
}
],
series : [
{
symbol: 'emptyCircle',
smooth:true,
name:"CPU走势",
type:"line",
itemStyle: {normal: {areaStyle: {type: 'default'}}},
data:[5, 20, 40, 10, 10, 20,7,35,1,9]
}
]
};
var oneMinuteOption = {
title:{
text:"一分钟负载走势图"
},
tooltip: {
show: true
},
toolbox: {
show : true,
padding: 30,
feature : {
restore : {show: true},
}
},
calculable : true,
grid:{
x:30,
x2:30
},
xAxis : [
{
boundaryGap : false,
type : 'category',
data : ["9.05","9.05","9.05","9.05","9.05","9.05","9.05","9.05","9.05","9.05"]
}
],
yAxis : [
{
type : 'value'
}
],
series : [
{
symbol: 'emptyCircle',
smooth:true,
name:"一分钟负载走势",
type:"line",
itemStyle: {normal: {areaStyle: {type: 'default'}}},
data:[5, 20, 40, 10, 10, 20,7,35,1,9]
}
]
};
var labelTop = {
normal : {
label:{
position:'inside',
formatter: '\n{b}',
textStyle: {
fontSize: 15,
baseline: 'top',
color: '#1e90ff'
}
},
labelLine:{show:false}
}
};
var labelBottom = {
normal : {
color: '#ccc',
label : {
formatter : function (params){
return 100 - params.value
},
show : true,
position : 'center',
textStyle: {
fontSize :20
}
},
labelLine : {
show : false
}
},
emphasis: {
color: 'rgba(0,0,0,0)'
}
};
var radius = [25, 35];
pieOption = {
title : {
text: '实时平均值',
x: 'left'
},
toolbox: {
show : true,
padding: 30,
feature : {
restore : {show: true},
}
},
series : [
{
startAngle: 90 + (46 / 100 * 360) / 2,
type : 'pie',
center : ['12%', '50%'],
radius : radius,
x: '0%', // for funnel
data : [
{name:'other', value:46, itemStyle : labelBottom},
{name:'CPU', value:54,itemStyle : labelTop}
]
},
{
startAngle:90 + (56 / 100 * 360) / 2,
type : 'pie',
center : ['37%', '50%'],
radius : radius,
x:'20%', // for funnel
data : [
{name:'other', value:56, itemStyle : labelBottom},
{name:'内存', value:44,itemStyle : labelTop}
]
},
{
startAngle:90 + (65 / 100 * 360) / 2,
type : 'pie',
center : ['62%', '50%'],
radius : radius,
x:'40%', // for funnel
data : [
{name:'other', value:65, itemStyle : labelBottom},
{name:'一分钟负载', value:35,itemStyle : labelTop}
]
},
{
startAngle:90 + (70 / 100 * 360) / 2,
type : 'pie',
center : ['87%', '50%'],
radius : radius,
x:'60%', // for funnel
data : [
{name:'other', value:70, itemStyle : labelBottom},
{name:'网络LO', value:30,itemStyle : labelTop}
]
},
]
};
cpuChart.setOption(cpuOption);
oneMinuteChart.setOption(oneMinuteOption);
pieChart.setOption(pieOption);
function androidFunction(option){
myChart.setOption(option);
}
</script>
</body>