Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

137
Views
My react app is just not displaying the graph

I am trying to make a bar chart using react-chartjs-2. whenever I run my react app using the following code it shows a black page only. What am I doing wrong here. Here is my code for Chart.js

import React,{Component} from "react";
import { Bar } from 'react-chartjs-2';

class Chart extends Component{

    constructor(props){
        super(props);
        this.state = {
            chartData:{
              labels: ['Boston','Worcestor',
            'Springfield','Lowell','Cambridge','New bedford'],
              datasets: [
                  {
                      label: 'Population',
                      data: [
                          641712,147895,12479546,1457897,127955,98745
                      ],
                      backgroundColor: [
                        'rgba(255, 99, 132, 0.2)',
                        'rgba(54, 162, 235, 0.2)',
                        'rgba(255, 206, 86, 0.2)',
                        'rgba(75, 192, 192, 0.2)',
                        'rgba(153, 102, 255, 0.2)',
                        'rgba(255, 159, 64, 0.2)',
                        'rgba(255, 99, 131, 0.2)'
                      ]
                  }
              ]
            }
         }
    }

    render(){
        return(
            <div className="chart">
                <Bar
                    data={this.state.chartData}
                    options={{
                        maintainAspectRatio: false
                    }}
                />
            </div>
        )
    }
}

export default Chart;

And this is main App.js

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You need to add this line to your imports: import Chart from 'chart.js/auto';

See Chart.js Integration

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!