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

HorizontalBarChart values not showing Charts 3.0 #1731

Closed
mecid opened this issue Oct 27, 2016 · 10 comments
Closed

HorizontalBarChart values not showing Charts 3.0 #1731

mecid opened this issue Oct 27, 2016 · 10 comments

Comments

@mecid
Copy link

mecid commented Oct 27, 2016

I have code like this for Charts version 2.2
`
private func setupHorizontalBarChart(samples: [HKQuantitySample]) {
let formatter = HeartRateFormatter()
formatter.activity = activity
formatter.age = userAge

    let dataset = BarChartDataSet()
    dataset.valueFont = UIFont.preferredFont(forTextStyle: UIFontTextStyle.caption1)
    dataset.valueFormatter = DefaultValueFormatter(formatter: formatter)
    dataset.valueTextColor = UIColor.white
    dataset.resetColors()

    var xVals: [String] = []

    var index = 0

    for sample in samples.reversed() {
        xVals.append(timeFormatter.string(from: sample.endDate))
        let value = sample.quantity.doubleValue(for: HKUnit.heartRate())
        let rate = HeartRate(activity: activity!, value: Int(value), age: userAge)

        if dataset.addEntry(BarChartDataEntry(x: Double(index), y: value)) {
            dataset.addColor(rate.status.color())
            index = index + 1
        }
    }

    horizontalBarChartHeight.constant = CGFloat(30 * xVals.count)
    horizontalBarChart.data = BarChartData(dataSet: dataset)
    horizontalBarChart.xAxis.labelCount = xVals.count

    horizontalBarChart.xAxis.valueFormatter = DefaultAxisValueFormatter { (value, axis) -> String in
        return xVals[Int(value)]
    }
}

`

2016-10-27 18 21 05

But with latest version of Charts3.0

14813278_1219891058050049_881733370_o

How can i fix problem?

@mecid mecid changed the title HorizontalBarChart values not showing HorizontalBarChart values not showing Charts 3.0 Oct 27, 2016
@liuxuan30
Copy link
Member

liuxuan30 commented Oct 31, 2016

are you talking about x axis labels, or bar values? ChartsDemo - horizontal bar chart can draw bar values.
For x axis value not showing each one, force labelCount = your x vals count

@danielgindi
Copy link
Collaborator

When posting screenshots to compare - please give screenshots with the same data. From the screenshots being very different it is hard to figure out the problem.
Anyway if you're talking about the labels missing every 2nd label - then please check your configuration. See the demo, it works and shows the values, so there isn't any missing functionality.

@mecid
Copy link
Author

mecid commented Oct 31, 2016

@danielgindi i gave this screens because data not important for this case.
More important chart configuration. Same code give different results.

@mecid
Copy link
Author

mecid commented Oct 31, 2016

@liuxuan30 as you see in my code snippet i was set
horizontalBarChart.xAxis.labelCount = xVals.count

But this is not working for me.

And why bar chart values not showing?

@danielgindi
Copy link
Collaborator

It's about your configuration, so you should compare yours to one of the demos, or post a working sample project so we can test it. When you do - please re-open the issue.

@liuxuan30
Copy link
Member

liuxuan30 commented Nov 2, 2016

@mecid so I am confused what labels are you asking - either x value labels, or just data value labels? If you are talking about data values, then I think you might miss some setup.

My code just wants to fix the x value labels appears every 2nd.

@kkontus
Copy link

kkontus commented Nov 2, 2016

@liuxuan30 can you show me an example how to show label on every 2nd bar (because I need to show 6 bars with labels that have following format: 2016-06, 2016-07, 2016-08, 2016-09, 2016-10, 2016-11). Since labels are pretty long it would be great if I could show every 2nd label. Here are the screenshots of what I want to accomplish (first one is Android version 2.2.5 just to see what I need and the second is from an iOS app with v3.0.0)

for now I'm using:
barChartView.xAxis.valueFormatter = DefaultAxisValueFormatter { (value, axis) -> String in return self.dataPoints[Int(value)] }

imageedit_2_5990845091
imageedit_4_6145158700

@kkontus
Copy link

kkontus commented Nov 2, 2016

@liuxuan30 found the solution, I needed granularity
barChartView.xAxis.granularity = 2.0

btw, sorry for posting on closed issue, didn't see that

@nmdias
Copy link

nmdias commented Jun 28, 2017

Setting the labelCount to the number of xAxis values did it for me. Maybe it should've behaved the other way around? Show every label by default, and let the user adjust in case they don't fit.

simulator screen shot 28 jun 2017 11 45 20

After setting labelCount:

self.horizontalBarChart.xAxis.labelCount = chartModel.items?.count ?? 0

Feels somewhat awkward comparing from the previous versions (before swift 3).

simulator screen shot 28 jun 2017 11 45 55

@Schabaani
Copy link

@nmdias Sorry that post here. How did you add some string labels on left of HorizonalBarChart

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

6 participants