<!DOCTYPE html>
<head>
<meta charset="utf-8">
<title>ECharts</title>
</head>
<body>
<!-- 為ECharts準備一個具備大小(寬高)的Dom -->
<div id="main" style="width:900px;height:300px"></div>
<!-- ECharts單檔案引入 -->
<script src="http://echarts.baidu.com/build/dist/echarts.js"></script>
<script type="text/javascript">
// 路徑配置
require.config({
paths: {
echarts: 'http://echarts.baidu.com/build/dist'
}
});
// 使用
require(
[
'echarts',
'echarts/chart/bar' // 使用柱狀圖就加載bar子產品,按需加載
],
function(ec) {
// 基于準備好的dom,初始化echarts圖表
var myChart = ec.init(document.getElementById('main'));
var option = {
tooltip: {
show: true
},
legend: {
data: ['銷量']
},
xAxis: [{
type: 'category',
data: ["襯衫", "羊毛衫", "雪紡衫", "褲子", "高跟鞋", "襪子"]
}],
yAxis: [{
type: 'value'
}],
series: [{
"name": "銷量",
"type": "bar",
"data": [5, 20, 40, 10, 10, 20],
itemStyle: {
normal: {
label: {
show: true, //開啟顯示
position: 'top', //在上方顯示
textStyle: { //數值樣式
color: 'black',
fontSize: 16
}
}
}
},
}]
};
// 為echarts對象加載資料
myChart.setOption(option);
}
);
</script>
</body>