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<NSDictionary<NSString *, NSValue *> *> *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没什么区别。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 一、实验目的 学习使用 weka 中的常用分类器,完成数据分类任务。 二、实验内容 了解 weka 中 explo...
    yigoh阅读 8,662评论 5 4
  • 发现 关注 消息 iOS 第三方库、插件、知名博客总结 作者大灰狼的小绵羊哥哥关注 2017.06.26 09:4...
    肇东周阅读 12,262评论 4 61
  • 刘长战先生是我的小学班主任,从四年级至六年级,舍去其间他被调任初二班主任的半年,我们一起生活了两年半的动人时光。 ...
    猪鼻子插葱阅读 378评论 1 2
  • 晨读概要 彰显自信的习惯 我一直相信,自信也是一种气质,它流露于举手投足间。生活中,我对那种自信的人都特别地有好感...
    一半一半zyh阅读 143评论 0 3
  • [cp]即使我没有走过千山万水, 也不曾满身经验与圆滑, 但 我也有勇气 走过陌生的街巷 遇见陌生的人群。 这人世...
    莫嵇雪阅读 94评论 0 1