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

2 posts, 0 answers
  1. Carmen
    Carmen avatar
    10 posts
    Member since:
    Dec 2015

    Posted 12 Jan Link to this post

    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?  


  2. Todor
    Todor avatar
    772 posts

    Posted 15 Jan Link to this post

    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();

    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() {
        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.

    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 R3 2016 release webinar banner
Back to Top