Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chart in TableViewCell #1247

Closed
Baldman68 opened this issue Jul 13, 2016 · 2 comments
Closed

Chart in TableViewCell #1247

Baldman68 opened this issue Jul 13, 2016 · 2 comments

Comments

@Baldman68
Copy link

Hi, forgive me if this question has been asked and answered but I have not have been able to find an answer in my searches. I am trying to create a line chart in a TableViewCell using Swift in iOS. It appears the chart is working correct, however, when I first see the chart it doesn't display correctly.
img_5466

If I tap on the chart it displays for an instant, but if I long press (I have set up no gesture recognizers) I then see the chart displayed correctly. (Other than the fact that it still says No chart data available)
img_5467

The code I'm using is below. Any help you can give will be greatly appreciated!

`//MARK: - Chart Stuff
func buildChart(){
lineChart.delegate = self;

    lineChart.descriptionText = "";
    lineChart.noDataTextDescription = "Data will be loaded soon."

    lineChart.maxVisibleValueCount = 60
    lineChart.pinchZoomEnabled = true
    lineChart.drawGridBackgroundEnabled = false
    lineChart.drawBordersEnabled = true

    loadData()
}

func loadData(){
    // 1 - creating an array of data entries
    var yVals1 : [ChartDataEntry] = [ChartDataEntry]()
    for i in 0 ..< allCheckIns.count {
        let checkIn: CheckIn = allCheckIns[i]
        yVals1.append(ChartDataEntry(value: checkIn.weight, xIndex: i))
    }

    // 2 - create a data set with our array
    let set1: LineChartDataSet = LineChartDataSet(yVals: yVals1, label: "Progress")
    set1.axisDependency = .Left // Line will correlate with left axis values
    set1.setColor(UIColor.redColor().colorWithAlphaComponent(0.5)) // our line's opacity is 50%
    set1.setCircleColor(UIColor.redColor()) // our circle will be dark red
    set1.lineWidth = 2.0
    set1.circleRadius = 6.0 // the radius of the node circle
    set1.fillAlpha = 65 / 255.0
    set1.fillColor = UIColor.redColor()
    set1.highlightColor = UIColor.whiteColor()
    set1.drawCircleHoleEnabled = true

    //3 - create an array to store our LineChartDataSets
    var dataSets : [LineChartDataSet] = [LineChartDataSet]()
    dataSets.append(set1)

    //4 - pass our months in for our x-axis label value along with our dataSets
    let timeFormatter = NSDateFormatter()
    timeFormatter.dateFormat = "MM-dd-YYYY"


    var dates: [String] = []
    for item in allCheckIns {
        let dateToDisplay: String = timeFormatter.stringFromDate(item.date)
        dates.append(dateToDisplay)
    }

    let data: LineChartData = LineChartData(xVals: dates, dataSets: dataSets)
    data.setValueTextColor(UIColor.whiteColor())

    //5 - finally set our data
    self.lineChart.data = data

// var myIndexPath: [NSIndexPath] = []
// myIndexPath.append(NSIndexPath(forRow: 0, inSection: 0))
// self.tableView.reloadRowsAtIndexPaths(myIndexPath, withRowAnimation: UITableViewRowAnimation.Fade)

}

`

@liuxuan30
Copy link
Member

well, I think there is something wrong in your UITableViewCell synergy with displaying some content. And I think it's beyond this project scope.

What I would suggest is looking at the cell frame, chart view frame, and when the data start loading, when cell start to display, etc. Again, it most likely your table view cell logic issues.

@tigert1998
Copy link

Have you fixed this problem?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants