Update a piechart on device orientation change


I am having great difficulty getting my charts to update after they have been initially rendered.  I have an existing project that I am in the process of integrating with Shinobin Charts and I cannot figure out how to get my charts to change their bound properly or chnage the lengen orientation (among other things).

I have doe some tests on the “interactive legend” pie chart demo (found in this tutorial) by adding this code to the PieChartViewController.m:

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
  [super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
  SChartTheme *theme = pieChart.theme;
  if (UIInterfaceOrientationIsPortrait(toInterfaceOrientation)) {
    theme.legendStyle.orientation = SChartLegendOrientationVertical;
    theme.legendStyle.borderWidth = [NSNumber numberWithInt:10];
    theme.chartTitleStyle.textColor = [UIColor greenColor];
  } else {
    theme.legendStyle.orientation = SChartLegendOrientationHorizontal;
    theme.legendStyle.borderWidth = [NSNumber numberWithInt:20];
    theme.chartTitleStyle.textColor = [UIColor redColor];
  [pieChart setTheme: theme];
  NSLog(@"changed theme");
  [pieChart redrawChartAndGL:YES];

This code doesn’t do anything - i expected the results to be vsible when changing the device orientation in the Simulator.  I would also like to adjust the bounds/frame but this trivial test has me blocked.

It seems like I’m missing something basic.  Any ideas?

Thanks in advance for any assitance.



It looks like you just need to change one line in that code snippet in order to get the changes working.  Where you currently call [pieChart setTheme: theme], replace that with [pieChart applyTheme] instead.  In the code snippet you’ve posted, calling setTheme: won’t have any effect, as you’re not changing the theme object which the chart is referencing.

By calling applyTheme instead, you’re telling the chart that the theme’s sub-styles have been updated, and that it needs to pull in the new properties.

Hope that helps!