需求是一个div同时显示饼图和折线图 我在echarts官网找到了 这样得模板 但是问题是 他的数据都是写死得而我的是异步获取 不知道怎么弄 请各位大佬赐教 下为代码和需求图片
setTimeout(function () {
var data_x = ['product', '', '', '', '', '', ''];
var data_xs = data_x;
var data1 = ['Matcha Latte', 41.1, 30.4, 65.1, 53.3, 83.8, 98.7];
var data2 = ['Milk Tea', 86.5, 92.1, 85.7, 83.1, 73.4, 55.1];
var data4 = ['Walnut Brownie', 55.2, 67.1, 69.2, 72.4, 53.9, 39.1];
var data3 = ['Cheese Cocoa', 24.1, 67.2, 79.5, 86.4, 65.2, 82.5]
var itemName = data_xs[0];
option = {
legend: {},
tooltip: {
trigger: 'axis',
showContent: false
},
dataset: {
source: [
data_xs,
data1,
data2,
data3,
data4
]
},
xAxis: {type: 'category'},
yAxis: {gridIndex: 0},
grid: {top: '55%'},
series: [
{type: 'line', smooth: true, seriesLayoutBy: 'row'},
{type: 'line', smooth: true, seriesLayoutBy: 'row'},
{type: 'line', smooth: true, seriesLayoutBy: 'row'},
{type: 'line', smooth: true, seriesLayoutBy: 'row'},
{
type: 'pie',
id: 'pie',
radius: '30%',
center: ['50%', '25%'],
label: {
formatter: '{b}: ({d}%)'
},
encode: {
itemName: itemName,
value: data_x[1]
}
}
]
};
myChart.on('updateAxisPointer', function (event) {
var xAxisInfo = event.axesInfo[0];
if (xAxisInfo) {
var dimension = xAxisInfo.value + 1;
myChart.setOption({
series: {
id: 'pie',
label: {
formatter: '{b}: {@[' + dimension + ']} ({d}%)'
},
encode: {
value: dimension,
tooltip: dimension
}
}
});
}
});
myChart.setOption(option);
});;
if (option && typeof option === "object") {
myChart.setOption(option, true);
}