I want to put an event where I click on the chart and express the color of the chart differently. To do so, chart data was processed, but the processed option did not work normally.
And after processing the data, additional SVG cannot be inserted into the chart. An error has occurred. So I've annotated it.
const getFill = (index: number) => {
if (index > 30) return "purple";
if (index > 20) return "blue";
if (index > 10) return "green";
return "red";
};
const pieData = dataList.map((value, index) => ({
value,
svg: {
fill: getFill(index)
},
key: `bar-${index}`
}));
console.log(pieData);
return (
...
<BarChart
style={{ flex: 9, width: apx(750) }}
spacingInner={0.2}
data={pieData}
gridMin={Y_AXIS_MIN}
gridMax={Y_AXIS_MAX}
// svg={{ fill: "red" }}
animate
>
{/* {pieData.map((_, i) => (
<Tooltip index={i} />
))} */}
</BarChart>
...
);
Console.log
[{"key": "bar-0", "svg": {"fill": "red"}, "value": 4000}, {"key": "bar-1", "svg": {"fill": "red"}, "value": 4000}, {"key": "bar-2", "svg": {"fill": "red"}, "value": 4000}, {"key": "bar-3", "svg": {"fill": "red"}, "value": 4000}, {"key": "bar-4", "svg": {"fill": "red"}, "value": 4000}, {"key": "bar-5", "svg": {"fill": "red"}, "value": 4000}, {"key": "bar-6", "svg": {"fill": "red"}, "value": 4000}, {"key": "bar-7", "svg": {"fill": "red"}, "value": 4000}, {"key": "bar-8", "svg": {"fill": "red"}, "value": 4000}, {"key": "bar-9", "svg": {"fill": "red"}, "value": 4000}, {"key": "bar-10", "svg": {"fill": "red"}, "value": 4000}, {"key": "bar-11", "svg": {"fill": "green"}, "value": 4000}, {"key": "bar-12", "svg": {"fill": "green"}, "value": 4000}, {"key": "bar-13", "svg": {"fill": "green"}, "value": 4000}]
Not Show Chart Screenshot
- package.json
{
"react-native-svg": "^12.1.0",
"react-native-svg-charts": "^5.4.0",
}
How can you solve this problem?