This is a migrated thread and some comments may be shown as answers.

ChartTrackBallBehavio with track info overdraws the chart

3 Answers 49 Views
Chart
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Sandro
Top achievements
Rank 2
Sandro asked on 03 Dec 2015, 02:35 PM

Hello,

 I have a question is it possible to "shrink" the chart? I want to use the trackball behavior and tool tip, but the tooltip overdraws the chart in some areas.

 the best solution I did come up with is the following:

mChartView.setOnLongClickListener(new View.OnLongClickListener() {
    @Override
    public boolean onLongClick(View view) {
        RadCartesianChartView chartView = (RadCartesianChartView) view;
        LinearAxis axis = (LinearAxis) chartView.getVerticalAxis();
        if (axis != null) {
            double range = (axis.getMaximum() - axis.getMinimum()) * 1.12;
            axis.setMaximum(axis.getMinimum() + range);
            chartView.setVerticalAxis(axis);
        }
 
        return false;
    }
});
 
mChartView.setOnTouchListener(new View.OnTouchListener() {
    @Override
    public boolean onTouch(View view, MotionEvent motionEvent) {
        // We're only interested in when the button is released.
        if (motionEvent.getAction() == MotionEvent.ACTION_UP) {
            RadCartesianChartView chartView = (RadCartesianChartView) view;
            LinearAxis axis = (LinearAxis) chartView.getVerticalAxis();
            axis.setMaximum(mFinanceApiTask.getHigh());
            chartView.setVerticalAxis(axis);
        }
        return false;
    }
});

This makes a bit of space for the tooltip on top by increasing the vertical axis. Is there a better solution?

3 Answers, 1 is accepted

Sort by
0
Todor
Telerik team
answered on 08 Dec 2015, 01:10 PM
Hi Sandro,

Thank you for writing.

You have correctly observed that the way to "shrink" the chart is to manually set values for the axis' minimum and/or maximum. However I'd like to ask you to share more details about the observed issue. The Trackball behavior is intended to show the trackball info always at the top of the chart and on a position relatively to the closest point. The info should be drawn high but should remain visible, so I don't understand the necessity to change the maximum while it is shown. Please elaborate a bit more so that we can assist you further.

Regards,
Todor
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Sandro
Top achievements
Rank 2
answered on 10 Dec 2015, 09:18 AM

Hi Todor,

I've attached two screenshots to show what I mean. In the first screenshot the chart is not "shrinked" and the tool tip info is drawn over the chart. That is why I shrink the chart like in the second screenshot. So that everything is visible.

Another thing I'd like to know is how to customize the tool tip info (layout, size, color, etc.). The best solution would be if I could achieve something like in screenshot 3 where the y-value is shown as tool tip info and the x-value is shown as label at the bottom. This would use the screen real estate in the moste efficient way . 

I hope this helps clarifying my needs.

 

Kind regards,

Sandro

0
Todor
Telerik team
answered on 10 Dec 2015, 01:07 PM
Hi Sandro,

Yes, the size of the chart and whether it is more "shrunk" or more "extended" can be affected by the axis' minimum and maximum properties. If you know the minimum and maximum points in your data (or cycle through all the points to find them) you can set a maximum and minimum relatively to your data to make the chart more "shrunk" from the very beginning. As to your second question regarding the tooltip info, you need to extend the ChartTrackballContentAdapter and override its getView method where you can return your custom content:

class MyContentAdapter extends ChartTrackballContentAdapter {
    public MyContentAdapter(Context context) {
        super(context);
    }
 
    @Override
    public View getView(Object[] targets) {
 
        for (Object dataPoint : targets) {
            DataPoint point = (DataPoint)dataPoint;
            // add info for the data point
 
        }
        //return info;
    }
}

Then you can set an instance of this class to the Trackball behavior:

trackBallBehavior.setContentAdapter(new MyContentAdapter(getContext()));

I hope this information helps.

Regards,
Todor
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
Chart
Asked by
Sandro
Top achievements
Rank 2
Answers by
Todor
Telerik team
Sandro
Top achievements
Rank 2
Share this question
or