});echarts
function drawUnitBar(){
// 路徑配置
require.config({
paths: {
echarts: '../js/echarts/build/source'
}
});
// 請求
$.post("<%=request.getContextPath()%>/userUnitStatistics/userUnit.c", {}, function(dataStr){
var data = dataStr;
//alert(data);
var data_yAxis = [];
var series_data = [];
for(var o in data){
data_yAxis.push(data[o].unitName);
series_data.push(data[o].count)
}
//alert(data_yAxis);
//alert(series_data);
// 使用
require(
[
'echarts',
'echarts/chart/bar' // 使用柱狀圖就加載bar模塊,按需加載
],
function (ec) {
// 基於準備好的dom,初始化echarts圖表
var myChart = ec.init(document.getElementById('main-unitID'));
var option = {
title : {
text: '',
subtext: ''
},
tooltip : {
trigger: 'axis'
},
legend: {
data:['用戶數']
},
toolbox: {
show : false,
feature : {
mark : {show: true},
dataView : {show: true, readOnly: false},
magicType: {show: true, type: ['line', 'bar']},
restore : {show: true},
saveAsImage : {show: true}
}
},
calculable : true,
xAxis : [
{
type : 'value',
boundaryGap : [0, 0.01]
}
],
yAxis : [
{
type : 'category',
data : data_yAxis
}
],
series : [
{
name:'用戶數',
type:'bar',
data:series_data,
itemStyle:{
normal: {
color:'#68BC31'
}
}
}
]
};
// 爲echarts對象加載數據
window.onresize = myChart.resize;
myChart.setOption(option);
}
);
});
}
dom