Custom Annotation


#1

Hello

do you have any example of custom annotations?

We’d need to implement an annotation drawing a png on a chart. What we miss is how to map the x,y coordinates from the axis value ( a date)

Thanks

Paolo


#2

Hi Paolo,

The SChartAnnotation has two properties, xValue and yValue that you use to specify the location, within your data coordinate system, where your annotation is anchored. You must also specify the X & Y axes that the annotation relates to (A chart can have multiple axes for each dimension). Here is a complete example:

// create an annotation
    SChartAnnotation* an = [[SChartAnnotation alloc] init];
    an.xAxis = chart.xAxis;
    an.yAxis = chart.yAxis;
    
    // set its location - using the data coordinate system
    an.xValue = @2;
    an.yValue = @5;
    
    // set bounds
    an.bounds = CGRectMake(0,0,50,50);
    
    // create a UIImageView witha PNG image
    UIImage* image = [UIImage imageNamed:@"icon.png"];
    UIImageView* imageView = [[UIImageView alloc] initWithImage:image];
    
    // add as a subview of the annotation
    [an addSubview:imageView];
    
    // add to the chart
    [chart addAnnotation:an];

#3

Works like a charm. 

Thanks

Paolo


#4

deleted!