Im kind of new to web dev and stuck at a problem when trying to visualize data using a doughnut chart from chartjs.
useEffect(() => {
const fetchAPI = async() => {
const resp = await httpClient.get("//localhost:5000/dashboard")
const data = resp.data
// console.log("From fetchapi", Object.values(data).map((crypto) => crypto.current))
const keys_list = Object.keys(data).map((crypto) => crypto)
const data_list = Object.values(data).map((crypto) => crypto.current)
//console.log(data_list)
setChartData({
labels: keys_list,
datasets: [
{
label: 'Price in KRW',
data: data_list,
backgroundColor: [
"#ffbb11",
"#ecf0f1",
"#50AF95"
]
}
]
});
};
fetchAPI()
}, []);
const [chartData, setChartData] = useState({})
return(
)
data
here looks like this
{'eth': {'available': '0.5', 'current': '890'}, 'ada': {'available': '43.9', 'current': '24'}}
so I'm trying to put data as data.current, here would be ['890', '24'] and the labels as ['eth', 'ada'] However I'm getting an Uncaught TypeError: Cannot read properties of undefined (reading 'map') error.
Any help would be highly appreciated!
