123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317 |
- <template>
- <div class="linechart" :id="id" style="width: 100%; height: 100%"></div>
- </template>
- <script>
- import { mapState } from "vuex";
- export default {
- name: "lineChartCarsimA", // carsim-折线图
- props: {
- id: {
- default: "lineChartCarsimA",
- type: String,
- },
- dataList: {
- default: function () {
- return [];
- },
- type: Array,
- },
- dataListA: {
- default: function () {
- return [];
- },
- type: Array,
- },
- columns: {
- default: function () {
- return [];
- },
- type: Array,
- },
- },
- data() {
- return {
- tipData: [], //线数据
- showData: [], //展示数据
- charts: "",
- };
- },
- watch: {
- dataList: {
- handler(val) {
- if (val.length > 0) {
- this.initStateList();
- }
- },
- deep: true,
- },
- dataListA: {
- handler(val) {
- if (val.length > 0) {
- this.initStateList();
- }
- },
- deep: true,
- },
- },
- computed: {
- ...mapState(["themeColor"]),
- },
- methods: {
- initStateList() {
- let array = this.dataList;
- let array1 = this.dataListA;
- for (let index = 0; index < array.length; index++) {
- const element = array[index];
- let flag = Object.values(element).some((i) => i === "");
- if (flag) {
- let option1 = {
- title: {
- text: "暂无数据",
- show: flag,
- left: "center",
- top: "center",
- },
- tooltip: {
- //提示框,可以在全局也可以在
- trigger: "item", //提示框的样式
- formatter: "{b}: {c}",
- color: "#000", //提示框的背景色
- textStyle: {
- //提示的字体样式
- color: "#ffffff",
- },
- confine: true,
- },
- xAxis: {
- type: "category",
- boundaryGap: false,
- data: [],
- },
- yAxis: {},
- series: [
- {
- data: [],
- type: "line",
- smooth: true,
- symbol: "circle",
- symbolSize: 6,
- lineStyle: {
- normal: {
- width: 1.5,
- // color: this.themeColor,
- },
- },
- itemStyle: {
- normal: {
- // color: this.themeColor,
- },
- },
- },
- ],
- grid: {
- top: "30px",
- left: "30px",
- right: "40px",
- bottom: "10%",
- containLabel: true,
- },
- };
- this.charts.clear();
- this.charts.setOption(option1);
- return;
- }
- }
- for (let index = 0; index < array1.length; index++) {
- const element = array1[index];
- let flag = Object.values(element).some((i) => i === "");
- if (flag) {
- let option1 = {
- title: {
- text: "暂无数据",
- show: flag,
- left: "center",
- top: "center",
- },
- tooltip: {
- //提示框,可以在全局也可以在
- trigger: "item", //提示框的样式
- formatter: "{b}: {c}",
- color: "#000", //提示框的背景色
- textStyle: {
- //提示的字体样式
- color: "#ffffff",
- },
- confine: true,
- },
- xAxis: {
- type: "category",
- boundaryGap: false,
- data: [],
- },
- yAxis: {},
- series: [
- {
- data: [],
- type: "line",
- smooth: true,
- symbol: "circle",
- symbolSize: 6,
- lineStyle: {
- normal: {
- width: 1.5,
- // color: this.themeColor,
- },
- },
- itemStyle: {
- normal: {
- // color: this.themeColor,
- },
- },
- },
- ],
- grid: {
- top: "30px",
- left: "30px",
- right: "40px",
- bottom: "10%",
- containLabel: true,
- },
- };
- this.charts.clear();
- this.charts.setOption(option1);
- return;
- }
- }
- let props = ["x", "y"];
- let xData = [];
- let yData = [];
- props.forEach((j) => {
- let arr = [];
- array.forEach((i) => {
- let a = i[j] || 0;
- if (j === "x") {
- xData.push(a);
- } else {
- arr.push(a);
- }
- });
- if (j != "x") yData.push(arr);
- });
- props.forEach((j) => {
- let arr = [];
- array1.forEach((i) => {
- let a = i[j] || 0;
- if (j != "x") {
- arr.push(a);
- }
- });
- if (j != "x") yData.push(arr);
- });
- let series = [];
- let names = ["up-shifting", "down-shifting"];
- yData.forEach((i, index) => {
- series.push({
- name: names[index],
- data: i,
- type: "line",
- smooth: true,
- symbol: "circle",
- symbolSize: 6,
- lineStyle: {
- normal: {
- width: 1.5,
- // color: this.themeColor,
- },
- },
- itemStyle: {
- normal: {
- // color: this.themeColor,
- },
- },
- });
- });
- let option = {
- title: {
- text: "暂无数据",
- show: yData.length === 0,
- left: "center",
- top: "center",
- },
- tooltip: {
- //提示框,可以在全局也可以在
- trigger: "item", //提示框的样式
- formatter: "{b}: {c}",
- color: "#000", //提示框的背景色
- textStyle: {
- //提示的字体样式
- color: "#ffffff",
- },
- confine: true,
- },
- xAxis: {
- type: "category",
- boundaryGap: false,
- data: xData,
- },
- yAxis: {},
- legend: {},
- series,
- grid: {
- top: "36px",
- left: "30px",
- right: "30px",
- bottom: "10%",
- containLabel: true,
- },
- };
- this.charts.setOption(option);
- },
- },
- mounted() {
- this.charts = this.$echarts.init(document.getElementById(this.id));
- this.initStateList();
- this.$nextTick(() => {
- window.addEventListener("resize", () => {
- this.charts.resize();
- });
- });
- },
- destroyed() {
- this.charts.dispose();
- },
- };
- </script>
- <style lang='less' scoped>
- .linechart {
- margin: 0 auto;
- overflow: hidden;
- }
- </style>
|