Retrieving the X/Y coordinates from a Line Chart click


« 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 Sai Krishna Movva on 29th August 2016
Hi,

Following is my code,
l1 = new RGraph.Line({
             id: 'holder',
             data: [
                 yValues
             ],
             options: {
                 gutterTop: 50,
                 labels: xLabels,
                 linewidth: 2,
                 // spline : true,
                 colors: ['black'],
                 // numxticks: 8,
                 adjustable: true,
                 tickmarks: "circle",
                 ylabelsOffsetx : 50,
                 tooltips: yValues.map(String),
                 ymax: 1.25 * Math.max.apply(this, yValues),
                 ymin: 0.75 * Math.min.apply(this, yValues),
                 textSize: 8,
                 textAccessible: true
             }
         }).on('adjustend', function(line) {
             console.log(line.coords2[0]);
             console.log(line.getValue(line.coords2[0]));
             currentData = line.data_arr;
             line.original_data[0] = currentData;
             line.set('chart.tooltips', currentData.map(showPercentageAndFinalVal).map(String));
         }).draw();


Here I want the X & Y values of the clicked point on a linechart in the "on" function. How can I get them ?
Can someone help me on this?
Posted by Richard on 29th August 2016
Hi there,

There's no concept of an X scale in a Line chart - you can only retrieve the Y value, by using the obj.getValue(e);

However, the adjustend event is a custom RGraph event so there's no event object.

IIRC you could do something like this to get the Y value in the adjustend event handler (I'm assuming you only have one dataset):


var shape = RGraph.Registry.get('chart.adjusting.shape');
var index = shape.index;
var value = line.original_data[0][index];


If you want the X value though you'd need to entirely switch to a Scatter based X/Y chart such as this:

www.rgraph.net/demos/scatter-gwt.html



Richard
Posted by Sai Krishna Movva on 29th August 2016
var shape = RGraph.Registry.get('chart.adjusting.shape');
var index = shape.index;
var value = line.original_data[0][index];

This is giving an error "Undefined property index of object". I have put the above code in 'onadjustend' handler.
Posted by Richard on 29th August 2016
Hi there,

Well here's a working demo:

www.rgraph.net/tests/line-onadjustend.html



Richard

Add a reply

 




« Back to message list
RGraph on social media