native-echarts:柱状图渐变,圆角矩形

1、需求:

  1. 柱状图的item填充色为渐变
  2. 柱状图的item上顶角为圆角矩形

ui给出的设计图:
在这里插入图片描述
官网直接有示例,官网给出的代码:
在这里插入图片描述
rn中引入的是native-echarts,直接按照官网的例子写,new echarts.graphic.LinearGradient{}报错,
打印出来new echarts.graphic.LinearGradient:
在这里插入图片描述

2、解决:

直接定义,不用new

  series: [
                {
                    name: '用电量',
                    type: 'bar',
                    data: data,
                    barWidth: AppViewSize(25), // 柱的宽度
                    itemStyle: {
                    
                        // 一定要加normal,否则设置的color属性不生效,
                        // native-echarts设置的很多属性不生效,但是在外面包一层normal就可能生效
                        normal:{ 
                        
                            // 柱状图:圆角矩形
                            // 方向:左上、右上、右下、左下
                            barBorderRadius: [15, 15, 0, 0], 
                            color:  {
                                type: "linear",
                                x: 0,
                                y: 0,
                                x2: 0,
                                y2: 1,
                                colorStops: [
                                    { offset: 0, color: '#657BC3' }, // 0% 处的颜色 
                                    { offset: 0.5, color: '#3598FD' }, // 50% 处的颜色 
                                    {offset: 1, color: '#3598FD' }, // 100% 处的颜色
                                ],
                                global: false // 缺省为 false
                            },
                            
                            
                        }, 
                    },
                }
            ]

3、效果图

木木模拟器效果图:
在这里插入图片描述

注意

  • native-echarts:series有一些属性直接按照echarts官网文档写,有些样式不生效,可以在要设置的属性外面再套上一层normal试试
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
如果 react-native-echarts-pro 组件在 React Native 中的图表溢出容器,可以通过以下两种方法进行解决: 1.设置容器的大小 可以在容器组件中设置宽度和高度,然后将宽度和高度作为 props 传递给 react-native-echarts-pro 组件。例如: ``` import React from 'react'; import { View, Dimensions } from 'react-native'; import Echarts from 'react-native-echarts-pro'; const windowWidth = Dimensions.get('window').width; const windowHeight = Dimensions.get('window').height; export default function App() { return ( <View style={{ width: windowWidth, height: windowHeight }}> <Echarts option={option} width={windowWidth} // 设置宽度 height={windowHeight} // 设置高度 /> </View> ); } ``` 2.使用 onLayout 事件设置图表的大小 可以在 react-native-echarts-pro 组件中使用 onLayout 事件来获取容器组件的宽度和高度,然后将宽度和高度设置给图表。例如: ``` import React, { useState } from 'react'; import { View, Dimensions } from 'react-native'; import Echarts from 'react-native-echarts-pro'; export default function App() { const [chartWidth, setChartWidth] = useState(0); const [chartHeight, setChartHeight] = useState(0); const onLayout = event => { const { width, height } = event.nativeEvent.layout; setChartWidth(width); setChartHeight(height); }; return ( <View style={{ flex: 1 }} onLayout={onLayout}> <Echarts option={option} width={chartWidth} height={chartHeight} /> </View> ); } ``` 以上两种方法均可将 react-native-echarts-pro 组件的大小设置为自适应容器的大小。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值