setZoom: on specific axis not working?


#1

I have a line graph where I want to add a bit of zoom to the xAxis initially, because the auto layout is not showing all ticklabels. I can achieve this with a zoom of 1.4, though the user then has to pan a little to see the entire xAxis. This is acceptable in my case.

So I’ve tried to call [_chart.xAxis setZoom:1.4] but it doesn’t change anything. I’ve also tried the other setZoom variants with point etc. No positive results either. Am I missing something here? I feel like I do, since the documentation is pretty clear and I haven’t been able to find others with the same problem. Or could I achieve this in some other way? Alter the length og the xAxis maybe? :confused:


#2

Hi AskeAnker,

What you’re doing seems fine - I suspect you’re perhaps just missing a call to redrawChart after the setZoom call to get the chart to redraw with the updated zoom/range.

Let me know if this does the trick,

Best regards,

Rob


#3

rippling

Hi AskeAnker,

What you’re doing seems fine - I suspect you’re perhaps just missing a call to redrawChart after the setZoom call to get the chart to redraw with the updated zoom/range.

Let me know if this does the trick,

Best regards,

Rob

HI,

I am also trying to set zoom level. But it not wroking after applying redraw chart fundtion.

So please let me konow I set zoom for x axixs so that when chart appaer then show zoomed chart.


#4

rippling

Hi AskeAnker,

What you’re doing seems fine - I suspect you’re perhaps just missing a call to redrawChart after the setZoom call to get the chart to redraw with the updated zoom/range.

Let me know if this does the trick,

Best regards,

Rob

HI,

I am also trying to set zoom level. But it not wroking after applying redraw chart fundtion.

So please let me konow I set zoom for x axixs so that when chart appaer then show zoomed chart.


#5

Hi satvikios,

Whereabouts are you setting the zoom level? If you try to set the zoom before the chart first renders then it is unable to calculate the zoom level as it is currently unaware of the data range. Therefore you need to set the zoom level after the chart has first rendered. Helpfully there is a delegeate method to allow you do this.

If you create an ivar in your view controller:

@interface SCViewController () <SChartDatasource, SChartDelegate> {
    BOOL firstRender;
    ShinobiChart *_chart;
}

and then set it in viewDidLoad (along with setting the chart delegate):

- (void)viewDidLoad
{
    [super viewDidLoad];
    ...

    _chart.delegate = self;
    firstRender = YES;    
}

then you can implement the required method:

- (void)sChartRenderFinished:(ShinobiChart *)chart
{
    if(firstRender) {
        _chart.xAxis.zoom = 3;
        [_chart redrawChart];
        firstRender = NO;
    }
}

Hope this helps,

sam


#6

sam

Hi satvikios,

Whereabouts are you setting the zoom level? If you try to set the zoom before the chart first renders then it is unable to calculate the zoom level as it is currently unaware of the data range. Therefore you need to set the zoom level after the chart has first rendered. Helpfully there is a delegeate method to allow you do this.

If you create an ivar in your view controller:

@interface SCViewController () <SChartDatasource, SChartDelegate> {
    BOOL firstRender;
    ShinobiChart *_chart;
}

and then set it in viewDidLoad (along with setting the chart delegate):

- (void)viewDidLoad
{
    [super viewDidLoad];
    ...

    _chart.delegate = self;
    firstRender = YES;    
}

then you can implement the required method:

- (void)sChartRenderFinished:(ShinobiChart *)chart
{
    if(firstRender) {
        _chart.xAxis.zoom = 3;
        [_chart redrawChart];
        firstRender = NO;
    }
}

Hope this helps,

sam

Thanks for support. It is working fine. Can we implement Range selector for normal chart? If yes then how I implement that? Is there any tutorial which show process of range selector.


#7

If you are interested in creating a range selector with ShinobiCharts, then check out this series of blog posts, which take you through every stage of the process:

  1. Building a range selector with ShinobiCharts: Part I
  2. Building a range selector with ShinobiCharts: Part II
  3. Building a range selector with ShinobiCharts: Part III
  4. Building a range selector with ShinobiCharts: Part IV

_sam