Chart Parameters

Description: the chart is plotted by parameters set in the current files.

The ViewController.h File

#import <UIKit/UIKit.h>
#import <Charting/Chart.h>
#import "Charting/ColumnSeries.h"
#import "Charting/AreaSeries.h"
#import "DataSource.h"
#import "Charting/BarSeries.h"
#import "Charting/PieSeries.h"
#import "Charting/LineSeries.h"
#import "Charting/LinePoint.h"
#import "Charting/ChartTouchesDelegate.h"
#import "Charting/ChartLabel.h"
#import "Charting/BubbleSeries.h"
#import "ChartTypes.h"
#import "RadialGradientBrush.h"
#import "GradientStop.h"
#import "Charting/ChartMarker+Charting.h"
@interface ViewController : UIViewController<ChartTouchesDelegate,TimeAxisDelegate>{
    Chart *chart;
    float max;
    float min;
    NSMutableDictionary *m_numberFormat;
    int axisType;
    BOOL hideAxis;
    int chartType;
    NSArray *m_colors;
    DataSource *datasource;
    RadialGradientBrush *radialBrush;
    BOOL outputInfo;
}
- (ChartLabel *)createDefaultLabel;
- (void) setChartSettings;
- (void) drawAllSeries;
- (NSDictionary *) createDictForBrushWithBaseColor:(UIColor *) color;
@end

File ViewController.m

#import &quot;ViewController.h&quot;
#import &quot;Brush.h&quot;
#import &quot;UIColor+transition.h&quot;
#import &lt;charting/gradientbrush+charting.h&gt;
#import &lt;charting/gradientstop+charting.h&gt;
#import &lt;charting/lineargradientbrush+charting.h&gt;
#import &lt;charting/radialgradientbrush+charting.h&gt;
#import &lt;charting/solidcolorbrush+charting.h&gt;
#define ColorWithRGBA(_r, _g, _b, _a) [UIColor colorWithRed:(_r) / 255.0f green:(_g) / 255.0f blue:(_b) / 255.0f alpha:(_a) / 255.0f]
@implementation ViewController
- (void)dealloc
{
        [super dealloc];
}
- (void)didReceiveMemoryWarning
{
        [super didReceiveMemoryWarning];
}
#pragma mark - View lifecycle
- (void)viewDidLoad
{
        [super viewDidLoad];
        m_numberFormat = [[NSMutableDictionary dictionaryWithObjectsAndKeys:
                                              [NSNumber numberWithBool:NO], @&quot;asInSource&quot;,
                                              [NSNumber numberWithInt:2], @&quot;decNumbers&quot;,
                                              [NSNumber numberWithBool:YES], @&quot;separator&quot;,
                                              @&quot;&quot;, @&quot;prefix&quot;,
                                              @&quot;&quot;, @&quot;suffix&quot;,
                                              [NSNumber numberWithBool:NO], @&quot;negativeRed&quot;,
                                              nil] retain];
        m_colors = [[NSArray arrayWithObjects:
                                  ColorWithRGBA(19, 88, 138, 255 ),
                                  ColorWithRGBA(109, 167, 192, 255 ),
                                  ColorWithRGBA(41, 171, 226, 255 ),
                                  ColorWithRGBA(0, 169, 157, 255 ),
                                  ColorWithRGBA(103, 124, 139, 255 ),
                                  ColorWithRGBA(221, 241, 250, 255 ),
                                  ColorWithRGBA(169, 221, 243, 255 ),
                                  ColorWithRGBA(102, 203, 196, 255 ),
                                  ColorWithRGBA(208, 222, 232, 255 ),
                                  ColorWithRGBA(190, 160, 186, 255 ),
                                  nil] retain];
        // Create a chart and set size
        chart = [[Chart alloc] initWithName:@&quot;Chart&quot;];
        chart.frame=CGRectMake(0, 0, 600, 550);
        
        chart.plotArea.zoomEnabled = NO;
        // Determine title parameters
        chart.caption.text = @&quot;Chart&quot;;
        chart.caption.textColor = [UIColor blackColor];
        chart.caption.maxTextLength = 100;
        chart.caption.blockAlignment = AlignmentCenter;
        // Determine legend parameters
        chart.legend.background = [SolidColorBrush solidColorBrushWithColor:[UIColor whiteColor]];
        chart.legend.borderRadius = 2;
        chart.legend.borderThickness = 1;
        chart.legend.borderColor = [UIColor whiteColor];
        chart.legend.font = [UIFont fontWithName:@&quot;Arial&quot; size:12];
        chart.legend.legendOrientation = LegendOrientationTop;
        chart.legend.textColor = [UIColor blackColor];
        for (ChartSeries *s in chart.seriesList) {
                [chart deleteSeries:s];
        }
        chart.usingRightToLeft = NO;
        chart.minimalHitRadius = 4;
        chart.chartArea.borderColor = [UIColor whiteColor];
        chart.chartArea.backgroundColor = [UIColor whiteColor];
        chart.chartArea.background = [SolidColorBrush solidColorBrushWithColor:[UIColor whiteColor]];
        // Create data source
        datasource = [[DataSource alloc] init];
        [chart setDataSource :datasource];
        [self setChartSettings];
        [self drawAllSeries];
        // Set link to data source
        [chart setDelegate:self];
        // Set maximum and minimum values by Y axis for data source
        [datasource prepare];
        [chart forceDataUpdate];
        // Execute custom example
        [self executeExample];
        // Display chart
        [self.view addSubview:chart];
}
// Function for example execution
-(void) executeExample{
};
- (void)drawAllSeries
{
        [chart deleteAllSeries];
        int seriesCount = datasource.countSeries;
        for (int i = 0; i &lt; seriesCount; ++i)
        {
                axisType = ValueAxisAbsolute;
                hideAxis = NO;
                BubbleSeries *ser = [[BubbleSeries new] autorelease];
                ser.backgroundColor = [UIColor blackColor];
                ser.marker.borderThickness = 1;
                ser.marker.borderColor = [UIColor blackColor];
                ser.marker.shape = MarkerShapeCircle;
                ser.renderTrace = NO;
                ser.color = [UIColor blueColor];
                ser.thickness = 2;
                UIColor *color = [m_colors objectAtIndex:i % [m_colors count]];
                radialBrush = [RadialGradientBrush new];
                GradientStop *st1 = [[[GradientStop alloc] initWithColor:[UIColor whiteColor] offset:0.1] autorelease];
                GradientStop *st2 = [GradientStop gradientStopWithColor:color offset:1.0];
                [radialBrush setGradientStops:[NSMutableArray arrayWithObjects:st1,st2, nil]];
                radialBrush.center = CGPointMake(0.5, 0.5);
                radialBrush.opacity = 1.0;
                RadialGradientBrush *brush = [radialBrush autorelease] ;
                [[radialBrush.gradientStops objectAtIndex:1] setColor:color];
                [ser.marker setBackground:brush];
                ser.shadowOffset   = CGSizeMake(0, 0);
                ser.showShadow = YES;
                ser.dataIndex = i;
                ser.defaultLabel = [self createDefaultLabel];
                [chart addSeries:ser];
        }
        [chart forceDataUpdate];
        ((ValueAxis *)[chart.axes objectForKey:[NSNumber numberWithInt:AxisLineX]]).valueAxisType = axisType;
        ((ValueAxis *)[chart.axes objectForKey:[NSNumber numberWithInt:AxisLineY]]).valueAxisType = axisType;
        ((ValueAxis *)[chart.axes objectForKey:[NSNumber numberWithInt:AxisLineX]]).visible = !hideAxis;
        ((ValueAxis *)[chart.axes objectForKey:[NSNumber numberWithInt:AxisLineY]]).visible = !hideAxis;
}
- (void )viewDidUnload
{
        [super viewDidUnload];
}
- (BOOL )shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
        return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
- (void )chartTouchesTapInView:(UIView *)v withPoint:(CGPoint)point
{
        UIView *sender = [v hitTest:point withEvent:nil];
        if ([sender isKindOfClass:[ChartPoint class]])
        {
                ChartPoint *pt = (ChartPoint *)sender;
                if([pt isKindOfClass:[BubblePoint class]])
                {
                        NSLog(@&quot;%@&quot;,[((BubblePoint *)pt).marker dumpConfigurationToDict]);
                }
                NSLog(@&quot;%@&quot;,pt.series);
                NSLog(@&quot;%d&quot;,pt.noValue);
                if (pt.chartLabel)
                {
                        pt.chartLabelVisible = !pt.chartLabelVisible;
                        if (pt.chartLabelVisible)
                        {
                                [pt moveAboveAllByZOrder];
                                ((BubblePoint *)pt).r *= 1.1;
                                ((BubblePoint *)pt).marker.borderThickness = 2;
                        }
                        else
                        {
                                [pt restoreZOrder];
                                ((BubblePoint *)pt).r /= 1.1;
                                ((BubblePoint *)pt).marker.borderThickness = 1;
                        }
                }
                [chart setNeedsLayout];
        }
        else
        {
                ((TimeAxis *)[chart.axes objectForKey:[NSNumber numberWithInt:AxisTypeTimeline]]).index++;
        }
        
        
        [chart setNeedsDisplay];
}
- (void)setChartSettings
{
        ValueAxis *axisX = (ValueAxis *)[chart.axes objectForKey:[NSNumber numberWithInt:AxisLineX]];
        axisX.axisThickness = 1;   // X axis thickness
        axisX.majorTicks.thickness = 0; // Thickness of X axis major tick marks
        axisX.minorTicks.thickness = 0; // Thickness of X axis minor tick marks
        axisX.startOffset = -0.1;
        ValueAxis *axisY = (ValueAxis *)[chart.axes objectForKey:[NSNumber numberWithInt:AxisLineY]];
        axisY.startOffset = -0.1;
        axisY.axisThickness = 1; // Y axis thickness
        axisY.majorTicks.thickness = 1;
        axisY.majorTicks.size = 3; // Tick mark length
        axisY.minorTicks.thickness = 0;
        axisY.showGrid = YES; // Display grid
        axisY.gridThickness = 1; // Grid thickness
        axisY.gridColor = ColorWithRGBA(200, 200, 200, 255);
        axisY.caption.visible = YES;
        axisY.caption.text = @&quot;axisY&quot;;
        axisY.caption.font = [UIFont fontWithName:@&quot;Arial&quot; size:20.0];
        if(outputInfo){
                NSLog(@&quot;%f&quot;,axisY.maxOffset);
                NSLog(@&quot;%f&quot;,axisY.pointsVisible);
        }
        // Determine axis tick mark parameters
        AxisTicks *majorTics = ((ValueAxis *)[chart.axes objectForKey:[NSNumber numberWithInt:AxisLineY]]).majorTicks;
        ((ValueAxis *)[chart.axes objectForKey:[NSNumber numberWithInt:AxisLineY]]).minorTicks = majorTics;
        // Determine bubble axis
        RadialAxis *radAxis = [chart.axes objectForKey:[NSNumber numberWithInt:AxisTypeR]];
        radAxis.maxSize = 50; // Maximum size of bubble
        radAxis.minSize = 10; // Minimum size of bubble
        radAxis.visible = YES;
        // Determine timeline parameters
        TimeAxis *timeAxis = ((TimeAxis *)[chart.axes objectForKey:[NSNumber numberWithInt:AxisTypeTimeline]]);
        timeAxis.visible = YES;
        timeAxis.delegate = chart;
        timeAxis.minIndex = 0;
        timeAxis.maxIndex = 5;
        timeAxis.jumpTime = AnimateTypeFast;
        timeAxis.font = [UIFont fontWithName:@&quot;Times New Roman&quot; size:14];
        timeAxis.label.text = @&quot;TimeAxis&quot;;
        timeAxis.delayTime = AnimateTypeFastest;
        timeAxis.minTickSpacing = 10.0;
        timeAxis.tickColor = [UIColor blueColor];
        if(outputInfo)
                NSLog(@&quot;%d&quot;,timeAxis.axisType);
        Thickness th = {10,0,0,20}; // Margins
        chart.legend.margin = th; // Legend margins
        th.bottom = 0;
        th.left = th.right = th.top = 10;
        chart.chartArea.padding = th; // Chart area margins
}
- (ChartLabel *)createDefaultLabel
{
        ChartLabel *result = [[[ChartLabel alloc] initWithFrame:CGRectZero] autorelease]; // Create a label
        result.background = [[SolidColorBrush new] autorelease]; // Set color
        result.borderColor = [UIColor blackColor]; // Border color
        result.borderThickness = 1;
        result.borderRadius = 10;
        result.font = [UIFont fontWithName:@&quot;Arial&quot; size:18]; // Font
        result.textAlignment = (Alignment)UITextAlignmentCenter;
        result.textColor = [UIColor blackColor];
        result.mask = [NSString stringWithFormat:@&quot;%@#FVAL%@&quot;,
                                      (NSString *)[m_numberFormat objectForKey:@&quot;prefix&quot;],
                                      (NSString *)[m_numberFormat objectForKey:@&quot;suffix&quot;]];
        result.countOfDecimalNumbers = [((NSNumber *)[m_numberFormat objectForKey:@&quot;decNumbers&quot;]) intValue];
        result.displayNegativesInRed = [(NSNumber *)[m_numberFormat objectForKey:@&quot;negativeRed&quot;] boolValue];
        result.hasHorizontalNoteLine = result.hasVerticalNoteLine = result.hasFootNoteLine = NO;
        result.minWidth = 0;
        return result;
}
- (void)chartDataReady:(id)sender
{
        NSLog(@&quot;Data was load&quot;);
}
- (void)chartTouchesSwipeInView:(UIView *)v withDirection:(UISwipeGestureRecognizerDirection)direction
{
        NSLog(@&quot;Swipe&quot;);
}
@end

See also:

Creating a Bubble Chart