Able to pan far above bar chart


#1

I’m creating a bar chart that I want to be able to pan around. The problem is that right now I’m able to keep panning far past any of the bars(horizontal bars). I’ve set a small range on the yAxis, but that just sets the the amount of bars that are visible in the window. Any help would be appreciated. I’ve included an image that shows a user having panned past the bars and are still able to keep panning further.


#2

Hi Jghazarian,

Are you using an SChartCategoryAxis on your chart’s Y-axis? If so, then there shouldn’t be tick marks when you have panned past all the data on your chart. Are you passing your chart two extra datapoints that are empty?

If you are sure that you aren’t passing in two extra datapoints then can you paste me your code where you create and customise your chart’s Y-axis?  

Kind Regards,
Andrew Polkinghorn


#3

Hi Andrew. Thanks for the response. Unfortunately, I ended up taking this chart out, but I still have the code available. The Y-axis is indeed the SChartCategoryAxis and the data should be coming directly from some test arrays I put in there. Here’s all the setup I’m doing for this chart. I hope it helps.

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    players = @[@"player 1",@"player 2",@"player 3", @"player 4", @"player 5", @"player 6", @"player 7", @"player 8", @"player 9", @"player 10"];
    points = @[@(1),@(2),@(3), @(3), @(5), @(2), @(8), @(12), @(18), @(2)];
    
    playersChart = [[ShinobiChart alloc] initWithFrame:self.graphView.bounds];
    [playersChart setClearsContextBeforeDrawing:YES];
    
    //We want to use the lighter theme
    playersChart.theme = [SChartLightTheme new];
    
    //Bars are horizontal - which means this axis has our data values
    SChartNumberAxis *xAxis = [SChartNumberAxis new];
    xAxis.rangePaddingHigh = @(1);
    xAxis.enableGesturePanning = YES;
    xAxis.enableMomentumPanning = YES;
    playersChart.xAxis = xAxis;
    
    //A category axis displays each country
    SChartCategoryAxis *yAxis = [[SChartCategoryAxis alloc] initWithRange:[[SChartNumberRange alloc] initWithMinimum:@(0) andMaximum:@(10)]];
    yAxis.allowPanningOutOfMaxRange = NO;
    yAxis.enableGesturePanning = YES;
    yAxis.enableMomentumPanning = YES;
    playersChart.yAxis = yAxis;
    
    playersChart.legend.hidden = YES;
    playersChart.datasource = self;
    playersChart.delegate = self;
     
    [self.graphView addSubview:playersChart];
}

- (int)numberOfSeriesInSChart:(ShinobiChart *)chart {
    return [players count];
}

-(SChartSeries *)sChart:(ShinobiChart *)chart seriesAtIndex:(int)index {
    
    SChartBarSeries *series = [SChartBarSeries new];
    series.stackIndex = [NSNumber numberWithInt:1];
    
    series.title = players[index];
    
    return series;
}

- (int)sChart:(ShinobiChart *)chart numberOfDataPointsForSeriesAtIndex:(int)seriesIndex {
    return 1;
}

- (id<SChartData>)sChart:(ShinobiChart *)chart dataPointAtIndex:(int)dataIndex forSeriesAtIndex:(int)seriesIndex {
    
    SChartDataPoint *dp = [SChartDataPoint new];

    dp.yValue = players[seriesIndex];
    dp.xValue = points[seriesIndex];
    
    return dp;
}

#4

Hi Jghazarian,

I coped the code you posted exactly and it worked fine. There were no extra tick marks or extra space above the chart.

If you want us to look into this issue further could you email us a cut down version of your project just showing the chart that replicates your issue to info@shinobicontrols.com linking this forum post and someone will get back to you.

Kind Regards,
Andrew Polkinghorn


#5

I’m having the same issue on the xAxis. I’m using the following code:

 SChartDateTimeAxis *xAxis = [[SChartDateTimeAxis alloc] init];

    _chart.xAxis = xAxis;

    _chart.xAxis.allowPanningOutOfMaxRange = NO;

    _chart.xAxis.EnableGesturePanning = true;

    _chart.xAxis.EnableGestureZooming = true;

    _chart.xAxis.EnableMomentumPanning = true;

I have the 6 months back from today’s date of date points along the xAxis, but i’m able to pan way into the future (2014+). I tried using the initWithRange method on the SChartDateTimeAxis, but that didn’t seem to help either. Any insight? I’m currently using the trial and need to build a prototype to show to management to hopefully move forward for licensing purchaces. 


#6

Hi sof4real,

Which version of ShinobiCharts are you using? As this sounds like a bug that we fixed in release 2.2.1.

You can get the version by printing out [chart getInfo];

Kind Regards,
Andrew Polkinghorn