ChartsOrg / ChartsOrg/Charts

Bar Chart xVals Issues - Force Left Alignment and Labels are being overlapped

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

Description

Hello

I am experiencing 2 issues with the barchart control please see below:

**Issue 1**
The xVals are not being left aligned and do not center within each individual Bar on the graph. Please can you advise how I can make it possible that the labels are left aligned rather the current right alignment that I am seeing. Please see screenshot below:

screen shot 2017-03-24 at 20 59 56

** Issue 2 **
The xVals are appearing overlapped when the label length is above 18 characters. Is it possible to increase the space between each Bar when using the BarGraph control? I have tried numerous things from StackOverflow and from reading the Issues raised on GitHub but have still not been able to tackle this problem. Please see screenshot below:

screen shot 2017-03-24 at 21 00 01

Please see all code being used to update the Bar Graph below:

```
// XAxis
let xAxis:XAxis = barChart.xAxis
xAxis.labelPosition = XAxis.LabelPosition.bottom
xAxis.labelFont = Constants.Font.fontWithSize(Constants.Font.Gotham, size: 10)
xAxis.labelWidth = CGFloat(2.0)
xAxis.drawGridLinesEnabled = false;
xAxis.centerAxisLabelsEnabled = true
xAxis.avoidFirstLastClippingEnabled = true
xAxis.wordWrapEnabled = true
xAxis.granularityEnabled = true

barChart.legend.enabled = false
barChart.rightAxis.enabled = false
barChart.leftAxis.enabled = false
barChart.xAxis.enabled = true
```

```
if xVals.count > 0 && yVals.count > 0 {
let set1:BarChartDataSet = BarChartDataSet(values: yVals, label: "DataSet")

set1.setColor(Constants.Color.Black)
set1.drawValuesEnabled = false
set1.highlightAlpha = 0.7
set1.highlightColor = Constants.Color.Blue

let data:BarChartData = BarChartData(dataSet: set1)
data.setValueFont(Constants.Font.fontWithSize(Constants.Font.GothamBook, size: 10))

barChart.xAxis.valueFormatter = IndexAxisValueFormatter(values: xVals)
barChart.xAxis.labelCount = xVals.count
barChart.xAxis.wordWrapEnabled = false

barChart.data = data;

barChart.setVisibleXRangeMinimum(visibleXRange)
barChart.setVisibleXRangeMaximum(visibleXRange)
}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.