So, this is my code. I have a simple question just about how I can use the state element with indexin key? In this case I need to set the different values for different data index elements.
import React, { Component } from 'react';
import {Doughnut} from 'react-chartjs-2';
class Chart extends Component {
constructor(props) {
super(props);
this.state = {
labels: ["All", "Done", "Active"],
datasets: [{
label: "Todos",
backgroundColor: 'grey',
borderColor: 'green',
data: [0, 0, 0]
}]
};
}
getTodosList = (todos) => {
const all = [];
const active = [];
const done = [];
todos.filter(todo => {
if (todo.status === 'active') {
active.push(todo);
} else if (todo.status === 'all') {
all.push(todo);
} else if (todo.status === 'done') {
done.push(todo);
}
});
this.setState({
datasets[0].data[0]: all, // error
datasets[0].data[1]: active, // error
datasets[0].data[2]: done // error
});
}