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

How to change the start position of the data along the x axis

1 Answer 58 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.
Carmen
Top achievements
Rank 1
Carmen asked on 12 Jan 2016, 03:55 PM

Lets say one has 100 data points on a graph, but I want to show only the last 20, so that I can pan across to the remaining 80 to the left. 

How would I accomplish this? When I load data into a graph it displays the entire data set? I could zoom in, but then I would have to guess at a zoom factor wouldn't I?  

Carmen

1 Answer, 1 is accepted

Sort by
0
Todor
Telerik team
answered on 15 Jan 2016, 12:29 PM
Hi Carmen,

Thank you for your question.

The Chart has a ChartPanZoomBehavior which allows you to zoom and or pan across the chart data if it is too big to fit. Additionally the chart has a setZoom method which allows you to programmatically zoom to a certain level. Here's an example:

ChartPanAndZoomBehavior panAndZoomBehavior = new ChartPanAndZoomBehavior();
panAndZoomBehavior.setZoomMode(ChartPanZoomMode.HORIZONTAL);
panAndZoomBehavior.setPanMode(ChartPanZoomMode.HORIZONTAL);
chart.getBehaviors().add(panAndZoomBehavior);
 
chart.setZoom(5,1);

Here the horizontal zoom is set to 5, since given that you want to display 20 out of 100 points. Depending on you requirements, you can set the zoom mode to none, if you don't want to allow users' zoom by gestures. Additionally to pan to the end on the initial load, you can use setPanOffset:

chart.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
    @Override
    public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
        chart.setPanOffset(-chart.getZoomWidth() * chart.getWidth(), 0);
    }
});

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
Carmen
Top achievements
Rank 1
Answers by
Todor
Telerik team
Share this question
or