1.柱形图表
<template>
<div class="gwtj-echart">
<div class="eachert-box" id="street-hdcs-echart"
@mouseout="mouseout"
@mouseover="mouseover"
></div>
</div>
</template>
<script>
import { getActivitiesSummary } from "@/api/module/lqdjScreen";
import * as echarts from "echarts";
export default {
name: "gwtjEchart",
data() {
return {
chartDom: null,
timgerId: null,
nowIndex: 0,
rowNameArr: [],
rowValueArr: [],
rowValueArr1:[]
};
},
props: {
unid: String,
communityName:String
},
mounted() {
this.getData();
},
methods: {
random(min, max) {
return Math.floor(Math.random() * (max - min)) + min;
},
getData() {
getActivitiesSummary({
communityName: this.communityName,
}).then((res) => {
if (res.code == 200) {
let tampArr = res.result.everyMonthActices || [];
this.rowNameArr = [];
this.rowValueArr = [];
tampArr.forEach((item) => {
// this.weekArr.push(item.counts);
this.rowNameArr.push(item.month);
this.rowValueArr.push(item.total);
// this.rowValueArr.push(this.random(1, 100));
});
// this.init(this.rowNameArr, this.rowValueArr);
this.startAnimation();
}
});
},
init(nameArr, valueArr) {
this.chartDom = echarts.init(document.getElementById("street-hdcs-echart"));
const option = {
title: {
text: "",
},
tooltip: {
trigger: "axis",
axisPointer: {
type: "shadow",
},
},
legend: {
data: ["活动次数"],
top: "5%",
right: "5%",
orient: "horizontal",
textStyle: {
fontSize: 12,
fontWeight: 400,
color: "#fff",
},
},
grid: {
left: "3%",
right: "4%",
bottom: "3%",
containLabel: true,
},
xAxis: {
type: "value",
// boundaryGap: [0, 0.01],
axisLine: {
lineStyle: {
color: "#fff",
},
},
splitLine: {
show: false,
},
},
yAxis: {
type: "category",
data: nameArr,
axisLine: {
lineStyle: {
color: "#fff",
},
},
splitLine: {
show: false,
}
},
series: [
{
name: "组织活动次数",
type: "bar",
data: valueArr,
// color: "#0263FF",
itemStyle: {
normal: {
color: new echarts.graphic.LinearGradient(
0, 0, 1, 0,
[
{offset: 0, color: '#df2c1e'}, //柱图渐变色
{offset: 0.5, color: '#e9713d'}, //柱图渐变色
{offset: 1, color: '#f7cc66'}, //柱图渐变色
]
)
}
}
}
],
};
this.chartDom.setOption(option);
window.addEventListener("resize", () => {
this.chartDom.resize();
});
this.chartDom.on("click", (params) => {
console.log(params);
this.$router.push({
path: "/bigScreen/communityBig",
query: {
communityName: params.name,
isFull:this.isFull
},
});
});
},
mouseover() {
clearInterval(this.timgerId);
},
mouseout() {
this.startAnimation();
},
startAnimation() {
//初始化图表
// this.nowIndex = 8;
var that=this;
let tampNameArr = [];
let tampValueArr = [];
this.rowNameArr.forEach((item, index) => {
tampNameArr.push(item);
tampValueArr.push(this.rowValueArr[index]);
});
this.init(tampNameArr, tampValueArr);
//开启定时任务
clearInterval(this.timgerId);
that.timgerId = setInterval(() => {
tampNameArr.shift();
tampValueArr.shift();
tampNameArr.push(that.rowNameArr[this.nowIndex]);
tampValueArr.push(that.rowValueArr[this.nowIndex]);
that.nowIndex++;
if (that.nowIndex >= that.rowNameArr.length) {
that.nowIndex = 0;
}
that.chartDom.setOption({
yAxis: [
{
data: tampNameArr,
},
],
series: [
{
data: tampValueArr,
},
],
});
}, 2000);
},
},
};
</script>
<style lang="less" scoped>
.gwtj-echart {
width: 100%;
height: 100%;
position: relative;
.eachert-box {
position: absolute;
width: 90%;
height: 90%;
top: 0;
left: 0;
}
}
</style>
```javascript
在这里插入代码片
2.线型图表
<template>
<div class="gwtj-echart">
<div class="eachert-box" id="gwtj-echart"></div>
</div>
</template>
<script>
import { getybdyNum } from "@/api/module/lqdjScreen";
import * as echarts from "echarts";
export default {
name: "gwtjEchart",
data() {
return {
chartDom: null,
timgerId: null,
nowIndex: 2,
rowNameArr: [],
rowValueArr: [],
};
},
props: {
unid: String,
},
mounted() {
this.getData();
},
methods: {
getData() {
getybdyNum({
areaUnid: this.unid,
}).then((res) => {
if (res.code == 200) {
let tampArr = res.result || [];
this.rowNameArr = [];
this.rowValueArr = [];
tampArr.forEach((item) => {
this.rowNameArr.push(item.title);
this.rowValueArr.push(item.value.number);
});
// this.init(this.nameArr, this.valueArr);
this.startAnimation();
}
});
},
init(nameArr, valueArr) {
this.chartDom = echarts.init(document.getElementById("gwtj-echart"));
const option = {
color: ["#ef7100", "#64c06c", "#f4cd49", "#e05667", "#8c5fe8"],
tooltip: {
backgroundColor: "#033b77",
borderColor: "#ef7100",
textStyle: {
color: "#fff",
fontSize: 13,
},
trigger: "item",
formatter: "{b0}:{c0}人",
},
xAxis: [
{
type: "category",
boundaryGap: false,
data: nameArr,
axisLabel: {
overflow: "break",
width: 80,
show: true,
interval: 0,
},
axisLine: {
lineStyle: {
color: "#fff",
},
},
},
],
yAxis: [
{
type: "value",
color: "#fff",
axisLine: {
lineStyle: {
color: "#fff",
},
},
splitLine: {
show: false,
},
},
],
series: [
{
type: "line",
areaStyle: {
normal: {
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
{
offset: 0,
color: "rgba(229,56,0 , 0.4)",
},
{
offset: 1,
color: "rgba(248,152,5, 0.4)",
},
]),
},
},
barGap: 0,
// label: labelOption,
emphasis: {
focus: "series",
},
data: valueArr,
},
],
};
this.chartDom.setOption(option);
window.addEventListener("resize", () => {
this.chartDom.resize();
});
},
startAnimation() {
//初始化图表
this.nowIndex = 3;
let tampNameArr = [];
let tampValueArr = [];
this.rowNameArr.forEach((item, index) => {
if (index < this.nowIndex) {
tampNameArr.push(item);
tampValueArr.push(this.rowValueArr[index]);
}
});
this.init(tampNameArr, tampValueArr);
//开启定时任务
clearInterval(this.timgerId);
this.timgerId = setInterval(() => {
tampNameArr.shift();
tampValueArr.shift();
tampNameArr.push(this.rowNameArr[this.nowIndex]);
tampValueArr.push(this.rowValueArr[this.nowIndex]);
this.nowIndex++;
if (this.nowIndex >= this.rowNameArr.length) {
this.nowIndex = 0;
}
this.chartDom.setOption({
xAxis: [
{
data: tampNameArr,
},
],
series: [
{
data: tampValueArr,
},
],
});
}, 2000);
},
},
beforeDestroy() {
clearInterval(this.timgerId);
},
};
</script>
<style lang="less" scoped>
.gwtj-echart {
width: 100%;
height: 100%;
position: relative;
.eachert-box {
position: absolute;
width: 100%;
height: 110%;
top: 0;
left: 0;
}
}
</style>
3.饼状图表
<template>
<div class="kq-echart">
<div
class="eachert-box"
id="kq-echart"
@mouseout="mouseout"
@mouseover="mouseover"
></div>
</div>
</template>
<script>
import moment from "moment";
import { getDyStatus } from "@/api/module/lqdjScreen";
import * as echarts from "echarts";
export default {
name: "kqEchart",
data() {
return {
nowIndex: 0,
timer: null,
chartDom: null,
};
},
mounted() {
this.getData();
},
methods: {
getData() {
getDyStatus({
dkrq: moment().format("YYYY-MM-DD"),
}).then((res) => {
if (res.code == 200) {
let tampArr = res.result || [];
let data = [];
tampArr.forEach((item) => {
data.push({
value: item.value.number,
name: item.title,
});
});
this.init(data);
}
});
},
init(data) {
this.chartDom = echarts.init(document.getElementById("kq-echart"));
const option = {
color: [
"#fc7b04",
"#FF7D00",
"#8781D7",
"#FFC83B",
"#FFA800",
"#c11200",
"#1304D3",
"#c11200",
],
tooltip: {
backgroundColor: "#033b77",
borderColor: "#21f2c4",
textStyle: {
color: "#fff",
fontSize: 13,
},
trigger: "item",
formatter: "{b0}:{d}%",
},
legend: {
top: "center",
left: "10%",
orient: "vertical",
textStyle: {
color: "#fff",
},
},
series: [
{
name: "考勤",
type: "pie",
top: "20",
left: "30%",
radius: ["40%", "70%"],
avoidLabelOverlap: false,
label: {
show: false,
position: "center",
},
emphasis: {
itemStyle: {
shadowColor: "rgba(255, 255, 255, 0.9)",
shadowBlur: 20,
},
label: {
show: true,
fontSize: "18",
fontWeight: "bold",
color: "#fff",
formatter: "{b}\n{c}人",
},
},
labelLine: {
show: false,
},
data: data,
},
],
};
this.chartDom.setOption(option);
this.chartDom.dispatchAction({
type: "highlight",
seriesIndex: 0,
dataIndex: this.nowIndex,
});
clearInterval(this.timer);
this.timer = setInterval(() => {
this.chartDom.dispatchAction({
type: "downplay",
seriesIndex: 0,
dataIndex: [0, 1, 2, 3],
});
this.nowIndex++;
if (this.nowIndex > 3) {
this.nowIndex = 0;
}
this.chartDom.dispatchAction({
type: "highlight",
seriesIndex: 0,
dataIndex: this.nowIndex,
});
}, 3000);
window.addEventListener("resize", () => {
this.chartDom.resize();
});
},
mouseover() {
this.chartDom.dispatchAction({
type: "downplay",
seriesIndex: 0,
dataIndex: [0, 1, 2, 3],
});
clearInterval(this.timer);
},
mouseout() {
this.chartDom.dispatchAction({
type: "highlight",
seriesIndex: 0,
dataIndex: this.nowIndex,
});
this.timer = setInterval(() => {
this.chartDom.dispatchAction({
type: "downplay",
seriesIndex: 0,
dataIndex: [0, 1, 2, 3],
});
this.nowIndex++;
if (this.nowIndex > 3) {
this.nowIndex = 0;
}
this.chartDom.dispatchAction({
type: "highlight",
seriesIndex: 0,
dataIndex: this.nowIndex,
});
}, 3000);
},
},
beforeDestroy() {
clearInterval(this.timer);
},
};
</script>
<style lang="less" scoped>
.kq-echart {
width: 100%;
height: 100%;
position: relative;
.eachert-box {
width: 100%;
height: 100%;
}
}
</style>