ChartTrackBallBehavio with track info overdraws the chart

4 posts, 0 answers
  1. Sandro
    Sandro avatar
    3 posts
    Member since:
    Nov 2015

    Posted 03 Dec 2015 Link to this post

    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?

  2. Todor
    Admin
    Todor avatar
    778 posts

    Posted 08 Dec 2015 Link to this post

    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
  3. DevCraft banner
  4. Sandro
    Sandro avatar
    3 posts
    Member since:
    Nov 2015

    Posted 10 Dec 2015 in reply to Todor Link to this post

    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

  5. Todor
    Admin
    Todor avatar
    778 posts

    Posted 10 Dec 2015 Link to this post

    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
Back to Top
DevCraft banner