Home forums Using CanvasJS Pie Chart With Dynamic Data

Tagged: 

This topic contains 4 replies, has 1 voice, and was last updated by  JipThePeople 2 years, 10 months ago.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #5599

    JipThePeople
    Participant

    I can successfully render a canvasJS pie chart using static data hard-coded within a js array like this:

    var dps = [{ y: 1, indexLabel: “Writing” }, { y: 0, indexLabel: “External Collaboration” }, { y: 0, indexLabel: “Ready for Edit” }, { y: 0, indexLabel: “Editing” }, { y: 0, indexLabel: “Ready for Review” }, { y: 0, indexLabel: “In Pink Team” }, { y: 0, indexLabel: “In Gold Team” }, { y: 1, indexLabel: “In Red Team” }, { y: 0, indexLabel: “Final Versions” }]

    However, I need to simply reference an array already populated. I am populating an array from a table on the page. I can’t understand why it won’t work because when I convert the array to string and print, everything is correct and in the right format. Below is the link to my jsfiddle example code.

    Any help is greatly appreciated.

    #5600

    JipThePeople
    Participant

    #5601

    JipThePeople
    Participant
    #5603

    JipThePeople
    Participant

    Line 18 is where I think the issue is.

    // S/B formatted like this: { y: 10, indexLabel: “Writing (1)” }
    dps.push([‘\{ y: ‘ + Number(value) + ‘, indexLabel: \”‘ + key + ‘ (‘ + value + ‘)\” \}’ ]);

    I would really appreciate any feedback.

    #5605

    JipThePeople
    Participant

    Here is the solution:

    dps.push({ y: Number(value), indexLabel: key + ‘(‘ + value + ‘)’});

    I was not building the array the right way. I was putting text elements in it where I needed to put objects in it.

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

You must be logged in to reply to this topic.