Can i ask if anyone knows the best way to use ShinobiChart premium in a subclassed UITableViewCell?
I am currently displaying a simply pie chart or donut chart with just 2 values, but memory does not appear to be released when UItableView is scrolled out of view and when a cell comes back into view containing the chart memory increases, until finally crash memory error!
//values declared as
@property(nonatomic, retain)ShinobiChart *donutChart;
@property(nonatomic, retain)NSDictionary* graphData;
graph and data initialised wirthin the tableviewcell
self.graphData = @{@"val1": [NSNumber numberWithDouble:val1], @"val2" :[NSNumber val2]};
self.donutChart = [[ShinobiChart alloc]initWithFrame:self.chartView.bounds];
self.donutChart.licenseKey = @"MY LICENSE KEY";
self.donutChart.datasource = self;
self.donutChart.delegate = self;
self.donutChart.legend.hidden = YES;
self.donutChart.backgroundColor = [UIColorclearColor];
[self.chartView addSubview:self.donutChart]; // chartview is simply a UIView to contain the graph
Delegate methods;
- (NSInteger)numberOfSeriesInSChart:(ShinobiChart *)chart {
return 1;
}
-(SChartDonutSeries *)sChart:(ShinobiChart *)chart seriesAtIndex:(NSInteger)index {
SChartPieSeries* pieSeries = [[SChartPieSeriesalloc] init];
pieSeries.style.showFlavour = YES;
pieSeries.style.showCrust = YES;
pieSeries.style.flavourColors = [NSMutableArrayarrayWithObjects:[UIColorcolorWithHexString:PRIMARY_COLOUR_ASSESSMENTS], [UIColorcolorWithHexString:PRIMARY_COLOUR_CARECIRCLE], nil];
pieSeries.selectedStyle.protrusion = 0.f;
pieSeries.selectionAnimation.duration = @0.4;
pieSeries.selectedPosition = @0.0;
//pieSeries.innerRadius = 10.f;
pieSeries.outerRadius = 50.f;
pieSeries.gesturePanningEnabled = NO;
UIColor* colour = [UIColorcolorWithHexString:MAIN_COLOUR];
UIColor* colour1 = [UIColor colorWithRed:[colour red] green:[colour green] blue:[colour blue] alpha:0.3];
[pieSeries.stylesetFlavourColors:[NSMutableArrayarrayWithArray:[NSArrayarrayWithObjects:colour1, colour, nil]]];
SChartPieSeriesStyle *style = [[SChartPieSeriesStylealloc] init];
style.labelFontColor = [UIColorredColor];
style.showCrust = YES;
style.crustThickness = [NSNumbernumberWithFloat:5.0];
style.crustColors = [NSMutableArrayarrayWithObjects:[UIColorwhiteColor], [UIColorwhiteColor], nil];
return pieSeries;
}
- (NSInteger)sChart:(ShinobiChart *)chart numberOfDataPointsForSeriesAtIndex:(NSInteger)seriesIndex {
returnself.graphData.allKeys.count;
}
- (id<SChartData>)sChart:(ShinobiChart *)chart dataPointAtIndex:(NSInteger)dataIndex forSeriesAtIndex:(NSInteger)seriesIndex {
SChartRadialDataPoint *datapoint = [[SChartRadialDataPointalloc] init];
NSString* key = self.graphData.allKeys[dataIndex];
datapoint.name = key;
datapoint.value = self.graphData[key];
return datapoint;
}