123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 |
- <template>
- <div class="linechart" :id="id" style="width: 100%; height: 100%"></div>
- </template>
- <script>
- export default {
- name: "lineChartTaskInfo",
- props: {
- id: {
- default: "lineChartA",
- type: String,
- },
- xList: {
- default: function () {
- return [];
- },
- type: Array,
- },
- yList: {
- default: function () {
- return [];
- },
- type: Array,
- },
- yUnit: {
- default: "",
- type: String,
- },
- },
- data() {
- return {
- tipData: [], //线数据
- showData: [], //展示数据
- charts: "",
- };
- },
- watch: {
- yList(val) {
- if (val.length > 0) {
- this.initStateList();
- }
- },
- },
- methods: {
- initStateList() {
- let xData = this.xList;
- let yData = this.yList;
- let option = {
- title: {
- text: "暂无数据",
- show: yData.length === 0,
- left: "center",
- top: "center",
- },
- tooltip: {
- //提示框,可以在全局也可以在
- trigger: "item", //提示框的样式
- formatter: "{b}: {c}",
- // formatter: function (params) {
- // if (params.value == 0) return params.name + " : 0";
- // //格式化函数
- // return params.name + " : " + params.value.toFixed(4);
- // },
- color: "#000", //提示框的背景色
- textStyle: {
- //提示的字体样式
- color: "#ffffff",
- },
- confine: true,
- },
- xAxis: {
- name: "t(s)",
- type: "category",
- boundaryGap: false,
- data: xData,
- },
- yAxis: {
- name: this.yUnit,
- },
- series: [
- {
- data: yData,
- type: "line",
- smooth: true,
- symbol: "circle",
- symbolSize: 6,
- lineStyle: {
- normal: {
- width: 1.5,
- color: "#3397FF",
- },
- },
- itemStyle: {
- normal: {
- color: "#3397FF",
- },
- },
- },
- ],
- grid: {
- top: "30px",
- left: "30px",
- right: "40px",
- 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>
|