Echarts基本使用
友情提示 需要先写div标签 然后应用echarts
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>123</title>
</head>
<!--<script type="text/javascript" src="js/jquery-3.2.1.min.js"></script>-->
<script type="text/javascript" src="js/echarts.js" ></script>
<body>
//先写这个div 不然加载不出来
<div id="main" style="width:600px; height:400px; background-color:rgba(255, 255, 0,0.5);">123</div>
<script type="text/javascript">
console.log('1');
// 基于准备好的 DOM,初始化 echarts 实例
var myChart = echarts.init(document.getElementById("main"));
console.log('begin');
// 指定图表的配置项和数据
var option = {
title:{
text:"ECharts 入门示例"
},
tooltip:{},
legend:{
data:["销量"]
},
xAxis:{
data:["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"]
},
yAxis:{},
series:{
name:["销量"],
type: "bar",
data:[5, 20, 36, 10, 10, 20]
}
}
// 使用刚指定的配置项和数据显示图表
myChart.setOption(option);
</script>
</body>
</html>
运行效果
南丁格尔图
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>ECharts Demo02-南丁格尔图</title>
<!-- 引入 ECharts 脚本文件 -->
<script src="js/echarts.js"></script>
</head>
<body>
<!-- 为 ECharts 准备一个具备大小的(宽高)的 DOM -->
<div id="main" style="width:600px; height:400px; background-color:rgba(255, 255, 255,0.5);">123</div>
<script type="text/javascript">
// 基于准备好的 DOM,初始化 echarts 实例
console.log('1');
var myChart = echarts.init(document.getElementById("main"));
console.log('2');
// 指定图表的配置项和数据
var option = {
backgroundColor: '#FFFFFF',
series : [
{
name: '访问来源',
type: 'pie',
radius: '55%',
data:[
{value:235, name:'视频广告'},
{value:274, name:'联盟广告'},
{value:310, name:'邮件营销'},
{value:335, name:'直接访问'},
{value:400, name:'搜索引擎'}
],
roseType: 'angle',
label: {
normal: {
textStyle: {
color: 'rgba(0, 0, 0, 0.7)'
}
}
},
labelLine: {
normal: {
lineStyle: {
color: 'rgba(0, 0, 0, 0.5)'
}
}
},
itemStyle: {
normal: {
color: '#c23531',
shadowBlur: 200,
shadowColor: 'rgba(0, 0, 0, 0.5)'
}
}
}
]
}
// 使用刚指定的配置项和数据显示图表
myChart.setOption(option);
</script>
</body>
</html>