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

This topic contains 2 replies, has 2 voices, and was last updated by  Mudassir 2 weeks ago.

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

    Mudassir
    Member

    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

    Suyash Singh
    Moderator

    @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

    Mudassir
    Member

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

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

You must be logged in to reply to this topic.