Ivan Hernandez
Ivan Hernandez

Reputation: 35

aChartEngine, How to get values from a chart

I'm new developping applications for android, so I hope someone can help me. I'm checking out a code from a friend, he made a class B to make the chart, in class A he created a GraphicalView and calls a GraphicalView method in class b to return the chart made. I want to get the value of the chart where the user clicks on, I've checked the demo of aChartEngine but in the example they create the setOnClickListener inside the code that creates the chart, so I want to know if someone know how can I get this values if the chart is already made in a GraphicalView, heare is an example of how it is.

class B{
    GraphicalView chart;
    public GraphicalView graf (){
        //heare is the code that generates the chart;
        return chart;
    }
}


class A{
    GraphicalView chartMade;
    b makeChart = new b();
    chartMade = makeChart.graf();
}

I want to get the values in class A.

Upvotes: 2

Views: 798

Answers (1)

Sam
Sam

Reputation: 86948

Your example is a vague so I cannot help you with specifics, but the basic approach is to override GraphicalChart's onTouchEvent() to call getCurrentSeriesAndPoint(). From this data you can call getValue() and / or getXValue() to get some of the chart's data.


Addition
Inside Class B try adding:

chartView.setOnTouchListener(new OnTouchListener() {
    @Override
    public boolean onTouch(View v, MotionEvent event) {
        SeriesSelection selection = ((GraphicalView) v).getCurrentSeriesAndPoint();
        Log.v("Touch", selection.getValue() + ", " + selection.getXValue());
        return false;
    }
});

Upvotes: 1

Related Questions