想用EChart做统计图,前端使用$.post请求已经得到json数据了,但是前端只有坐标系,不能生成统计图
配置项如下
<script>
function roomRate(){
var myChart = echarts.init(document.getElementById("bar"));
$.post('/hotel/HistoryOrderServlet',{flag:2},function(response){
myChart.setOption({
title: {
text: '房间使用情况'
},
tooltip: {},
legend: {
data: ['房间类型'],
},
xAxis: {
data: response.roomType,
},
yAxis: {},
series: [{
name: '房间类型',
type: 'bar',
data: response.num,
}]
});
},'json');
}
</script>
这是请求返回的数据:
[{"num":"5","roomType":"单人间"},{"num":"3","roomType":"双人间"},{"num":"1","roomType":"商务间"},{"num":"2","roomType":"豪华间"}]