bar
function optionFactory(res) {
var myChart = echarts.init(document.getElementById('main'));
var option = {
title: {
text: 'ECharts 入门示例'
},
toolbox: {
show: true,
feature: {
saveAsImage: {
show: true
}
}
},
legend: {
data: ['销量']
},
xAxis: {
data: res.xtype
},
yAxis: {},
series: [{
name: '销量',
type: 'bar',
data: res.xdata
}]
};
myChart.setOption(option);
}
$.ajax({
type: 'get',
url: 'http://127.0.0.1:5000/data',
dataType: "jsonp", // 指定此次请求是jsonp形式
// 【如果不使用jsonp方式,上面 ↑ 就可以那样写】
success: function (res) {
optionFactory(res);
},
error: function (msg) {
console.log(msg);
}
});