Skip to content
This repository was archived by the owner on Jul 19, 2019. It is now read-only.
This repository was archived by the owner on Jul 19, 2019. It is now read-only.

Uncaught TypeError: Chart is not a constructor #100

@leighghunt

Description

@leighghunt

Hi,

I'm having trouble getting this working in my project, and I'm hoping I'm missing something obvious.

When I include the dist folder in my React/Reduc project, and open a view that includes some simple example code, I'm getting the following error within the react-chart.js file on the browser:

react-chartjs.js:143 Uncaught TypeError: Chart is not a constructor

Code in question, with > next to line causing issue:


        classData.initializeChart = function(nextProps) {
          var Chart = __webpack_require__(5);
          var el = ReactDOM.findDOMNode(this);
          var ctx = el.getContext("2d");
>         var chart = new Chart(ctx)[chartType](nextProps.data, nextProps.options || {});
          this.state.chart = chart;
        };

Chart seems to be getting initialised to the literal integer value 3.

My skeletal code in the view:

...
import React, { Component } from 'react'
import { connect } from 'react-redux'
...

import { Chart } from 'Chartjs'
import { Line } from 'react-chartjs'

...

class ChartView extends Component {
...
  render() {
...
    var chartData = {
    labels: ["January", "February", "March", "April", "May", "June", "July"],
    datasets: [
        {
            label: "My First dataset",
            fillColor: "rgba(220,220,220,0.2)",
            strokeColor: "rgba(220,220,220,1)",
            pointColor: "rgba(220,220,220,1)",
            pointStrokeColor: "#fff",
            pointHighlightFill: "#fff",
            pointHighlightStroke: "rgba(220,220,220,1)",
            data: [65, 59, 80, 81, 56, 55, 40]
        },
        {
            label: "My Second dataset",
            fillColor: "rgba(151,187,205,0.2)",
            strokeColor: "rgba(151,187,205,1)",
            pointColor: "rgba(151,187,205,1)",
            pointStrokeColor: "#fff",
            pointHighlightFill: "#fff",
            pointHighlightStroke: "rgba(151,187,205,1)",
            data: [28, 48, 40, 19, 86, 27, 90]
        }
    ]
    }

    var chartOptions = {

    };

    return (
      <div id='chart'>

      <Line data={chartData} options={chartOptions} width="600" height="250"/>

      </div>
    )
  }
}

export default connect(..., ...)(ChartView)

The react-chartjs.js file being downloaded to the browser is the file created by npm run build. I think I'm missing some basic webpack step (which I'm new to) perhaps? Any pointers?

Cheers,
Leigh.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions