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 displays values, but no bars #2744

Closed
FasterThanLlamas opened this issue Aug 22, 2017 · 6 comments
Closed

Chart displays values, but no bars #2744

FasterThanLlamas opened this issue Aug 22, 2017 · 6 comments

Comments

@FasterThanLlamas
Copy link

func updateChartWithData() {
    for diaper in realm.objects(SubmittedEntry.self).filter("diaperWasChanged = true") {
        diaperEntries.append(diaper.submissionTime!)
    }
    for i in 0..<diaperEntries.count {
        let timeIntervalForDate: TimeInterval = diaperEntries[i].timeIntervalSince1970
        let dataEntry = BarChartDataEntry(x: Double(timeIntervalForDate), y: 1.0)
        dataEntries.append(dataEntry)
    }
    let chartDataSet = BarChartDataSet(values: dataEntries, label: "Diaper count")
    let chartData = BarChartData(dataSet: chartDataSet)
    barView.data = chartData

    let xaxis = barView.xAxis
    xaxis.valueFormatter = axisFormatDelegate
}

screen shot 2017-08-21 at 6 50 20 pm

@seenoevo
Copy link

show code of what your stringForValue looks like, you're probably not formatting it correctly

look at similar code here if you need guidance: #2215

@FasterThanLlamas
Copy link
Author

extension ChartsViewController: IAxisValueFormatter {
    
    func stringForValue(_ value: Double, axis: AxisBase?) -> String {
        let dateFormatter = DateFormatter()
        dateFormatter.dateFormat = "MMM d, yyyy"
        return dateFormatter.string(from: Date(timeIntervalSince1970: value))
    }
}

@seenoevo
Copy link

seenoevo commented Aug 22, 2017

you are incorrectly passing in timeIntervalForDate instead of the index i into BarChartDataEntry(x: Double(timeIntervalForDate), y: 1.0)

just look at BarChartViewController.m and its associated DayAxisValueFormatter.m to see how it's done, it's similar to how you're doing it

@FasterThanLlamas
Copy link
Author

Are there Swift versions?

@seenoevo
Copy link

no there is not, but you can see that the code is very similar

for example you can see in BarChartViewController.m:

    for (int i = start; i < start + count + 1; i++)
    {
        double mult = (range + 1);
        double val = (double) (arc4random_uniform(mult));
        if (arc4random_uniform(100) < 25) {
            [yVals addObject:[[BarChartDataEntry alloc] initWithX:i y:val icon: [UIImage imageNamed:@"icon"]]];
        } else {
            [yVals addObject:[[BarChartDataEntry alloc] initWithX:i y:val]];
        }
}

Notice it is passing in the index i in initWithX:i

As I mentioned, give it a barWidth and see what happens because I dont see that in your code, so the chart does not know how to size the bar correctly

@fabio90h
Copy link

can put your code up as an example?
Im still confused on what to do.

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

4 participants