1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| const CustomSlice = (props: any) => { const {index, data} = props; console.log('data', data, index); const colors: any = { Cats: 'blue', Dogs: 'red', Birds: 'yellow' } console.log('color', colors[data[index].x]) const style = Object.assign({}, props.style, { stroke: colors[data[index].x] }); return ( <Slice {...props} style={style}/> ); } <VictoryPie labelComponent={<></>} // 不显示label style={{ data: { fillOpacity: 0, stroke: "transparent", strokeWidth: 2 }, }} dataComponent={<CustomSlice />} // 如果要自定义每一个data的样式可以这样做 data={[ { x: "Cats", y: 35 }, { x: "Dogs", y: 40 }, { x: "Birds", y: 55 } ]} />
|