iOS PNLineChart的点不准确

如果比例较小的时候,还不容易看出来折现标注的点不准确,但是比例小的时候,如y轴为0-5,就可以看出来,x,y都不准确。

修改一个方法的两个地方

- (void)calculateChartPath:(NSMutableArray *)chartPath andPointsPath:(NSMutableArray *)pointsPath andPathKeyPoints:(NSMutableArray *)pathPoints andPathStartEndPoints:(NSMutableArray *)pointsOfPath {

            //  添加 _yValueMax = self.yFixedValueMax;
        _yValueMax = self.yFixedValueMax;
        
        // Draw each line
        for (NSUInteger lineIndex = 0; lineIndex < self.chartData.count; lineIndex++) {
            PNLineChartData *chartData = self.chartData[lineIndex];

            CGFloat yValue;
            CGFloat innerGrade;

            UIBezierPath *progressline = [UIBezierPath bezierPath];

            UIBezierPath *pointPath = [UIBezierPath bezierPath];

            [chartPath insertObject:progressline atIndex:lineIndex];
            [pointsPath insertObject:pointPath atIndex:lineIndex];

            NSMutableArray *gradePathArray = [NSMutableArray array];
            [self.gradeStringPaths addObject:gradePathArray];

            NSMutableArray *linePointsArray = [[NSMutableArray alloc] init];
            NSMutableArray *lineStartEndPointsArray = [[NSMutableArray alloc] init];
            int last_x = 0;
            int last_y = 0;
            NSMutableArray *> *progrssLinePaths = [NSMutableArray new];
            CGFloat inflexionWidth = chartData.inflexionPointWidth;

            for (NSUInteger i = 0; i < chartData.itemCount; i++) {

                yValue = chartData.getData(i).y;

                if (!(_yValueMax - _yValueMin)) {
                    innerGrade = 0.5;
                } else {
                    innerGrade = (yValue - _yValueMin) / (_yValueMax - _yValueMin);
                }
        
                        // 加上对yAxisOffset偏移
                CGFloat yAxisOffset = 10.f;
                
                int x = i * _xLabelWidth + _chartMarginLeft + _xLabelWidth / 2.0 + yAxisOffset;

最近,看了JBChartView,这个从设计上可能更好,相较于PNChart更容易读懂,也没有出现点位置不对的情况,准备替换项目里的PNChart。JBChartView的设计借鉴了UITableView,将图标分成一段一段的,可以像设置cell那样设置每一段的情况,代码写起来和创建UITableView没什么区别。

你可能感兴趣的:(iOS PNLineChart的点不准确)