Home forums Using CanvasJS A variable for dataPoints

This topic contains 3 replies, has 4 voices, and was last updated by  Vishwas R 6 months, 3 weeks ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #6067

    Stupefiant
    Participant

    Hello,

    I downloaded canvasJS recently and I encountered a problem that I wasn’t able to solve.
    In my code if I do :
    `

    window.onload = function () {
    var tableauDataPoints = [
    { label: "apple", y: 10 },
    { label: "orange", y: 15 }
    ];

    [...]
    data: [
    {
    type: "column",
    dataPoints: tableauDataPoints
    }
    ]
    [...]

    The graphic will be displayed and I have no problem.
    However I need to fill this table otherwise.
    So I did :


    window.onload = function () {
    var tableauDataPoints = new Object(); /* I also tested with [] and new Array() */

    for (i = 1; i < 3; i++) {
    tableauDataPoints[i] = { label: "test", y: i };
    alert(tableauDataPoints[i].label + tableauDataPoints[i].y);
    }

    [...]
    data: [
    {
    type: "column",
    dataPoints: tableauDataPoints
    }
    ]
    [...]

    The alerts are correct, but I have no display, and I have no idea why, so I changed the variable type of “tableauDataPoints”, but no effect.
    If you have any idea, it will be really helpful!

    Thanks in advance,

    • This topic was modified 2 years, 9 months ago by  Stupefiant.
    #6075

    Sunil Urs
    Keymaster

    Stupefiant,

    DataPoints needs to be an array. Can you try var tableauDataPoints = [] instead?

    If the above suggestion doesn’t work, please re-create the issue on JSFiddle, so that I can figure out the problem.


    Sunil Urs

    #10496

    JustXtasy
    Member

    $.each(data, function (i, item) {
    dps.push(“{label: “+item.ProfileName+”, y:”+ item.TotalCustomer+”},”);
    alert(dps[0]);
    });

    How do i do this..?

    is it possible for a datapoints to be like that..?

    i cant render the Chart because I do not know the format.

    #10498

    Vishwas R
    Keymaster

    You can use dps.push({label:”label”, y:yValue})

    Here is an example.

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

You must be logged in to reply to this topic.