3

I am using Charts library. I want to keep chart max width fix. I didn't find any way to restrict to some width.

enter image description here

James Z
  • 12,209
  • 10
  • 24
  • 44
Santosh Singh
  • 765
  • 11
  • 27

2 Answers2

1

There is a way to make sure the width of a bar is never more than a certain proportion of the screen width. For example setting the setVisibleXRangeMinimum to 10 means each bar will be around 1/10 of the screen width

barChart.setVisibleXRangeMinimum(10.0)

You can also set the maximum:

barChart.setVisibleXRangeMaximum(10.0)
DevB2F
  • 4,674
  • 4
  • 36
  • 60
  • 1
    Let me try that. I was thinking ChartBar will have some method to hard fix it. I will look into it and lets see if it solve my purpose. – Santosh Singh Jan 13 '18 at 05:53
  • But why would you want to have the width fixed? That would make each bar look differently when using different screen sizes. Having the width proportional makes the graph look the same on all screen sizes. – DevB2F Jan 14 '18 at 05:44
  • 1
    I am sharing my code and end result as well for chart configuration. Still not getting the desired result. chartView.leftAxis.spaceBottom = 0.0 chartView.drawBarShadowEnabled = false chartView.drawValueAboveBarEnabled = false let xAxis = chartView.xAxis xAxis.labelCount = dataCount xAxis.labelPosition = .bottom xAxis.granularity = 0.2 let leftAxisFormatter = NumberFormatter() [![enter image description here][1]][1] [1]: https://i.stack.imgur.com/ucuSP.png – Santosh Singh Jan 14 '18 at 08:35
  • 1
    Finally, I am able to find the problem in my code. I was adding long value for X, which was creating the problem. BarChartDataEntry(x: Double(x_Value), y: Double(y_Value)) – Santosh Singh Jan 14 '18 at 14:49
1

Finally, I am able to find the problem in my code. I was adding long value for X, which was creating the problem. I corrected the X value and everything is perfect :)

BarChartDataEntry(x: Double(x_Value), y: Double(y_Value))
Santosh Singh
  • 765
  • 11
  • 27