如果比例較小的時候,還不容易看出來折現(xiàn)標注的點不準確勺择,但是比例小的時候创南,如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气忠,這個從設(shè)計上可能更好,相較于PNChart更容易讀懂赋咽,也沒有出現(xiàn)點位置不對的情況旧噪,準備替換項目里的PNChart。JBChartView的設(shè)計借鑒了UITableView,將圖標分成一段一段的脓匿,可以像設(shè)置cell那樣設(shè)置每一段的情況淘钟,代碼寫起來和創(chuàng)建UITableView沒什么區(qū)別。