score:0

this.getChartData = this.getChartData.bind(this);

score:2

fetch("https://data.cityofnewyork.us/resource/27iv-9uub.json") 
  .then(response => response.json())
  .then(data => {
    this.setState({...});
    return data;
  })
  .catch(() => { 
    console.log("Promise Rejected"); 
  });

score:3

constructor(){
super();
this.state = {
  chartData:{},
}
}

componentDidMount(){
  this.getChartData();
}

getChartData(){
  // Ajax calls here

fetch("https://data.cityofnewyork.us/resource/27iv-9uub.json") 
  .then(response => response.json())
  .then(data => {
    // eslint-disable-next-line
    let boroughs = data.map((data) => {
      console.log(data.borough);
      return data.borough;
    })

    this.setState({
      chartData:{
        labels: boroughs,
        datasets:[
          {
            label:'Population',
            data:[
              617594,
              1810450,
              153060,
              106519,
              105162
            ],
            backgroundColor:[
              'rgba(255, 99, 132, 0.6)',
              'rgba(54, 162, 235, 0.6)',
              'rgba(255, 206, 86, 0.6)',
              'rgba(75, 192, 192, 0.6)',
              'rgba(153, 102, 255, 0.6)',
              'rgba(255, 159, 64, 0.6)'
            ]
          }
        ]
      }
    });
  })
  .catch(() => { 
    console.log("Promise Rejected"); 
  });
}

Related Query

More Query from same tag