0

I have this object 'cp'. and it has got some properties like labels and arcSettings in it. Whenever i initialize this object and call the method 'graph()' it says

Uncaught TypeError: Cannot read property '0' of undefined 

Am I doing something wrong?

function cp() {             
        this.labels = [{
            "pointThickness": 0.8,
            "distance": 8,
            "textDistance": 7,
            "strokeColor": "#888",
            "strokeWidth": 0.5,
            "textColor": "#777",
            "pointColor": "#888",
            "textSize": 4,
            //"interval":100,
            //"precision":2,
            "num": 10,
            "startValue": 0,
            "endValue": 300
        }
        ];

        this.arcSettings = [
            {
               "totalArcAngle":300,
                "startAngle":(-this.totalArcAngle/2),
                "endAngle":(this.totalArcAngle/2),
                "progressValue":200,
                "radius":150,
                "thickness":30,
                "displayValue":this.progressValue
            }
        ];                   
}

cp.prototype.getOneUnit = function () {
    return oneUnit = (this.arcSettings[0].totalArcAngle) / (this.label[0].endValue - this.label[0].startValue);

}

cp.prototype.graph= function(){                     
var oneUnit = this.getOneUnit();

}

var cp = new cp();
cp.graph();

3 Answers 3

2

In the cp.prototype.getOneUnit function, you are using this.label. Instead, it should be this.labels.

cp.prototype.getOneUnit = function () {
    return oneUnit = (this.arcSettings[0].totalArcAngle) / (this.labels[0].endValue - this.labels[0].startValue);
}
Sign up to request clarification or add additional context in comments.

Comments

2

At first make an instance of the object

var cp = new cp();

Then add methods/properties into prototype

cp.prototype.graph= function(){ }

Also, you have used same name in both Class/Function declaration and object instance variable. You may change function cp() to function Cp().

Comments

1

You just made a typo. You wrote label instead of labels.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.