ArthurGuibert/FSLineChart

Calling setChartData: with an array containing one data point will crash the chart

4Kicks opened this issue · 3 comments

In a number of locations, calculations are done using (_data.count - 1), e.g. line 134 (https://github.com/ArthurGuibert/FSLineChart/blob/master/FSLineChart/FSLineChart/FSLineChart.m#L134).

There are a number of other locations where this assumption (_data.count > 1) is made. The crashes are happening because these calculated values end up being NaN.

In addition to empty data arrays, it looks like the code needs to safeguard against data arrays containing one value.

In the drawRect method , the library just want to draw lines with point more than ones. So just add an if else in it and draw one point if the data just contains only one point.

发自我的 iPhone

在 2015年3月16日,上午5:17,4Kicks notifications@github.com 写道:

In a number of locations, calculations are done using (_data.count - 1), e.g. line 134 (https://github.com/ArthurGuibert/FSLineChart/blob/master/FSLineChart/FSLineChart/FSLineChart.m#L134).

There are a number of other locations where this assumption (_data.count > 1) is made. The crashes are happening because these calculated values end up being NaN.

In addition to empty data arrays, it looks like the code needs to safeguard against data arrays containing one value.


Reply to this email directly or view it on GitHub.

This is fixed with 9306d81

Recommending close issue

Fix Needs to be added here if Data Points are needed:

  • (void)strokeDataPoints
    {
    CGFloat minBound = [self minVerticalBound];
    CGFloat maxBound = [self maxVerticalBound];
    CGFloat scale = _axisHeight / (maxBound - minBound);

    if (minBound == 0 && maxBound == 0) {
    scale = _axisHeight;
    }