How can I set the data on a Bar chart dynamically? - Official support forum | RGraph.net

How can I set the data on a Bar chart dynamically?


Posted by Mohamed at 13:14 on Tuesday 30th March 2021 [link]
How can be the data set in a bar dynamically?
myBar.original_data[0] = newData; //is not working

Posted by Richard at 15:29 on Tuesday 30th March 2021 [link]
The original_data variable is a Line chart variable - for the Bar chart you need to set the data slightly differently; and then, crucially, call the RGraph.redraw() function. For example:

function setData (obj, data)
{
    obj.data = data;
    RGraph.redraw();
}

Which you would call like this:

setData(myBar, newData);

And the format of the newData array should be like this:

// Regular Bar chart
newData = [4,8,6,3,5,4,8];

// Grouped or stacked data
newData = [[3,5,6],[2,5,8],[7,6,3],[8,5,7],[4,9,9],[5,2,3],[4,8,6]];

[Replies are now closed]