0👍
for one, fetch
is asynchronous, so you have to wait for it to finish.
which is why you have then
methods.
however, you’re trying to sort keyz
before keyz
has any data.
move the sort function into the then
method,
after wordCount
where keyz
is filled.
and calling compare
on its own, does nothing…
// Fetch JSON file locally and return the data
fetch('../test_feed.json')
.then(res => res.json())
.then(data => {
handleTweetText(data)
wordCount()
keyz.sort(compare)
createChart()
})
.catch(err => console.error(err));
but typically, you don’t use the same data for both labels
and data
in the chart.
is it possible you meant to use counts
for data
in the chart?
- Chartjs-How to dynamically update data of line chart used with chart Js?
- Chartjs-PrimeFaces: ChartJs stacked bar chart label removal
Source:stackexchange.com