Dynamically adding and removing lines from Line graph


« Back to message list

Enter your email address to get email updates on this topic. You can stop receiving updates by clicking the link in the update email messages.

Posted by Marin on 10th July 2014
Hi,

I have few checkboxes (number of them depends on the data from database), and i want to be able to draw a line on a chart whenever i click on a particular checkbox (data for the line is taken from the database).Sometimes there can be more lines on the samo graph, depending how many checkboxes are clikced. I also need to delete particuar line when i uncheck that particular checkbox. Is there a way to dynamically add and remove specific array from graph, just by specifying array name ,something like :

line.original_data.add(array1)
line.original_data.remove(array1)

or do I always have to clear the whole graph and draw a new one with new arrays?
I've tried with push(array) and pop() but pushing works fine,and popping (of course) just pops the last element.

Thanks,

Marin
Posted by Richard on 10th July 2014
There's nothing like what you want. What you could do is maintain your own object that does what you want and then populate the original_data array from that. Your object could contain the whole data or just each datasets relevant index in the original_data array. The pbject signature could be like this:


var MyData = function()
{
     this.data = [];


     this.add = function ()
     {
     };


     this.remove = function ()
     {
     };


     // Return the data so that it can be assigned to
     // the original_data array
     this.get = function ()
     {
         return this.data;
     };
};





Richard
Posted by Marin on 10th July 2014
Thank You for your quick response
Posted by Arun on 16th July 2014
I need to bind the data dynamically in Rgraph bar charts.
Posted by Richard on 16th July 2014
With the Bar chart you can add the data by updating the obj.data property and then calling RGraph.redraw() There's a list on the API page that details ech charts data properties:

www.rgraph.net/api#data


Richard


« Back to message list
RGraph on social media