typescript + echarts-for-react 制作渐变柱状图, 提示[ts] 类型“Graphic”上不存在属性“LinearGradient”...

 

更新: 2019/03 无意间发现Graphic上已有 LinearGradient属性 ???

 

效果如图: 是不是比较炫~

遇到的问题:@types/echart 到目前只到 v4.1.1,类型“Graphic”上没有 LinearGradient属性

tslint提示:color: new echarts.graphic中没有LinearGradient属性
 
, ,,, 不支持那渐变还怎么显示出来呢,无奈,只有搬出
// @ts-ignore
让它跳过类型检查啦,真的希望echarts团队赶紧把这个属性定义一下,总感觉这么暴力的方式不优雅哈哈~
// 1. 引入模块

import ReactEcharts from 'echarts-for-react'

import * as echarts from 'echarts' 
// 2. 配置

get option() { const dataAxis
= ['10,20', '10.21', '10.22'] const chartsCost = [100, 200, 300] return { dataZoom: [ { type: 'inside', }, ], grid: {}, series: [ { animation: false, barCategoryGap: '40%', barGap: '-100%', data: dataAxis, itemStyle: { normal: { color: '#000' }, }, type: 'bar', }, { data: chartsCost, itemStyle: { emphasis: { barBorderRadius: 20, // @ts-ignore color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [ { offset: 0, color: 'rgba(215,59,255,1)' }, { offset: 0.5, color: 'rgba(66,70,175,1)' }, ]), }, normal: { barBorderRadius: [3, 3, 0, 0], // @ts-ignore color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [ { offset: 0, color: 'rgba(215,59,255,1)' }, { offset: 0.6, color: 'rgba(66,70,175,1)' }, ]), }, }, type: 'bar', }, ], xAxis: { axisLabel: { textStyle: { color: 'rgba(136,58,253,1)', }, }, axisLine: { show: true, }, axisTick: { show: true, }, data: dataAxis, name: '日期', nameTextStyle: { color: 'rgba(136,58,253,1)', }, z: 10, }, yAxis: { axisLabel: { textStyle: { color: 'rgba(136,58,253,1)', }, }, axisLine: { show: false, }, axisTick: { show: false, }, name: '投放额', nameTextStyle: { color: 'rgba(136,58,253,1)', }, splitLine: { lineStyle: { color: 'rgba(136,58,253,.2)', }, show: true, }, }, } }
   // 3. 调用echarts-for-react 
<ReactEcharts option={this.option} notMerge={true} lazyUpdate={true} style={{ height: '100%' }} />

 

转载于:https://www.cnblogs.com/aloehui/p/9858323.html

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值