vue移动端中使用echart折线面积图(设置渐变色)解决ios6/11渐变色不显示bug

本文介绍了如何在ECharts中实现折线图和区域图的渐变色效果,包括线本身的渐变和阴影面积渐变,提供了Vue全局引入和单页面引入的代码示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

前言:

1.折线本身渐变色
2.折线阴影面积渐变色

效果如图所示:

在这里插入图片描述

在这里插入图片描述

1.全局引入echart
main.js

// 如果全局引入就在此加上这两行代码
// 如果就一个页面直接页面引入完事儿 import echarts from 'echarts';
// import * as echarts from 'echarts';
import echarts from 'echarts';
Vue.prototype.$echarts = echarts;

index.vue

series: [
  {
   name: '折线呀',
   type: 'line',
   data: [1,2,3,4,5],
   smooth: true,
   showSymbol: false,
   // 核心 
   //此处color如果使用rgba一定要写透明度参数,否则ios6/11下,会导致图表不展示
   areaStyle: { //渐变面积图
     color: new this.$echarts.graphic.LinearGradient(0, 0, 0, 1, [
       {offset: 0, color: 'rgb(82, 210, 196)'},
       {offset: 1, color: 'rgb(255, 255, 255)'}
     ]),
   },
   itemStyle:{//线本身渐变图
	  normal:{
	    color: {
	      type: 'linear',
	      x: 0,
	      y: 0,
	      x2: 0,
	      y2: 1,
	      colorStops: [{
	        offset: 0, color: 'red' // 0% 处的颜色
	      }, {
	        offset: 1, color: 'blue' // 100% 处的颜色
	      }],
	      global: false // 缺省为 false
	    }
	  }
	},
]

2.单页面引入echart.vue

// 单页直接引入 重要
import echarts from 'echarts';

series: [
  {
   name: '折线呀',
   type: 'line',
   data: [1,2,3,4,5],
   smooth: true,
   showSymbol: false,
    // 核心 
   //此处color如果使用rgba一定要写透明度参数,否则ios6/11下,会导致图表不展示
   areaStyle: {
     color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
       {offset: 0, color: 'rgb(82, 210, 196)'},
       {offset: 1, color: 'rgb(255, 255, 255)'}
     ]),
   },
   itemStyle:{//线本身渐变图
	  normal:{
	    color: {
	      type: 'linear',
	      x: 0,
	      y: 0,
	      x2: 0,
	      y2: 1,
	      colorStops: [{
	        offset: 0, color: 'red' // 0% 处的颜色
	      }, {
	        offset: 1, color: 'blue' // 100% 处的颜色
	      }],
	      global: false // 缺省为 false
	    }
	  }
	},
]

完整代码

<div id="line" style="width: 100%;height:200px;"></div>
import echarts from 'echarts';

lineChart() {
   let myChart = echarts.init(document.getElementById('line'));
   let option = {
     tooltip: {
       trigger: 'axis',
     },
     grid: {
       left: '0',
       right: '0',
       bottom: '10',
       top:'20',
       containLabel: true
     },
     xAxis: [
       {
         type: 'category',
         // boundaryGap: false,
         data: [1,2,3,4,5],
         splitLine: {
           show: false,
         },
         axisLine: {
           lineStyle: {
             type: 'solid',
             color: '#E6E7EC',//左边线的颜色
             width:'1'//坐标线的宽度
           }
         },
         axisLabel: {
           textStyle: {
             color: '#B8CED6',//坐标值得具体的颜色
           }
         }
       }
     ],
     yAxis: [
       {
         type: 'value',
         minInterval:1,
         splitLine: {
           show: true,
           lineStyle:{
             type:'dashed'
           }
         },
         axisLine: {
           lineStyle: {
             type: 'solid',
             color: '#E6E7EC',//左边线的颜色
             width:'1'//坐标线的宽度
           }
         },
         axisLabel: {
           textStyle: {
             color: '#B8CED6',//坐标值得具体的颜色
           }
         }
       }
     ],
     color: 'rgba(37, 190, 171, 1)',
     series: [
       {
         name: '',
         type: 'line',
         data: [2.3.4,6,7],
         smooth: true,
         showSymbol: false,
         areaStyle: {
           color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
             {offset: 0, color: 'rgb(82, 210, 196)'},
             {offset: 1, color: 'rgb(255, 255, 255)'}
           ]),
         },
         // itemStyle:{
         //   normal:{
         //     color: {
         //       type: 'linear',
         //       x: 0,
         //       y: 0,
         //       x2: 0,
         //       y2: 1,
         //       colorStops: [{
         //         offset: 0, color: 'red' // 0% 处的颜色
         //       }, {
         //         offset: 1, color: 'blue' // 100% 处的颜色
         //       }],
         //       global: false // 缺省为 false
         //     }
         //   }
         // }
       }
     ]
   }
   // 使用刚指定的配置项和数据显示图表。
   myChart.setOption(option);
   myChart.dispatchAction({ //设置激活第一个选项
     type: 'showTip',
     seriesIndex: 0,
     dataIndex: 0
   });
 },

备注:
樱花开了,梦幻啊。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

刘斩仙的笔记本

富贵险中求

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值