首页 > 代码库 > echarts 柱状图

echarts 柱状图

$(document).ready(function () {
var myChart = echarts.init(document.getElementById(‘main‘), ‘westeros‘);
function main(chartData) {
var delayAvg = []; //延迟完成数组
var completedAvg = []; //按时完成数组
for (var i = 0; i < chartData.delayDayList.length; i++) {
if (chartData.delayDayList[i] >= 0) {
completedAvg.push(null);
delayAvg.push(chartData.delayDayList[i]);
} else {
completedAvg.push(chartData.delayDayList[i]);
delayAvg.push(null);
}
}
var option = {
color: [‘#3398DB‘],
tooltip: {
show: false,
trigger: ‘axis‘,
axisPointer: {
type: ‘shadow‘
}
},
grid: {
x: 58,
y: 48,
x2: 53,
y2: 95,
containLabel: false
},
xAxis: [
{
type: ‘category‘,
data: chartData.nodeTileList,
axisTick: {
alignWithLabel: true
},
axisLabel: {
textStyle: {
fontSize: 12,
color: ‘#000‘
},
formatter: function (par) {
return par;
},
interval: 0 //类目全显
//rotate: 90 //顺时针旋转45度
}
}
],
yAxis: [
{
type: ‘value‘
}
],
"dataZoom": [
{
"show": false,
"height": 30,
"xAxisIndex": [0],
bottom: 20,
"start": 0,
"end": 250,
handleIcon: ‘path://M306.1,413c0,2.2-1.8,4-4,4h-59.8c-2.2,0-4-1.8-4-4V200.8c0-2.2,1.8-4,4-4h59.8c2.2,0,4,1.8,4,4V413z‘,
handleSize: ‘110%‘,
handleStyle: {
color: "#d3dee5"
},
textStyle: {
color: "#000"
},
borderColor: "#90979c"
}, {
"type": "inside",
"show": true,
"height": 15,
"start": 1,
"end": 35
}
],
series: [
{
name: ‘延迟完成‘,
type: ‘bar‘,
barWidth: ‘40%‘,
stack: ‘数量‘,
itemStyle: {
normal: {
label: {
show: true,
position: ‘top‘,
formatter: function (par) {
if (par.data >= 0) {
return par.data;
} else {
return "";
}
},
textStyle: {
color: ‘#000‘
}
},
color: ‘rgb(168, 1, 6)‘
}
},
data: delayAvg
}, {
name: ‘已完成‘,
type: ‘bar‘,
stack: ‘数量‘,
barWidth: ‘40%‘,
itemStyle: {
normal: {
label: {
show: true,
position: ‘bottom‘,
formatter: function (par) {
if (par.data < 0) {
return par.data;
} else {
return "";
}
},
textStyle: {
color: ‘#000‘
}
},
color: ‘rgb(25, 107, 0)‘
}
},
data: completedAvg
}
]
};
myChart.on(‘click‘, function (param) {
var index = param.dataIndex;
_nodeId = chartData.flowNodeIdList[index];
var startTime = $("#txtStartTime").val(); //开始时间
var endTime = $("#txtEndTime").val(); //结束时间
window.open("/Statistical/ProjectNode/NodeAvgDelayList?flowNodeId=" + _nodeId + "&status=all&startTime=" + startTime + "&endTime=" + endTime);
});
//使用刚指定的配置项和数据显示图表。
myChart.setOption(option);
};

//请求堆积图数据AJAX
var ajaxGetStacke = function (startTime, endTime) {
$.ajax({
type: "get",
url: "/Statistical/ProjectNode/GetNodeProAvgDayResult?time="+new Date(),
data: { startTime: startTime, endTime: endTime },
dataType: "json",
success: function (data) {
if (data.Success === true) {
var result = data.results;
main(result);
}
},
error: function (error) {
console.log(error);
//parent.$.messager.layer.alert(‘提示‘, ‘模板节点规则信息获取失败!‘, ‘info‘);
return;
}
});
}
//第一次进页面刷新调用
ajaxGetStacke(null, null);
//点击统计调用
$("#subSta").click(function () {
var startTime = $("#txtStartTime").val(); //开始时间
var endTime = $("#txtEndTime").val(); //结束时间
ajaxGetStacke(startTime, endTime);
});
});

 

 

<div id="main" style="height: 460px; margin-bottom: 40px; background-color: #fff;"></div>
<script type="text/javascript">
// 基于准备好的dom,初始化echarts实例
</script>

echarts 柱状图