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

BarChartView height is not reflecting the values assigned to it. #977

Closed
LekhaP opened this issue Apr 25, 2016 · 4 comments
Closed

BarChartView height is not reflecting the values assigned to it. #977

LekhaP opened this issue Apr 25, 2016 · 4 comments

Comments

@LekhaP
Copy link

LekhaP commented Apr 25, 2016

Hi,

Currently what i have right now is
image

The values i am sending to the chart is :
var str: [String] = ["1","2"];
var score: [Double] = [1,0.5];
setChart(str, values: score)

And i have used the formatter as:
let percentageNumberFormatter = NSNumberFormatter()
percentageNumberFormatter.numberStyle = .PercentStyle
chartDataSet.valueFormatter = percentageNumberFormatter

Its not reflecting 100% and 50% in proportion. It rather looks like 100% and 5%.

Could somebody help me understand what i might be doing wrong.

Thank you advance.

@liuxuan30
Copy link
Member

liuxuan30 commented Apr 26, 2016

can you check ChartsDemo? I think you must missed something. But without details we can't say what's wrong.

@LekhaP
Copy link
Author

LekhaP commented Apr 28, 2016

Here is the code i used for the charts.

@IBOutlet var barChartView: BarChartView!

func setChart(dataPoints: [String], values: [Double]) {

    var dataEntries: [BarChartDataEntry] = []
    for i in 0..<dataPoints.count {
        let dataEntry = BarChartDataEntry(value: Double(values[i]), xIndex: i)
        dataEntries.append(dataEntry)
    }

    let chartDataSet = BarChartDataSet(yVals: dataEntries, label:"Quiz Scores on chapters(%)")
    let chartData = BarChartData(xVals: dataPoints, dataSet: chartDataSet)
    barChartView.data = chartData


    // valueFormatter
    let percentageNumberFormatter = NSNumberFormatter()
    percentageNumberFormatter.numberStyle = .PercentStyle
    chartDataSet.valueFormatter = percentageNumberFormatter


    barChartView.data?.setValueFont(UIFont.systemFontOfSize(9.0))
    barChartView.data?.setValueTextColor(UIColor(red: 216/255, green: 76/255, blue: 62/255, alpha: 1))
    chartDataSet.colors = [UIColor(red: 216/255, green: 76/255, blue: 62/255, alpha: 1)]

    barChartView.descriptionText = ""
    barChartView.drawBarShadowEnabled = false;
    barChartView.drawValueAboveBarEnabled = true;

    let xAxis:ChartXAxis = barChartView.xAxis
    xAxis.labelPosition = .Bottom
    xAxis.labelFont = UIFont.systemFontOfSize(9.0)
    xAxis.drawGridLinesEnabled = false
    xAxis.spaceBetweenLabels = 0
    xAxis.labelTextColor = UIColor(red: 77/255, green: 85/255, blue: 95/255, alpha: 1)


    //hide left and right axis
    barChartView.leftAxis.enabled = false
    barChartView.leftAxis.drawGridLinesEnabled = false
    barChartView.rightAxis.enabled = false
    barChartView.rightAxis.drawGridLinesEnabled = false

    barChartView.legend.enabled = false;
    barChartView.userInteractionEnabled = false
}

Thats pretty much all i have.
I looked at the ChartsDemo. It din really help much.

@liuxuan30
Copy link
Member

liuxuan30 commented Apr 29, 2016

try put barChartView.data = chartData at last line of your func. I see you changing lots of view properties after you set data, which is wrong. You either call data setter at last, or manually call notifyDataSetChanged()

@danielgindi
Copy link
Collaborator

You chart is probably being offset. Either by limiting the Y axis with a minimum value that's around 45%, or viewport translations.

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