html页面
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>ECharts</title>
<!-- 引入 echarts.js -->
<script src="echarts.min.js"></script>
<script src="jquery-1.7.1.min.js"></script>
</head>
<body style="background-color:#425DFF;">
<div style="position:relative;width: 100%;height:200px;background-color:#fff;border-radius:10px;">
<!-- 为ECharts准备一个具备大小(宽高)的Dom -->
<div id="main" style="position:absolute;z-index:2;height:100%;"></div>
<!--<div id="myDiv" style="position:absolute;z-index:3;color:#3571FE; top:5px;right:10px;font-size:14px" onclick="init()">查看详情</div>-->
</div>
<script type="text/javascript">
var width;
var height;
var myChart;
function browserRedirect() {
var sUserAgent = navigator.userAgent.toLowerCase();
var bIsIpad = sUserAgent.match(/ipad/i) == "ipad";
var bIsIphoneOs = sUserAgent.match(/iphone os/i) == "iphone os";
var bIsMidp = sUserAgent.match(/midp/i) == "midp";
var bIsUc7 = sUserAgent.match(/rv:1.2.3.4/i) == "rv:1.2.3.4";
var bIsUc = sUserAgent.match(/ucweb/i) == "ucweb";
var bIsAndroid = sUserAgent.match(/android/i) == "android";
var bIsCE = sUserAgent.match(/windows ce/i) == "windows ce";
var bIsWM = sUserAgent.match(/windows mobile/i) == "windows mobile";
if (bIsIpad || bIsIphoneOs || bIsMidp || bIsUc7 || bIsUc || bIsAndroid || bIsCE || bIsWM) {
height = document.body.clientHeight
width = document.body.clientWidth
// alert(height)
$("#main").css("width",width);
$("#main").css("height",height);
setEcharts();
$(window).resize(function() {
width = document.body.clientWidth
height = document.body.clientHeight
$("#main").css("width",width);
$("#main").css("height",height);
});
} else {
alert("pc");
//自适应设置
width = $(window).width();
height = $(window).height();
// alert(height)
$("#main").css("width",width-35);
$("#main").css("height",height-360);
setEcharts();
$(window).resize(function() {
width = $(window).width();
height = $(window).height();
$("#main").css("width",width-35);
$("#main").css("height",height-360);
});
}
}
window.onload=function(){
browserRedirect()
}
function setEcharts(){
// 基于准备好的dom,初始化echarts实例
myChart = echarts.init(document.getElementById('main'));
//自适应
window.onresize = myChart.resize;
var data = myHtmlTestBean.getData().split(",").map(Number);
var data2 = myHtmlTestBean.getTime();
var aar2 = data2.split(",");
var markLineOpt = {
animation: false,
symbol: ['none', 'none'],//去掉箭头
lineStyle: {
type: 'solid'
},
data: [{
name: 'Y 轴值为 500 的水平线',
yAxis: 500
}]
};
// 指定图表的配置项和数据
var option = {
title: {
text: '配件统计(月)',
show:true,
textAlign :'auto',
left: 'center',
top:'5px',
textStyle:{
fontWeight:'normal'
}
},
legend: {
data:['配件维修','配件更换','直接维修'],
//取消图例点击事件
selectedMode:false,
icon:'roundRect',
top:25
},
xAxis: {
type: 'category',
//从0开始
boundaryGap:false,
//data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
data:aar2
},
yAxis: {
type: 'value'
},
dataZoom: [
//缩放
{
type: 'inside',
xAxisIndex: [0],
start: 1,
end: 100
},
{
type: 'inside',
yAxisIndex: [0],
start: 1,
end: 100
}
],
grid: {
left:'5%',
right:'10%',
bottom:'5%',
containLabel:true
},
series: [{
name:'配件维修',
//取消图表点击事件
clickable:false,
//data: [820, 932, 901, 934, 1290, 1330, 1320],
data:data,
type: 'line',
//是否平滑曲线显示
smooth: true,
//线条颜色
itemStyle: {
color: 'rgb(255, 0, 0)',
//显示数值
<!--normal: {label : {show: true}}-->
},
//警戒线
<!--markLine: markLineOpt,-->
//填充颜色
<!--areaStyle:{-->
//填充渐变颜色
<!--color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{-->
<!--offset: 0,-->
<!--color: 'rgb(255, 158, 68)'-->
<!--}, {-->
<!--offset: 1,-->
<!--color: 'rgb(255, 70, 131)'-->
<!--}])-->
<!--}-->
}
,{
name:'配件更换',
data: [820, 932, 901, 934, 1290, 1330, 1320],
//data:data,
type: 'line',
//是否平滑曲线显示
smooth: true,
//线条颜色
itemStyle: {
color: 'rgb(0, 255, 0)'
},
//警戒线
<!--markLine: markLineOpt,-->
//填充颜色
<!--areaStyle:{-->
//填充渐变颜色
<!--color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{-->
<!--offset: 0,-->
<!--color: 'rgb(255, 158, 68)'-->
<!--}, {-->
<!--offset: 1,-->
<!--color: 'rgb(255, 70, 131)'-->
<!--}])-->
<!--}-->
},{
name:'直接维修',
data: [150, 550, 160, 514, 1290, 830, 120],
//data:data,
type: 'line',
//是否平滑曲线显示
smooth: true,
//线条颜色
itemStyle: {
color: 'rgb(0, 0, 255)'
},
//警戒线
<!--markLine: markLineOpt,-->
//填充颜色
<!--areaStyle:{-->
//填充渐变颜色
<!--color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{-->
<!--offset: 0,-->
<!--color: 'rgb(255, 158, 68)'-->
<!--}, {-->
<!--offset: 1,-->
<!--color: 'rgb(255, 70, 131)'-->
<!--}])-->
<!--}-->
}
]
};
// 使用刚指定的配置项和数据显示图表。
myChart.setOption(option);
}
</script>
</body>
</html>