echart实现天气预报

用的是腾讯天气预报的接口,vue项目需要代理,如果接口请求通了,图片不显示,在html页面加上<meta name="renderer" content="webkit" />标签

https://i.news.qq.com/weather/common?source=pc&weather_type=observe|forecast_1h|forecast_24h|index|alarm|limit|tips|rise&province=浙江省&city=宁波市&county=

echart实现部分 

 <div id="main" style="width: 100%; height:450px;"></div>

let myChart= ref(null);
var option;
function initEchart(){
   //销毁
   if(myChart.value){
      myChart.value.dispose();
   }
   myChart.value = echarts.init(document.getElementById('main'));
   
 option = {
        grid: {
         //  show: true,
         //  backgroundColor: 'transparent',
         //  opacity: 0.3,
         //  borderWidth: '0',
            top: '130',
            left:30,
            right:30,
           bottom: '0'
        },
        tooltip: {
          trigger: 'axis'
        },
        legend: {
          show: false
        },
        xAxis: [
          // 日期
          {
            type: 'category',
            boundaryGap: false,
            position: 'top',
            offset: 100,
            //zlevel: 100,
            axisLine: {
              show: false,
               lineStyle: {
                  color:'#2B2B2B'
               }
            },
            axisTick: {
              show: false
            },
            // axisLabel: {
            //   interval: 0,
            //   formatter: [
            //     '{a|{value}}'
            //   ].join('\n'),
            //   rich: {
            //     a: {
            //       // color: 'white',
            //       fontSize: 18
            //     }
            //   }
            // },
            // nameTextStyle: {

            // },
            data: ["25日","26日","27日","28日","29日","30日","31日"]
          },
          // 星期
          {
            type: 'category',
            boundaryGap: false,
            position: 'top',
            offset: 80,
           // zlevel: 100,
            axisLine: {
              show: false,
              lineStyle: {
                  color:'#2B2B2B'
               }
            },
            axisTick: {
              show: false
            },
            axisLabel: {
              interval: 0,
              formatter: [
                '{a|{value}}'
              ].join('\n'),
              rich: {
                a: {
                  // color: 'white',
                  fontSize: 14
                }
              }
            },
            nameTextStyle: {
              fontWeight: 'bold',
              fontSize: 19
            },
            data: ["周一","周二","周三","周四","周五","周六","周日"]
          },
          // 天气图标
          {
            type: 'category',
            boundaryGap: false,
            position: 'top',
            offset: 40,
            //zlevel: 100,
            axisLine: {
              show: false,
              lineStyle: {
                  color:'#2B2B2B'
               }
            },
            axisTick: {
              show: false
            },
            axisLabel: {
              interval: 0,
              formatter: function(value, index) {
                return '{' + index + '| }\n{b|' + value + '}'
              },
              rich: {
                0: {
                  backgroundColor: {
                    // image: require('@/assets/weather_icon/' + this.weatherIconDic[this.weatherdata.weather[0]] + '.png')
                    image: 'https://d.scggqx.com/forecast/img/小雨.png'
                  },
                    height: 30,
                  width: 30
                },
                1: {
                  backgroundColor: {
                    // image: require('@/assets/weather_icon/' + this.weatherIconDic[this.weatherdata.weather[1]] + '.png')
                    image: 'https://d.scggqx.com/forecast/img/小雨.png'
                  },
                    height: 30,
                  width: 30
                },
                2: {
                  backgroundColor: {
                    // image: require('@/assets/weather_icon/' + this.weatherIconDic[this.weatherdata.weather[2]] + '.png')
                    image: 'https://d.scggqx.com/forecast/img/阴.png'
                  },
                   height: 30,
                  width: 30
                },
                3: {
                  backgroundColor: {
                    // image: require('@/assets/weather_icon/' + this.weatherIconDic[this.weatherdata.weather[3]] + '.png')
                    image: 'https://d.scggqx.com/forecast/img/小雨.png'
                  },
                    height: 30,
                  width: 30
                },
                4: {
                  backgroundColor: {
                    // image: require('@/assets/weather_icon/' + this.weatherIconDic[this.weatherdata.weather[4]] + '.png')
                    image: 'https://d.scggqx.com/forecast/img/多云.png'
                  },
                    height: 30,
                  width: 30
                },
                5: {
                  backgroundColor: {
                    // image: require('@/assets/weather_icon/' + this.weatherIconDic[this.weatherdata.weather[5]] + '.png')
                    image: 'https://d.scggqx.com/forecast/img/小雨.png'
                  },
                    height: 30,
                  width: 30
                },
                6: {
                  backgroundColor: {
                    // image: require('@/assets/weather_icon/' + this.weatherIconDic[this.weatherdata.weather[6]] + '.png')
                    image: 'https://d.scggqx.com/forecast/img/小雨.png'
                  },
                   height: 30,
                  width: 30
                },
               //  b: {
               //    // color: 'white',
               //    fontSize: 12,
               //    lineHeight: 30,
               //    height: 20
               //  }
              }
            },
            // nameTextStyle: {
            //   fontWeight: 'bold',
            //   fontSize: 19
            // },
            // data: this.weatherdata.weather
            data: ["小雨","小雨","阴","小雨","多云","小雨","小雨"]
          },
         {
            type: 'category',
            boundaryGap: false,
            position: 'top',
            offset: 10,
            axisLine: {
              show: false,
              lineStyle: {
                  color:'#2B2B2B'
               }
            },
            axisTick: {
              show: false
            },
            data: ["西风1-3","东北风1-3","西风1-3","西风1-3","西风1-3","西风1-3","西风1-3"]
          },
          {
            type: 'category',
            boundaryGap: false,
            position: 'bottom',
            offset: -150,
            axisLine: {
              show: false,
              lineStyle: {
                  color:'#2B2B2B'
               }
            },
            axisTick: {
              show: false
            },
            data: ["西风1-3","东北风1-3","西风1-3","西风1-3","西风1-3","西风1-3","西风1-3"]
          },
          // 天气图标
          {
            type: 'category',
            boundaryGap: false,
            position: 'bottom',
            offset: -200,
            //zlevel: 100,
            axisLine: {
              show: false,
              lineStyle: {
                  color:'#2B2B2B'
               }
            },
            axisTick: {
              show: false
            },
            axisLabel: {
              interval: 0,
              formatter: function(value, index) {
                return '{' + index + '| }\n{b|' + value + '}'
              },
              rich: {
                0: {
                  backgroundColor: {
                    // image: require('@/assets/weather_icon/' + this.weatherIconDic[this.weatherdata.weather[0]] + '.png')
                    image: 'https://d.scggqx.com/forecast/img/小雨.png'
                  },
                   height: 30,
                  width: 30
                },
                1: {
                  backgroundColor: {
                    // image: require('@/assets/weather_icon/' + this.weatherIconDic[this.weatherdata.weather[1]] + '.png')
                    image: 'https://d.scggqx.com/forecast/img/小雨.png'
                  },
                    height: 30,
                  width: 30
                },
                2: {
                  backgroundColor: {
                    // image: require('@/assets/weather_icon/' + this.weatherIconDic[this.weatherdata.weather[2]] + '.png')
                    image: 'https://d.scggqx.com/forecast/img/阴.png'
                  },
                   height: 30,
                  width: 30
                },
                3: {
                  backgroundColor: {
                    // image: require('@/assets/weather_icon/' + this.weatherIconDic[this.weatherdata.weather[3]] + '.png')
                    image: 'https://d.scggqx.com/forecast/img/小雨.png'
                  },
                   height: 30,
                  width: 30
                },
                4: {
                  backgroundColor: {
                    // image: require('@/assets/weather_icon/' + this.weatherIconDic[this.weatherdata.weather[4]] + '.png')
                    image: 'https://d.scggqx.com/forecast/img/多云.png'
                  },
                    height: 30,
                  width: 30
                },
                5: {
                  backgroundColor: {
                    // image: require('@/assets/weather_icon/' + this.weatherIconDic[this.weatherdata.weather[5]] + '.png')
                    image: 'https://d.scggqx.com/forecast/img/小雨.png'
                  },
                   height: 30,
                  width: 30
                },
                6: {
                  backgroundColor: {
                    // image: require('@/assets/weather_icon/' + this.weatherIconDic[this.weatherdata.weather[6]] + '.png')
                    image: 'https://d.scggqx.com/forecast/img/小雨.png'
                  },
                  height: 30,
                  width: 30
                },
               //  b: {
               //    // color: 'white',
               //    fontSize: 12,
               //    lineHeight: 30,
               //    height: 20
               //  }
              }
            },
            // nameTextStyle: {
            //   fontWeight: 'bold',
            //   fontSize: 19
            // },
            // data: this.weatherdata.weather
            data: ["小雨","小雨","阴","小雨","多云","小雨","小雨"]
          },
        ],
        yAxis: {
          type: 'value',
          show: false,
         //  axisLabel: {
         //    formatter: '{value} °C',
         //    color: 'white'
         //  }
        },
        series: [
          {
            name: '最高气温',
            type: 'line',
            data: ["16.3","16.2","17.6","14.2","17.6","15.7","14.3"],
            symbol: 'emptyCircle',
            symbolSize: 10,
            showSymbol: true,
            smooth: true,
            itemStyle: {
              normal: {
                color: 'green'
              }
            },
            label: {
              show: true,
              position: 'top',
              // color: 'white',
              formatter: '{c} °C'
            },
            // lineStyle: {
            //   width: 1,
            //   // color: 'white'
            // },
            // areaStyle: {
            //   opacity: 1,
            //   color: 'transparent'
            // }
          },
          {
            name: '最低气温',
            type: 'line',
            data: ["13.4","12.8","13.5","12.5","12.4","13.2","13"],
            symbol: 'circle',
            symbolSize: 10,
            showSymbol: true,
            smooth: true,
            itemStyle: {
              normal: {
                color: 'blue'
              }
            },
            label: {
              show: true,
              position: 'bottom',
              // color: 'white',
              formatter: '{c} °C'
            },
            // lineStyle: {
            //   width: 1,
            //   // color: 'white'
            // },
            // areaStyle: {
            //   opacity: 1,
            //   color: 'transparent'
            // }
          }
        ]
      }

   myChart.value.setOption(option);
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值