Home forums Using CanvasJS Uncaught type error: cannot read property of undefined

Tagged: 

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

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

    I have a problem when updating datapoint in canvas chart. I get this error message:

    Uncaught TypeError: Cannot read property ‘getTime’ of undefined

    The output I receive in response.msg is

    [{label: ‘Purok I’, y:1},{label: ‘Purok II’, y:1},{label: ‘Purok III’, y:2}]
    When this is replaced with response renders the chart successfully. However passing response to datapoints gives the error. This is my Javascript. Any help?

    $(‘#barangay-list’).click(function() {
    var barangay_id = $(this).val()
    console.info(barangay_id)
    $.ajax({
    url: ‘../classes/main.php’,
    type: ‘POST’,
    data: {
    ‘population-chart’: 1,
    ‘barangay_id’: barangay_id
    },
    async: true,
    dataType: ‘JSON’,
    success: function(response, data) {
    var chart = new CanvasJS.Chart(“chartContainer”, {
    theme: “light2”,
    zoomEnabled: true,
    animationEnabled: true,
    animationEnabled: true,
    axisX: {
    title: “Street Name”,
    gridThickness: .9,
    lineThickness: .9,
    titleFontSize: 14,
    labelFontSize: 12,
    },
    axisY: {
    includeZero: true,
    title: “Number of Population”,
    gridThickness: .9,
    lineThickness: .9,
    titleFontSize: 14,
    labelFontSize: 12
    },
    toolTip: {
    shared: “true”
    },
    legend: {
    cursor: “pointer”,
    itemclick: toggleDataSeries,
    verticalAlign: “bottom”,
    horizontalAlign: “center”
    },
    data: [{
    type: “spline”,
    showInLegend: true,
    name: “Populaltion Number”,
    dataPoints: response.msg
    }]
    });
    chart.render();

    function toggleDataSeries(e) {
    if (typeof(e.dataSeries.visible) === “undefined” || e.dataSeries.visible) {
    e.dataSeries.visible = false;
    } else {
    e.dataSeries.visible = true;
    }
    chart.render();
    }
    },
    // Error Handler
    error: function(xhr, textStatus, error) {
    console.info(xhr.responseText);
    }
    });
    });

    #24525

    @johncris,

    Can you kindly create sample project with sample data reproducing the issue and share it to us over Google-Drive or Onedrive, which helps us run your code at our end, understand the issue you are facing and help you with a solution?


    Vishwas R
    Team CanvasJS

    #25584

    I am facing an error while rendering the chart. Please review my code and help me in resolving the issue.
    Here is the link of my jsfiddle: https://jsfiddle.net/45nvs1u0/

    Regeards,
    Samyukta

    #25585

    I am getting an error “cannot read property ‘data points’ of undefined”.

    #25590

    Samyukta,

    The issue seems to be with the approach of looping through ‘Values’ object. Please take a look at this stackoverflow thread for more information on looping through the properties of a JavaScript object.

    If this doesn’t help you fulfill your requirements, kindly brief us more about your requirements so that we can understand it better and help you achieve the same.


    Vishwas R
    Team CanvasJS

    #25597

    Yes it works! Thank you so much!

    Regards,
    Samyukta

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

You must be logged in to reply to this topic.