Skip to content
bugcloud edited this page Oct 16, 2010 · 4 revisions

These source codes based on s7graphview. s7graphview make you be able to draw graph on iOS. For more about s7graphview, see (http://code.google.com/p/s7graphview/)

I costomed s7graphview blow.

  1. You can define X and Y axis's unit.
  2. You can touch the point of graph. You will draw plot's info writing delegate I added.
  3. If you have emtpy for the value for X axis, s7graphview will ignore the empty value and draw line using next X axis's point that have not empty value.

how to use

{{ 1. You can define X and Y axis's unit. }} Only to add blow 2 properties in your controller.

  • self.graphView_.xUnit
  • self.graphView_.yUnit

{{ 2. You can touch the point of graph. }} Implement the blow method S7GraphViewDelegate.

- (void)graphView:(S7GraphView *)graphView indexOfTappedXaxis:(NSInteger)indexOfTappedXaxis{
  // write your code using index number of X axis's array.
}

{{ 3. When you have emtpy for the value for X axis }} You should add String value to yValues array in blow method S7GraphViewDatasource.

- (NSArray *)graphView:(S7GraphView *)graphView yValuesForPlot:(NSUInteger)plotIndex {

    /* Return the values for a specific graph. Each plot is meant to have equal number of points.
     And this amount should be equal to the amount of elements you return from graphViewXValues: method. */
    NSMutableArray *array = [[NSMutableArray alloc] initWithCapacity:0];
    switch (plotIndex) {
        default:
        case 0:
            for (GraphInfo *gInfo in graphInfoList_.list_) {
                [array addObject:[NSNumber numberWithFloat:gInfo.value_]];
            }
            break;
        case 1:{
            for (int i=0; i<[graphInfoList_.list_ count]; i++) {
                if (i==0) {
                    [array addObject:[NSNumber numberWithFloat:1.1f]];
                } else if (i==[graphInfoList_.list_ count]-1) {
                    [array addObject:[NSNumber numberWithFloat:10.1f]];
                } else {
                    // if you add empty string, a graph will be drawn using next x point.
                    [array addObject:@""];
                }

            }
            break;
        }
    }
    return [array autorelease];
}
Clone this wiki locally