| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- <template>
- <div
- :class="className"
- :style="{
- height: height,
- width: width,
- background: background,
- marginRight: '16px',
- }"
- >
- <div ref="chart" class="chart"></div>
- </div>
- </template>
-
- <script>
- import echarts from "echarts";
- require("echarts/theme/macarons"); // echarts theme
- const animationDuration = 6000;
- export default {
- props: {
- className: {
- type: String,
- default: "chart",
- },
- width: {
- type: String,
- default: "100%",
- },
- height: {
- type: String,
- default: "464px",
- },
- background: {
- type: String,
- default: "#fff",
- },
- watcherList: {
- type: Array,
- default: () => [],
- },
- },
- data() {
- return {
- chart: null,
- people: [],
- quality: [],
- };
- },
- watch: {
- watcherList: function (newData, oldData) {
- if (newData !== oldData) {
- this.initChart();
- }
- },
- },
- methods: {
- initChart() {
- this.watcherList.forEach((item) => {
- this.people.push(item.watcher);
- this.quality.push(item.quality);
- });
- console.log("fithis.watcherListrst", this.watcherList);
- this.chart = echarts.init(this.$refs.chart, "macarons");
- this.chart.setOption({
- title: {
- text: "监督员质态统计",
- textStyle: {
- color: "#0F2B4C",
- },
- top: 10,
- left: 5,
- },
- tooltip: {
- trigger: "axis",
- axisPointer: {
- type: "shadow",
- },
- formatter: function (params) {
- var tar = params[0];
- return (
- "监督人:" + tar.name + "<br/>" + "质态数" + " : " + tar.value
- );
- },
- },
- xAxis: {
- type: "category",
- data: this.people,
- axisLabel: {
- rotate: 45, // 设置标签倾斜角度,单位为度
- },
- },
- yAxis: {
- type: "value",
- },
- series: [
- {
- data: this.quality,
- type: "bar",
- barWidth: "16px",
- itemStyle: {
- color: "#0147EB",
- },
- },
- ],
- });
- },
- },
- beforeDestroy() {
- if (!this.chart) {
- return;
- }
- this.chart.dispose();
- this.chart = null;
- },
- };
- </script>
-
- <style lang="scss">
- .chart {
- height: 100%;
- width: 100%;
- }
- </style>
|