Home forums Using CanvasJS Uncaught TypeError: Cannot read property 'getTime' of undefined

This topic contains 5 replies, has 5 voices, and was last updated by  linehammer 4 months, 3 weeks ago.

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #17760

    I am facing an issue when updating the datapoints of canvas chart, and the error message says “Uncaught TypeError: Cannot read property ‘getTime’ of undefined”. Below is my html (I am making ajax call to update the datapoints)

    <html>
    <head>
    <script type="text/javascript">
        function GetGraph(val) {
            $("#dialogOpen").dialog({
                autoOpen: false,
                modal: true,
                title: "Graph"
            });
            $.ajax({
                type: 'POST',
                url: '/Ranking/ReturnKeywordGraph',
                contentType: "application/json; charset=utf-8",
                dataType: 'html',
                data: '{keywordId: "' + val + '" }'
            }).success(function (response) {
                //$('#dialogOpen').html(response);
    
                var chart = new CanvasJS.Chart("chartContainer",
                {
                    title: {
                    },
                    animationEnabled: true,
                    axisX: {
                        interval: 3
                    },
                    axisY: {
                    },
                    legend: {
                        verticalAlign: "bottom",
                        horizontalAlign: "center"
                    },
                    data: [{
                        name: "Graph Overview",
                        showInLegend: true,
                        legendMarkerType: "square",
                        type: "area",
                        color: "#0990B0",
                        markerSize: 0,
                        dataPoints: [
                                        response
                        ]
                    }]
                });
    
                chart.render();
                $('#dialogOpen').dialog('open');
            }).error(function (response) {
                $('#dialogOpen').html(response.responseText);
                $('#dialogOpen').dialog('open');
            });
        }
    </script>
    </head>
    <body>
    <div id="dialogOpen" style="display: block; width:100%;">
                            <div id="chartContainer" style="height: 289px; width: 100%;">
                            </div>
                        </div>
    </body>
    </html>

    The output I receive in response is “{x: new Date(2017, 10, 20),y: 10},{x: new Date(2017, 10, 17),y: 15},” which when replaced with “response” renders the chart successfully. But passing response to datapoints gives the error.

    Any help ????

    #17818

    @mudassir,

    dataPoints is an array of objects. Seems like you are passing a string
    ("{x: new Date(2017, 10, 20),y: 10},{x: new Date(2017, 10, 17),y: 15}") to it instead of an object. You need to parse your data and convert it to object.

    If this doesn’t suit your requirements, Can you please create a jsfiddle, along with your sample data, reproducing the issue?

    ___
    Suyash Singh
    Team CanvasJS

    #17837

    @Suyash Singh
    Thanks mate, I got it working, thanks for the helping response.

    #24100

    Hi Mudassir
    I am facing same problem,can u tell me how did it worked

    #24132

    @savnur-imran,

    You’ll be able to render the chart by passing valid dataPoints. Seems like you are passing a string to dataPoint array instead of an object. In case you’re fetching the data from JSON data source, parse the received data to the format accepted by CanvasJS.

    In case you’re still facing the issue, can you please create a JSFiddle reproducing the issue so that we can look into it and help you out?

    ____
    Shashi Ranjan
    Team CanvasJS

    #25332

    This error occurs in Chrome Browser when you read a property or call a method on an undefined object . Uncaught TypeError: Cannot read property of undefined error is probably easiest to understand from the perspective of undefined, since undefined is not considered an object type at all (but its own undefined type instead), and properties can only belong to objects within JavaScript. There are a few variations of this error depending on the property you are trying to access. Sometimes instead of undefined it will say null.

Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.