Determine the line in click event if more than 2 lines

Share RGraph:   Share or Like RGraph on Facebook!

« 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 Othmar on 31st December 2015
Hello is it possible to find out which line was clicked if i have more than two lines.

Have add fiddle here: jsfiddle.net/eb9snw6v/1/
Posted by Richard on 31st December 2015
Hi,

You can use the shape.object variable instead of the [canvas].__object__ property. So the handler would look like this:

function myFunc2(e, shape)
{
   // Use the shape.object variable to get the RGraph object
   var obj = shape.object

   var index = shape['index_adjusted'],
       dataset = shape['dataset'],
       value = obj.original_data[dataset][index];

   alert('Value is: ' + value);
   alert('UID is: ' + obj.uid);
}




Richard
Posted by Othmar on 1st January 2016
Thank you

This is ok for me. So i can refer which line was clicked by the color. (3 lines with different colors)

function datapoint(e, shape){
    var obj = shape.object

    var index = shape['index_adjusted'],
        dataset = shape['dataset'],
        value = obj.original_data[dataset][index];

    var color = obj.properties["chart.colors"];

    alert( index +' ' + color+ " / " + value);
};

Maybe a line "name" would be nice for the future (feature request). So anybody can set a reference backwards. (from draw a line to click --> uid is auto generated value wich was changed every draw).
In my case i can make a reference by the differnt colors. This is ok for me.

Happy new year
Othmar
Posted by Richard on 1st January 2016
Hi,

If you want you can set your own property on the object and then test that:

var line = new RGraph.Line({
     id: 'cvs',
     data: [1,2,3,4,5,6,7,8,9,0],
     options: {
         // ...
     }
}).draw();

// After drawing the chart set a custom name property so that the object
// can be later identified
line.name = 'line1';



And then in your datapoint function test for it:


function datapoint(e, shape)
{
     var obj = shape.object

     var index = shape['index_adjusted'],
         dataset = shape['dataset'],
         value = obj.original_data[dataset][index];

     var name = obj.name;

     alert(name);
};


Obviously use a different name for each object!





Richard
Posted by Othmar on 1st January 2016
Hi Richard

This is exact what i need!
Thank you and happy new year,

Othmar
Posted by Richard on 1st January 2016
Hi,

Happy new year! Hopefully this will be the year that RGraph takes over the world! (Probably not though).



Richard

Add a reply




« Back to message list