Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Real Time Data and Moving X happens automatically ? #610

Closed
ArEnSc opened this issue Dec 14, 2015 · 0 comments
Closed

Real Time Data and Moving X happens automatically ? #610

ArEnSc opened this issue Dec 14, 2015 · 0 comments

Comments

@ArEnSc
Copy link

ArEnSc commented Dec 14, 2015

When I add entries into the graph, it continiously grows and expands the x axis, even when I clear the buffer to keep the size of the graph small, it expands the graph and only draws within the x 64 - 128 region.

The result is that the graph gets small and the graph expands for no reason. ill post an image.

I am just trying to get the graph to pop the previous x and y points to prevent a data overflow and keep the window size to be large enough to show 128 data points.

Any advice?

-(void) setupGraphy {
    // Delegate
    self.graphy.delegate = self;

    // Descriptions
    self.graphy.descriptionText = @"";
    self.graphy.noDataTextDescription = @"You need to start recording";

    // Actions
    self.graphy.dragEnabled = YES;
    self.graphy.scaleXEnabled = YES;
    self.graphy.drawGridBackgroundEnabled = YES;
    self.graphy.pinchZoomEnabled = NO;

    // x Axis is every 16 miliseconds

    // Raw Data -> ChartEntries -> ChartDataSet -> Multiple ChartDataSets ->

    // create the y values data entry on the chart.
    NSMutableArray* chartDataEntries = [NSMutableArray array];

    /**
    for (int i = 0; i < [ax count];i++ ) {
        ChartDataEntry* entry = [[ChartDataEntry alloc] initWithValue:[ax[i] doubleValue] xIndex:i];
        [chartDataEntries addObject:entry];
    }**/

    self.setAx = [[LineChartDataSet alloc] initWithYVals:chartDataEntries];

    self.setAx.axisDependency = AxisDependencyLeft;
    [self.setAx setColor:[UIColor flatRedColor]];
    [self.setAx setCircleColor:[UIColor flatRedColorDark]];


    self.setAx.lineWidth = 0.5;
    self.setAx.circleRadius = 0.1;
    self.setAx.fillAlpha = 65/255.0;
    self.setAx.fillColor = [UIColor flatWhiteColor];
    self.setAx.drawCircleHoleEnabled = NO;

    self.data = [[LineChartData alloc] initWithXVals:[NSMutableArray array] dataSet:self.setAx];

    // Adds entry to the data set
    //[data addEntry:0 dataSetIndex:0];
    //self.graphy moveViewToX:];
    //[self.graphy notifyDataSetChanged];
    self.graphy.data = self.data;

}


- (IBAction)startRecordingPressed:(id)sender {

    UIButton* button = sender;

    __weak typeof(self) weakSelf = self;

    // If the text is Start recording start recording and change the text to stop hack I know
    if([button.titleLabel.text isEqualToString:@"Start Recording"]) {

    button.titleLabel.text = @"Stop Recording";

    [self.motionManager startAccelerometerUpdatesToQueue:self.aQueue withHandler:^(CMAccelerometerData * _Nullable accelerometerData, NSError * _Nullable error) {

        SensorData* data = [[SensorData alloc] initWithType:SensorAccelerometer andX:accelerometerData.acceleration.x andY:accelerometerData.acceleration.y andZ:accelerometerData.acceleration.z];

        static int s = 0;
        s = (s + 1) % 128;
        __block ChartDataEntry* entry = [[ChartDataEntry alloc] initWithValue:accelerometerData.acceleration.x xIndex:s];


        dispatch_async(dispatch_get_main_queue(), ^{
            [self.data addEntry:entry dataSetIndex:0];
            NSString* v = [NSString stringWithFormat:@"%zd",s];
            NSLog(@"%@",v);
            [self.data addXValue:v];
            //[self.graphy moveViewToX:s];

            if (s > 64) {
                [self.data removeXValue:0];
                [self.data removeEntryByXIndex:0 dataSetIndex:0];
            }

            [self.graphy notifyDataSetChanged];



        });


    }];
}
@ArEnSc ArEnSc closed this as completed Dec 14, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant