Determining Fill Brushes

Operating system requirements: iOS 5.0 or later.

Mobile device: iPad.

Description

This example implements resizing of chart markers, and also creating of fill brushes based on the specified parameters and their application to chart elements.

On clicking the chart bubble a label is displayed, and the bubble is drawn on top of others. On second click the label is hidden, and standard drawing order is restored.

Source Code

Executing the example requires to place the following code instead of the executeExample method of the ViewController class (see the Creating a Bubble Chart section):

// Function for example execution
-(void) executeExample{
    // Set minimum size for chart bubbles
    [[chart radialAxis] setMinSize:30];
    // Create gradient linear fill object
    LinearGradientBrush *linearGBrush = [LinearGradientBrush new];
    // Get arrays of gradient stop parameters
    NSDictionary *gStops = [linearGBrush dumpGradientStops];
    NSArray *gStopsValues = [gStops objectForKey:@"value"];
    // Create new objects of gradient stops based on obtained parameters
    GradientStop *s1 = [GradientStop gradientStopWithDict:gStopsValues[0]];
    GradientStop *s2 = [GradientStop gradientStopWithDict:gStopsValues[1]];
    // Determine transition color
    UIColor *newColor = [UIColor transitionColorFrom:[UIColor lightGrayColor] to:[UIColor blueColor] position:5];
    // Set gradient stop colors
    [s1 setColor: newColor];
    [s2 setColor:[UIColor grayColor]];
    // Set gradient stops
    [linearGBrush gradientStops][0] = s1;
    [linearGBrush gradientStops][1] = s2;
    // Set chart series point marker brush
    [[[[[chart seriesList][0] points] objectForKey:@"0"] marker] setBackground:linearGBrush];
    // Determine brush
    UIColor *solidBrushColor = [UIColor colorWithIntRed:121 green:160 blue:193 alpha:255];
    SolidColorBrush *solidBrush = [SolidColorBrush solidColorBrushWithColor:solidBrushColor];
    // Get brush parameters
    NSMutableDictionary *solidBrushDict = [solidBrush dumpConfigurationToDict];
    // Create new brushes based on obtained parameters
    SolidColorBrush *newSolidBrush = [SolidColorBrush solidColorBrushWithDict:solidBrushDict];
    [newSolidBrush setOpacity:1];
    [newSolidBrush setColor:solidBrushColor];
    GradientBrush *gradientBrush = [GradientBrush brushWithDict:solidBrushDict];
    // Set new brushes of chart series point markers
    if([newSolidBrush mainColor] != nil)
        [[[[[chart seriesList][1] points] objectForKey:@"0"] marker] setBackground:newSolidBrush];
    else
        [[[[[chart seriesList][1] points] objectForKey:@"0"] marker] setBackground:solidBrush];
    if([gradientBrush mainColor] != nil)
        [[[[[chart seriesList][2] points] objectForKey:@"0"] marker] setBackground:gradientBrush];
    else
        [[[[[chart seriesList][2] points] objectForKey:@"0"] marker] setBackground:[SolidColorBrush solidColorBrushWithColor:[UIColor purpleColor]]];
};

It is also required to place the following code instead of the chartTouchesTapInView:withPoint: method:

// Process chart area touch event
- (void)chartTouchesTapInView:(UIView *)v withPoint:(CGPoint)point{
    // Get a data series
    ChartSeries *series = [chart seriesList][0];
    // Get data series point
    BubblePoint *bPoint = [[series points] objectForKey:@"0"];
    // Get brush that determines series point marker background
    LinearGradientBrush *brush = [[bPoint marker] background];
    [[brush gradientStops][1] setColor:[UIColor blueColor]];
    // Get brush settings
    NSMutableDictionary *d1 = [brush dumpConfiguration];
    // Get brush general settings
    NSMutableDictionary *d2 = [brush dumpConfigurationToDict];
    // Get transparency settings
    NSMutableDictionary *opacityDict = [d1 objectForKey:@"opacity"];
    // Set new value of transparency
    [opacityDict setValue:@0.5 forKey:@"value"];
    [d1 setValue:opacityDict forKey:@"opacity"];
    [d2 setValue:d1 forKey:@"LinearGradientBrush"];
    // Create a new brush based on the specified parameters
    LinearGradientBrush *brush2 = [LinearGradientBrush linearGradientBrushWithDict:d2];
    // Set brush for series point marker
    [[bPoint marker] setBackground:brush2];
    // Get clicked object
    UIView *sender = [v hitTest:point withEvent:nil];
    if ([sender isKindOfClass:[ChartPoint class]])
    {
        ChartPoint *pt = (ChartPoint *)sender;
        if (pt.chartLabel)
        {
            // Display point label if it is hidden or hide if it is displayed
            pt.chartLabelVisible = !pt.chartLabelVisible;
            if (pt.chartLabelVisible){
                // Display series point on top of other points
                [pt moveAboveAllByZOrder];
            }
            else{
                // Restore drawing order
                [pt restoreZOrder];
            }
        }
    }
    // Redraw chart
    [chart redrawChart];
}

After executing the example, chart marker size and background colors are changed:

Click the chart central marker.

As a result, the background color is changed, and the marker label is displayed, the marker is displayed on top of other markers:

Click the chart marker again.

As a result, the previous marker drawing order is restored, and the marker label is hidden:

See also:

Examples of Component Use