需要进行走马灯+echarts图表展示,后台返回数据为一次性返回
<el-carousel
indicator-position="none"
class="carousel"
>
<el-carousel-item
v-for="item,index in length"
:key="index"
>
<div
class="online_echarts"
:ref="`online_echarts${index+1}`"
:id="`online_echarts${index+1}`"
>
</div>
</el-carousel-item>
</el-carousel>
this.length = Math.ceil(data.length / 6)
for (let i = 0; i < this.length; i++) {
this.initChart(res.rows.splice(0, 6), i + 1)
}
initChart (data, index) {
this.$nextTick(() => {
const chart = echarts.init(document.getElementById(`online_echarts${index}`))
var option;
option = {
tooltip: {
trigger: "axis",
axisPointer: {
type: "shadow",
},
},
legend: {
textStyle: {
color: "#00d7ff",
},
icon: "circle",
},
grid: {
left: "3%",
right: "4%",
bottom: "8%",
top: "18%",
containLabel: true,
},
xAxis: [
{
type: "category",
axisLabel: {
color: "#ffffff",
rotate: 20,
interval: 0,
textStyle: {
fontSize: '12',
}
},
},
],
yAxis: [
{
type: "value",
name: "(%)",
axisLabel: {
formatter: "{value}",
color: "#ffffff",
},
splitLine: false,
axisLine: {
show: true,
lineStyle: {
},
},
},
],
series: [
{
name: "",
type: "bar",
emphasis: {
focus: "series",
},
barWidth: "8",
data: data.map((item) => {
return [item.devTypeName, ((item.onlineCount * 100) / item.deviceTypeCount).toFixed(2)];
}),
itemStyle: {
color: "#1d9dcf"
},
},
],
};
option && chart.setOption(option);
});
},
|