title: ReactJS - Loading data using Axios + chartjs
body: <p>I'm learing react and I'm creating app using react,axios and chartjs. I would like use data from axios to create chart but data load after chart creating. The same problem occurs when I update chart. </p>
  
  <p>To create chart I'm using: <code>document.getElementById('myChart').getContext('2d')</code> so I cant't wait with render to finish data loading.</p>
  
  <p>In componentWillMount() I'm loading data using getDataFromServer() so I thought the chart would be created with these data.</p>
  
  <p>In componentDidMount() I'm creating my chart.</p>
  
  <pre><code>componentDidMount() {
      this.state.mainCtx = document.getElementById('myChart').getContext('2d');
      this.state.mainChart = new Chart(this.state.mainCtx, {
          type: 'line',
          data: {
              labels: this.state.tempsMonthLabels,
              datasets: [{
                  label: "My First dataset",
                  borderColor: 'rgb(255, 99, 132)',
                  data: [0, 10, 5, 2, 20, 30, 35, 3],
              }]
          },
          options: {
              title: {
                  display: true,
                  text: 'Custom Chart Title'
              }
          }
      });}
  
  
  getDataFromServer(month) {
      axios.get('http://localhost:8080/avgTempsMonth/'.concat(month))
          .then(res =&gt; {
              const tempsMonth = res.data;
              this.setState({ tempsMonth });
              const tempsMonthLabels = []; 
              //
              ..converting data to tempsMonthLabels
              //
              this.setState({ tempsMonthLabels });
              this.setState({ isLoading: false });
          })
  }
  
  handleChange = event =&gt; {
      this.state.currentMonth = event;
      this.getMonthTempsFromServer(event); 
      this.state.mainChart.data.labels = this.state.tempsMonthLabels; 
      this.state.mainChart.update();
  }
  </code></pre>
  
  <p>What can I do to load the data before creating chart?
  Thanks for avdice.</p>