| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- <template>
- <view>
- <div class="chart1" ref="chart"></div>
- </view>
- </template>
-
- <script>
- import echarts from "echarts";
- export default {
- props: {
- fangQu:{
- type: Array,
- // 定义是否必须传
- required: false,
- // 定义默认值
- default: []
- },
- fangquTime:{
- type: Array,
- // 定义是否必须传
- required: false,
- // 定义默认值
- default: []
- },
- },
- mounted() {
- this.getEchartData()
- },
- watch:{
- fangQu: {
- immediate: true,
- handler(value) {
- this.fangQu = value
- this.getEchartData()
- }
- },
- },
- data() {
- return {
- }
- },
-
- methods: {
- // 折线图
- getEchartData() {
- const chart = this.$refs.chart;
- var option = null;
- const myChart = this.$echarts.init(chart);
- option = {
- legend: {
- top: 20,
- },
- xAxis: {
- type: 'category',
- data: this.fangquTime//['05-01', '05-02', '05-03', '05-04', '05-05']
- },
- yAxis: {
- type: 'value'
- },
- series: [
- {
- name: '访问量',
- data: this.fangQu,//[150, 230, 224, 218, 135, 147, 260],
- type: 'line'
- }
- ]
- };
- myChart.setOption(option);
- window.addEventListener("resize", function () {
- myChart.resize();
- });
- this.$on("hook:destroyed", () => {
- window.removeEventListener("resize", function () {
- chart.resize();
- });
- });
- return option;
- },
-
- },
-
- }
- </script>
- <style>
- .chart1 {
- width: 100%;
- height: 115%;
- display: block;
- }
- </style>
|