123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- <!--
- * @Author: your name
- * @Date: 2021-10-25 16:13:34
- * @LastEditTime: 2021-12-17 08:46:16
- * @LastEditors: Please set LastEditors
- * @Description: 折线图
- * @FilePath: \hyyfScreen\src\views\Zoology\charts\ChartLine.vue
- -->
- <template>
- <div :id="'chartLine' + id" class="chart-line"></div>
- </template>
- <script>
- export default {
- props: {
- id: {
- type: Number,
- },
- data: {
- type: Object,
- },
- },
- data() {
- return {
- myChart: null,
- };
- },
- methods: {
- init() {
- let start = this.data.xAxisData.length - 7;
- let end = this.data.xAxisData.length - 1;
- let options = {
- tooltip: {
- trigger: "axis",
- },
- grid: {
- top: "8%",
- left: "15%",
- bottom: "20%",
- right: "10%",
- },
- dataZoom: [{
- type: 'inside',
- startValue: start,
- endValue: end,
- show: false
- }],
- xAxis: [
- {
- type: "category",
- // name: this.data.xAxisName,
- data: this.data.xAxisData,
- axisPointer: {
- type: "shadow",
- },
- axisLabel: {
- textStyle: {
- color: "#fff",
- },
- },
- axisLine: {
- show: true,
- lineStyle: {
- color: "rgb(0, 255, 255)",
- },
- },
- axisTick: {
- show: false,
- },
- },
- ],
- //[
- yAxis: {
- type: "value",
- // name: this.data.yAxisName,
- nameTextStyle: {
- color: "red",
- },
- axisLabel: {
- textStyle: {
- color: "#fff",
- },
- formatter: "{value}" + this.data.yAxisName,
- },
- axisLine: {
- show: true,
- lineStyle: {
- color: "rgb(0, 255, 255)",
- },
- },
- axisTick: {
- show: false,
- },
- splitLine: {
- show: false,
- },
- },
- //],
- series: [
- {
- name: this.data.xAxisName,
- type: "line",
- smooth: false,
- data: this.data.yAxisData,
- itemStyle: {
- normal: {
- color: "#3aa0ff",
- lineStyle: {
- color: "#3aa0ff",
- },
- label: {
- show: true,
- }
- },
- },
- },
- ],
- };
- this.myChart.setOption(options);
- },
- },
- mounted() {
- this.myChart = this.$echarts.init(
- document.getElementById("chartLine" + this.id)
- );
- this.init();
- },
- watch: {
- data: {
- handler(newVal) {
- if (newVal) {
- this.myChart.clear();
- this.init();
- }
- },
- deep: true,
- },
- },
- };
- </script>
- <style scoped>
- .chart-line {
- width: 100%;
- height: 100%;
- }
- </style>
|