Zomato / DR-charts

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Bar Chart Overlapping issue

mrimadali opened this issue · comments

Dear @dhirenthirani

For Bar Graph, I'm returning the number of Bar to be plotted as 3, the 2nd and 3rd bar line is overlapping with each other.
To test, Pls return "3" bars for numberOfBarsToBePlotted datasource method.
Please let me know any changes to be made in the library.

Best,
Imad

Hey,
Sorry for late reply.
I will check and will let you know wen its fixed.

Thanks for your reply.
Now it can be used for multiple bar chart lines.
I fixed this by adding following in the class (BarChart.m) & method (createGraph).

int counter = 0;
 for (BarChartDataRenderer *barData in self.barDataArray) {
for (int i = 0; i < barData.yAxisArray.count; i++){
            startPoint = CGPointMake(x+OFFSET_X + counter*barWidth + barData.barWidth, HEIGHT(self.graphView) - (OFFSET_Y + y));
            endPoint = CGPointMake(x+OFFSET_X + counter*barWidth, HEIGHT(self.graphView) - OFFSET_Y);

}
counter++;
}

thanks
Still I will check it once.

Full code for fix:

  • (void)createGraph{
    CGFloat barWidth = 0;
    int counter = 0;
    for (BarChartDataRenderer *barData in self.barDataArray) {
    int x = 0;
    int y = 0;

      CGPoint startPoint;
      CGPoint endPoint;
      
      for (int i = 0; i < barData.yAxisArray.count; i++){
          x = i * stepX;
          y = [[barData.yAxisArray objectAtIndex:i] floatValue] * stepY;
          
          startPoint = CGPointMake(x+OFFSET_X + counter*barWidth + barData.barWidth, HEIGHT(self.graphView) - (OFFSET_Y + y));
          endPoint = CGPointMake(x+OFFSET_X + counter*barWidth, HEIGHT(self.graphView) - OFFSET_Y);
    
          
          CAShapeLayer *shapeLayer = [[CAShapeLayer alloc] init];
          [shapeLayer setPath:[[self drawBarPathWithStartPoint:endPoint endPoint:startPoint] CGPath]];
          [shapeLayer setStrokeColor:[barData.barColor CGColor]];
          [shapeLayer setFillColor:[barData.barColor CGColor]];
          [shapeLayer setFillRule:kCAFillRuleEvenOdd];
          [shapeLayer setLineWidth:0.5f];
          [shapeLayer setOpacity:0.7f];
          [shapeLayer setShadowRadius:0.0f];
          [shapeLayer setShadowColor:[[UIColor clearColor] CGColor]];
          [shapeLayer setShadowOpacity:0.0f];
          [shapeLayer setValue:[barData.yAxisArray objectAtIndex:i] forKey:@"data"];
          
          [CATransaction begin];
          
          CABasicAnimation *pathAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
          [pathAnimation setFromValue:[NSNumber numberWithFloat:0.0f]];
          [pathAnimation setToValue:[NSNumber numberWithFloat:1.0f]];
          
          CABasicAnimation *fillColorAnimation = [CABasicAnimation animationWithKeyPath:@"fillColor"];
          [fillColorAnimation setFromValue:(id)[[UIColor clearColor] CGColor]];
          [fillColorAnimation setToValue:(id)[barData.barColor CGColor]];
          
          CAAnimationGroup *group = [[CAAnimationGroup alloc] init];
          [group setAnimations:[NSArray arrayWithObjects:pathAnimation,fillColorAnimation, nil]];
          [group setDuration:ANIMATION_DURATION];
          [group setFillMode:kCAFillModeBoth];
          [group setRemovedOnCompletion:FALSE];
          [group setBeginTime:CACurrentMediaTime()];
          [group setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]];
          
          [shapeLayer addAnimation:group forKey:@"animate"];
          
          [CATransaction commit];
          
          [self.graphView.layer addSublayer:shapeLayer];
      }
      barWidth = barData.barWidth;
      counter++;
    

    }
    }