1.简单图表
在HTML
<body> <!-- 为 ECharts 准备一个具备大小(宽高)的 DOM --> <div id="main" style="width: 600px;height:400px;"></div> </body>
柱状图:
<body>
<!-- 为ECharts准备一个具备大小(宽高)的Dom -->
<div id="main" style="width: 600px;height:400px;"></div>
<script type="text/javascript">
// 基于准备好的dom,初始化echarts实例
var myChart = echarts.init(document.getElementById('main'));
// 指定图表的配置项和数据
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>
折线图
option = {
title: {
text: '折线图堆叠'
},
tooltip: {
trigger: 'axis'
},
legend: {
data: ['邮件营销', '联盟广告', '视频广告', '直接访问', '搜索引擎']
},
grid: {
left: '3%',
right: '4%',
bottom: '3%',
containLabel: true
},
toolbox: {
feature: {
saveAsImage: {}
}
},
xAxis: {
type: 'category',
boundaryGap: false,
data: ['周一', '周二', '周三', '周四', '周五', '周六', '周日']
},
yAxis: {
type: 'value'
},
series: [
{
name: '邮件营销',
type: 'line',
stack: '总量',
data: [120, 132, 101, 134, 90, 230, 210]
},
{
name: '联盟广告',
type: 'line',
stack: '总量',
data: [220, 182, 191, 234, 290, 330, 310]
},
{
name: '视频广告',
type: 'line',
stack: '总量',
data: [150, 232, 201, 154, 190, 330, 410]
},
{
name: '直接访问',
type: 'line',
stack: '总量',
data: [320, 332, 301, 334, 390, 330, 320]
},
{
name: '搜索引擎',
type: 'line',
stack: '总量',
data: [820, 932, 901, 934, 1290, 1330, 1320]
}
]
};
矩形树图
路径图
散点图
饼状图
var data = [{
name: 'Apples',
value: 70
}, {
name: 'Strawberries',
value: 68
}, {
name: 'Bananas',
value: 48
}, {
name: 'Oranges',
value: 40
}, {
name: 'Pears',
value: 32
}, {
name: 'Pineapples',
value: 27
}, {
name: 'Grapes',
value: 18
}];
option = {
title: [{
text: 'Pie label alignTo'
}, {
subtext: 'alignTo: "none" (default)',
left: '16.67%',
top: '75%',
textAlign: 'center'
}, {
subtext: 'alignTo: "labelLine"',
left: '50%',
top: '75%',
textAlign: 'center'
}, {
subtext: 'alignTo: "edge"',
left: '83.33%',
top: '75%',
textAlign: 'center'
}],
series: [{
type: 'pie',
radius: '25%',
center: ['50%', '50%'],
data: data,
animation: false,
label: {
position: 'outer',
alignTo: 'none',
bleedMargin: 5
},
left: 0,
right: '66.6667%',
top: 0,
bottom: 0
}, {
type: 'pie',
radius: '25%',
center: ['50%', '50%'],
data: data,
animation: false,
label: {
position: 'outer',
alignTo: 'labelLine',
bleedMargin: 5
},
left: '33.3333%',
right: '33.3333%',
top: 0,
bottom: 0
}, {
type: 'pie',
radius: '25%',
center: ['50%', '50%'],
data: data,
animation: false,
label: {
position: 'outer',
alignTo: 'edge',
margin: 20
},
left: '66.6667%',
right: 0,
top: 0,
bottom: 0
}]
};
2.实现基础的三维可视化
var option = { // 需要注意的是我们不能跟 grid 一样省略 grid3D grid3D: {}, // 默认情况下, x, y, z 分别是从 0 到 1 的数值轴 xAxis3D: {}, yAxis3D: {}, zAxis3D: {} }