How to get the X/Y value from another chart?

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 Weezy on 20th June 2016
How to get the X/Y value from a another chart?

www.rgraph.net/docs/howto-get-the-x-y-value-from-a-scatter-chart.html
Posted by Richard on 20th June 2016
Hi there,

You'll need to explain more. You can use the method described there to get the X/Y values from any chart on the page.






Richard
Posted by Weezy on 20th June 2016
Thanks for your answer.

When I run this program (to get the X∕Y value from a line chart) an error is displayed:

"TypeError: line.canvas is undefined
  line.canvas.onmousemove = function (e)"

<script>

    window.onload = function ()
    {
        RGraph.AJAX.getJSON('getJson.php', drawGraph);


    function drawGraph (json)
    {
          // Now draw the chart
        var line = new RGraph.Line({
            id: 'line',
            data: [json.a, json.b, json.c],
            options: {
                annotatable: true,
                annotateLinewidth: 2,
                contextmenu: [['Effacer les annotations', function () {RGraph.Clear(line.canvas);
                            RGraph.ClearAnnotations(line.canvas); line.Draw();}]],
                key: ['a','b', 'c'],
                labels: json.nom,
                title: 'Exemple courbe',
                gutterBottom: 35,
                gutterTop: 35,
                tickmarks: 'circle',
                cursor:{zoom:true},
                numxticks: 0
           }
        }).trace();
      }


      line.canvas.onmousemove = function (e)
        {
            var obj = e.target.__object__;
            var x = obj.getXValue(e);
            var y = obj.getYValue(e);

            document.getElementById("x").value = x.toFixed(1);
            document.getElementById("y").value = y.toFixed(1);
        }
    };

</script>
Posted by Richard on 20th June 2016
Hi there,

There's no concept of X coordinates with the Line chart. That's why the URL you gave is using the Scatter chart. If you want an XY Line chart you'll need to use the Scatter.

This example uses the Scatter chart (but without the line option enabled) and logs the X/Y values to the console.

www.rgraph.net/fiddle/view.html/another-scatter-chart






Richard
Posted by Weezy on 20th June 2016
My problem is I need to recover the coordinates of any point in the line chart not scatter chart because the structure of my data is not compatible for the chart scatter.
Posted by Richard on 20th June 2016
Hi there,

Well the Line chart doesn't support an X scale - the points are simply spaced equally horizontally.







Richard
Posted by Weezy on 20th June 2016
Ok so, we can't get the X/Y values for any type chart except scatter chart?
Posted by Richard on 20th June 2016
Hi there,

That's correct.






Richard
Posted by Weezy on 20th June 2016
OK, and have you an idea for solve my issue please?
Posted by Richard on 20th June 2016
Hi there,
As I mentioned above, an XY chart can be achieved by using the Scatter chart with a joining Line.





Richard
Posted by Weezy on 20th June 2016
Ok but to create an scatter chart you have need this data type: (x1,y1);(x2,y2);(x3,y3);... but my data type is: (x1,'name1');(x2,'name2');(x3,'name3')... it's not compatible?
Posted by Richard on 20th June 2016
Hi there,

If you only have X values then even a Line chart isn't going to help. Maybe a Horizontal Bar chart would be appropriate here with each name up the left, and the Bars representing the value. Like this:

www.rgraph.net/examples/hbar-labels-above.html






Richard
Posted by Weezy on 20th June 2016
I know thanks but I want to work with line chart because I try to program a function who will be able to zoom on part of chart area.
Posted by Richard on 20th June 2016
Hi,

The only zoom in RGraph is this:

www.rgraph.net/docs/adding-zoom-to-your-charts.html

Which zooms the whole canvas.





Richard
Posted by Weezy on 21st June 2016
Thanks I know but it's not exactly what I am looking for.

Add a reply




« Back to message list