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

Bar height is calculated wrong #1031

Closed
inatu opened this issue May 13, 2016 · 2 comments
Closed

Bar height is calculated wrong #1031

inatu opened this issue May 13, 2016 · 2 comments

Comments

@inatu
Copy link

inatu commented May 13, 2016

When I write my code like this, I find that the height of the bar is too big, and if I use the custom renderer, it just not work correctly. Any hint will be thankful.

    let chart = BarChartView()
    chart.backgroundColor = UIColor.whiteColor()

    chart.clipsToBounds = false
    chart.extraLeftOffset = 20.0
    chart.extraRightOffset = 30.0
    chart.descriptionText = ""
    chart.legend.enabled = false
    chart.pinchZoomEnabled = false
    chart.scaleYEnabled = false
    chart.scaleXEnabled = false
    chart.drawBordersEnabled = false
    chart.zoom(8.0, scaleY: 1.0, x: 0, y: 0)

    let xAxis = chart.xAxis
    xAxis.labelFont = UIFont.systemFontOfSize(10.0)
    xAxis.labelTextColor = UIColor(hex6: 0x000000, alpha: 0.87)
    xAxis.labelPosition = .Bottom
    xAxis.drawAxisLineEnabled = false
    xAxis.yOffset = 8.0
    xAxis.drawGridLinesEnabled = false


    let limitLine = ChartLimitLine(limit: 30, label: "达标\n30")
    limitLine.lineWidth = 1.0
    limitLine.lineDashLengths = [2.0, 2.0]
    limitLine.lineColor = UIColor(hex6: 0xD8D8D8)
    limitLine.labelPosition = .RightTop
    limitLine.xOffset = -30.0
    limitLine.valueFont = UIFont.systemFontOfSize(10.0)
    limitLine.valueTextColor = UIColor(hex6: 0x000000).colorWithAlphaComponent(0.54)


    let leftYAxis = chart.leftAxis
    leftYAxis.enabled = false

    let rightYAxis = chart.rightAxis
    rightYAxis.setLabelCount(0, force: true)
    rightYAxis.axisMinValue = 0
    rightYAxis.drawZeroLineEnabled = false
    rightYAxis.drawAxisLineEnabled = false
    rightYAxis.drawTopYLabelEntryEnabled = false
    rightYAxis.drawLabelsEnabled = false
    rightYAxis.addLimitLine(limitLine)

    var xVals = [String]()
    var yVals = [BarChartDataEntry]()
    for (index, point) in points.enumerate()
    {
      xVals.append(point.x)
      yVals.append(BarChartDataEntry(value: point.y, xIndex: index))
    }

    let dataSet = BarChartDataSet(yVals: yVals, label: nil)
    dataSet.setColor(UIColor(hex6: 0xF8BC1C), alpha: 1.0)
    dataSet.drawValuesEnabled = false
    dataSet.highlightEnabled = false
    dataSet.barSpace = 0.7
    let chartData = BarChartData(xVals: xVals, dataSet: dataSet)
    chart.data = chartData

    performanceDetailTimeView.chart = chart

    if timeViewDisplayed
    {
      performanceDetailTimeView.loadChart() // the chart will be added to a view, like  chartView.addSubview(chart), chart.frame = chartView.bounds

      chart.moveViewToX(CGFloat(points.count))
    }
```swift
@inatu
Copy link
Author

inatu commented May 13, 2016

for example, one point being transformed to

▿ CGRect
  ▿ origin : CGPoint
    - x : -2268.3466666666664
    - y : 211.7275390625
  ▿ size : CGSize
    - width : 14.559999999999945
    - height : 4075.3038194444398 { ... }

@liuxuan30
Copy link
Member

liuxuan30 commented May 16, 2016

well, since you mentioned a custom renderer, your should first understand how the bar is calculated and renderered and debug on your side.
The only hint I can say is, the transformer's matrix is a mess. It looks like first you should draw a normal bar chart and then try set the scale and other properties that's related to matrix.

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

2 participants