123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144 |
- <!--
- * @Author: your name
- * @Date: 2021-10-25 16:13:34
- * @LastEditTime: 2021-10-25 16:55:38
- * @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,
- required: true
- }
- },
- data() {
- return {
- myChart: null
- }
- },
- methods: {
- init() {
- let options = {
- // title: {
- // text: '存栏变动',
- // x: 10,
- // y: 0
- // },
- tooltip: {
- trigger: 'axis',
- },
- // legend: {
- // data: ['头']
- // },
- // color: ['#3aa0ff', '#4dcb73', '#fad337', '#f2637b', '#975fe4'],
- grid: {
- top: '10%',
- left: '10%',
- bottom: '20%',
- right: '10%'
- },
- 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'
- }
- }
- }
- }
- ]
- }
- 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: 160px;
- }
- </style>
|