123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169 |
- <template>
- <div :id="'chart-stark-bar-' + id" style="width: 100%; height: 100%"></div>
- </template>
- <script>
- export default {
- name: "ChartStarkBar",
- props: {
- id: {
- type: String,
- default: () => "0",
- },
- starkList: {
- type: Array,
- default: () => [],
- },
- },
- watch: {
- starkList: {
- handler(newVal) {
- if (newVal) {
- this.myChart.clear();
- this.init();
- }
- },
- deep: true,
- },
- },
- data() {
- return {
- myChart: null,
- };
- },
- methods: {
- init() {
- var time = [];
- var data1 = [];
- var data2 = [];
- var data3 = [];
- this.starkList.forEach((item) => {
- time.push(item.screateTime);
- data1.push(item.onevalue);
- data2.push(item.twovalue);
- data3.push(item.threevalue);
- });
- let start = time.length - 8;
- let end = time.length - 1;
- var option = {
- legend: {
- data: ["1号楼", "2号楼", "3号楼"],
- },
- color: ["#73C0DE", "#9A60B4", "#5470C6", "#91CB74"],
- tooltip: {
- trigger: "axis",
- },
- dataZoom: [
- {
- type: "inside",
- startValue: start,
- endValue: end,
- show: false,
- },
- ],
- xAxis: [
- {
- type: "category",
- data: time,
- axisPointer: {
- type: "shadow",
- },
- axisLine: {
- show: false,
- lineStyle: {
- color: "#6e7079",
- },
- },
- axisTick: {
- show: false,
- },
- },
- ],
- yAxis: [
- {
- type: "value",
- name: "用料统计情况",
- axisLabel: {
- formatter: "{value} 吨",
- },
- axisLine: {
- show: false,
- lineStyle: {
- color: "#6e7079",
- },
- },
- axisTick: {
- show: false,
- },
- },
- ],
- series: [
- {
- name: "1号楼",
- data: data1,
- type: "bar",
- itemStyle: {
- color: this.color,
- borderColor: this.color,
- normal: {
- label: {
- show: true,
- position: "top",
- textStyle: {
- fontSize: 14,
- },
- },
- },
- },
- },
- {
- name: "2号楼",
- data: data2,
- type: "bar",
- itemStyle: {
- color: this.color,
- borderColor: this.color,
- normal: {
- label: {
- show: true,
- position: "top",
- textStyle: {
- fontSize: 14,
- },
- },
- },
- },
- },
- {
- name: "3号楼",
- data: data3,
- type: "bar",
- itemStyle: {
- color: this.color,
- borderColor: this.color,
- normal: {
- label: {
- show: true,
- position: "top",
- textStyle: {
- fontSize: 14,
- },
- },
- },
- },
- },
- ],
- };
- this.myChart.setOption(option);
- },
- },
- mounted() {
- this.myChart = this.$echarts.init(
- document.getElementById("chart-stark-bar-" + this.id)
- );
- this.init();
- },
- };
- </script>
- <style scoped></style>
|