ChartsOrg / ChartsOrg/Charts

setViewPortOffsets does not work on Horizontal BarChartView

Open
#2,853 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
Swift
Stars
28k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

I want to create offset for _horizontalBarChart_, However, it does not work.

```
let ys1 = [model.totalIncome, abs(model.totalExpense)]

var yse1 = ys1.enumerated().map { x, y -> BarChartDataEntry in
return BarChartDataEntry(x: Double(x), y: y)
}

let count = 2
let data = BarChartData()
let ds1 = BarChartDataSet(values: yse1, label: "")
ds1.colors = [UIColor.red, UIColor.blue]

// Number formatting of Values
ds1.valueFormatter = YAxisValueFormatter()
ds1.valueFont = UIFont(fontType: .H6)!
ds1.valueTextColor = UIColor.dark_text
ds1.iconsOffset = CGPoint(x: 350.0, y: 350.0)

// Data set
data.addDataSet(ds1)
horizontalBarChartView.data = data

// General setting
horizontalBarChartView.xAxis.drawLabelsEnabled = false
horizontalBarChartView.setScaleEnabled(false)
//horizontalBarChartView.zoomToCenter(scaleX: count > 6 ? CGFloat(count) / 6.0 : 1.0, scaleY: 1.0)

// Grid
horizontalBarChartView.xAxis.drawGridLinesEnabled = false
horizontalBarChartView.leftAxis.gridLineDashLengths = [15.0, 15.0]
horizontalBarChartView.leftAxis.gridColor = UIColor.palette_28
horizontalBarChartView.rightAxis.drawGridLinesEnabled = false
horizontalBarChartView.xAxis.valueFormatter = IndexAxisValueFormatter(values: ["A","b"])
horizontalBarChartView.xAxis.granularityEnabled = true
horizontalBarChartView.xAxis.granularity = 1
horizontalBarChartView.xAxis.labelPosition = .bottomInside


// Disable number formatting of leftAxis and rightAxis
horizontalBarChartView.leftAxis.enabled = false
horizontalBarChartView.rightAxis.enabled = false


// setViewPortOffsets
let digitCount = Int(data.yMax).digitCount
let leftOffset: CGFloat = digitCount > 2 ? CGFloat((digitCount - 1) * 10) : 10.0
horizontalBarChartView.setViewPortOffsets(left: leftOffset, top: 200, right: 100, bottom: 100)

// https://github.com/danielgindi/Charts/issues/2063
horizontalBarChartView.leftAxis.axisMinimum = 0

horizontalBarChartView.data?.notifyDataChanged()

```
I created **horizontalBarChartView** programmatically

```
lazy var horizontalBarChartView: HorizontalBarChartView = {
let chartView = HorizontalBarChartView()
chartView.contentMode = .scaleAspectFit
chartView.drawBordersEnabled = false
chartView.drawGridBackgroundEnabled = false
chartView.gridBackgroundColor = UIColor.clear
chartView.legend.enabled = false
chartView.chartDescription = nil
chartView.highlighter = nil
chartView.clipsToBounds = true
chartView.translatesAutoresizingMaskIntoConstraints = false
return chartView
}()
```

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the supplied programmatic HorizontalBarChartView setup, focusing on the setViewPortOffsets call and the later leftAxis.axisMinimum change. Trace how HorizontalBarChartView applies viewport offsets and determine why the requested left, top, right, and bottom values are not reflected; done means those offsets visibly affect the chart.

Written by the indexing model from the issue text.

Assessment

Tech stack
swift
Domain
mobile-dev
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.