heli-mes/mes-ui/mes-echarts/src/views/rightbot2.vue

280 lines
7.3 KiB
Vue
Raw Normal View History

2025-01-09 18:29:48 +08:00
<template>
<div>
<dv-border-box-13>
<div class="dvrow">
<div>
<span class="title-span">2024年度开发模具数量</span>
</div>
</div>
<div class="echarts" id="rbot2main"></div>
</dv-border-box-13>
</div>
</template>
<script>
import * as echarts from "echarts";
export default {
props: {},
data() {
return {};
},
created() {},
mounted() {
this.echarts();
},
methods: {
echarts() {
const labelOption = {
show: true,
formatter: "{c} {name|{a}}",
fontSize: 16,
rich: {
name: {},
},
};
var robt2Chart = echarts.init(document.getElementById("rbot2main"));
let dataX = [
"1月",
"2月",
"3月",
"4月",
"5月",
];
// dataX对应的数据
// let dataA = [44, 55, 66, 46, 67, 69, 55, 66, 46, 67];
// let dataB = [44, 55, 66, 46, 67, 69, 55, 66, 46, 67];
var option = {
dataZoom: [
{
// 第一个 dataZoom 组件
type: "inside",
xAxisIndex: 0, // 表示这个 dataZoom 组件控制 第一个 xAxis
startValue: 0, // 数据窗口范围的起始数值index
endValue: 4, // 数据窗口范围的结束数值index
},
],
// 这是用于显示提示信息的配置项,通常包括悬浮在图表上时的信息提示。
tooltip: {
//提示框组件
trigger: "axis",
formatter: "{b}<br />{a0}: {c0}",
axisPointer: {
type: "shadow",
label: {
backgroundColor: "#6a7985",
},
},
},
legend: {
textStyle: {
color: "white",
},
data: ["模具总数", "黑色铸造模具", "有色铸造模具"],
},
toolbox: {
show: true,
orient: "vertical",
left: "right",
},
grid: {
show: false, //是否显示直角坐标系网格
left: "13%",
right: "10%",
bottom: "15%",
top: "15%",
// containLabel: true,
},
xAxis: [
{
type: "category",
data: dataX,
axisLabel: {
//坐标轴刻度标签的相关设置。
textStyle: {
color: "white",
fontStyle: "normal",
fontSize: 14,
fontWeight: 700,
},
rotate: 0, // 文字倾斜显示
},
axisTick: {
//坐标轴刻度相关设置。
show: false,
},
axisPointer: {
type: "shadow",
},
axisLine: {
//坐标轴轴线相关设置
lineStyle: {
color: "white",
},
},
splitLine: {
//坐标轴在 grid 区域中的分隔线。
show: false,
},
},
],
yAxis: [
{
type: "value",
axisLabel: {
textStyle: {
color: "white",
fontStyle: "normal",
fontSize: 14,
},
},
axisTick: {
show: false,
},
axisLine: {
show: true,
},
// 背景刻度线
splitLine: {
show: true,
lineStyle: {
type: "dashed", //solid实线;dashed虚线
color: "rgb(81, 82, 8,0.5)",
},
textStyle: {
color: "white",
},
},
axisLabel: {
show: true,
formatter: "{value} ",
textStyle: {
color: "white",
},
},
},
],
series: [
{
name: "黑色铸造模具",
type: "bar",
stack: "total",
barWidth: "50%", // 柱的宽度
emphasis: {
focus: "series",
},
data: [12, 7, 0,0,0],
label: {
show: true, // 开启显示
align: "center",
rotate: "0",
position: "inside",
// distance: 10, // 距离图形元素的距离。当 position 为字符描述值(如 'top'、'insideRight')时候有效。
verticalAlign: "middle",
textStyle: {
// 数值样式
color: "#333",
fontSize: 12,
},
},
},
{
name: "有色铸造模具",
type: "bar",
stack: "total",
barWidth: "50%", // 柱的宽度
emphasis: {
focus: "series",
},
data: [17, 5],
label: {
show: true, // 开启显示
align: "center",
rotate: "0",
position: "inside",
// distance: 10, // 距离图形元素的距离。当 position 为字符描述值
verticalAlign: "middle",
textStyle: {
// 数值样式
color: "#fff",
fontSize: 12,
},
},
},
{
name: "模具总数",
type: "bar",
stack: "total",
// barWidth: "50%", // 柱的宽度
// barGap: 0,
// label: labelOption,
emphasis: {
focus: "series",
},
data: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
label: {
show: true, // 开启显示
align: "center",
rotate: "0",
position: "top", // 在..显示
// distance: -5, // 距离图形元素的距离。当 position 为字符描述值(如 'top'、'insideRight')时候有效。
// verticalAlign: "middle",
textStyle: {
// 数值样式
color: "#D2CC13",
fontSize: 12,
},
formatter: (obj) => {
const datal = [29, 12];
// console.log(obj);
return datal[obj.dataIndex];
},
},
},
],
};
option && robt2Chart.setOption(option);
// 设置定时器, 每隔2s判断是否滚动到末尾, 是则重置为初始状态, 否则向前滚动一位
this.timerId = setInterval(() => {
if (option.dataZoom[0].endValue == dataX.length - 1) {
option.dataZoom[0].endValue = 4;
option.dataZoom[0].startValue = 0;
} else {
option.dataZoom[0].endValue = option.dataZoom[0].endValue + 1;
option.dataZoom[0].startValue = option.dataZoom[0].startValue + 1;
}
robt2Chart.setOption(option);
}, 2000);
},
},
//组件
components: {},
};
</script>
<style scoped lang="scss">
.dv-border-box-13 {
width: 100%;
height: 370px;
padding-top: 20px;
.dvrow {
height: 15px;
padding: 0 20px;
display: flex;
justify-content: space-between;
}
.echarts {
margin-top: 15px;
width: 100%;
height: 320px;
}
}
</style>