ChartsOrg / ChartsOrg/Charts

y Axis Skips

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

Description

Here are my Y Axis labels: ["0","1","2","3","4","5"]

It Skips at three.

Here's my code:

`class ReviewDetailVC: UIViewController, ChartViewDelegate {


@IBOutlet weak var chartView: LineChartView!

var yValues = [Double]()
var yLabels = [String]()
var months = [String]()
var xValues = [String]()
let red = UIColor(hue: 0.9639, saturation: 0.62, brightness: 0.93, alpha: 1.0)
let black = UIColor(red:0.29, green:0.29, blue:0.29, alpha:1.0)
let grey = UIColor(red:0.81, green:0.81, blue:0.81, alpha:1.0)

let avenirDemi = UIFont(name: "AvenirNext-DemiBold", size: 14)
override func viewDidLoad() {
super.viewDidLoad()

chartView.delegate = self
// Chart Ui Settings

chartView.leftAxis.axisMinimum = 0
chartView.leftAxis.axisMaximum = 5
chartView.leftAxis.labelCount = 7

chartView.chartDescription?.text = ""
chartView.xAxis.labelPosition = .bottom
chartView.legend.enabled = false
chartView.scaleYEnabled = false
chartView.scaleXEnabled = true
chartView.doubleTapToZoomEnabled = false
chartView.highlighter = nil
chartView.rightAxis.enabled = false
chartView.xAxis.drawGridLinesEnabled = false
chartView.dragEnabled = true
chartView.scaleXEnabled = false
chartView.scaleYEnabled = false
chartView.zoom(scaleX: 4, scaleY: 1, x: 0, y: CGFloat(AxisDependency.left.rawValue))
chartView.xAxis.labelFont = avenirDemi!
chartView.xAxis.labelTextColor = grey
chartView.leftAxis.labelFont = avenirDemi!
chartView.leftAxis.labelTextColor = black
chartView.xAxis.axisLineWidth = 0
chartView.leftAxis.axisLineWidth = 0
chartView.leftAxis.granularity = 1
chartView.xAxis.avoidFirstLastClippingEnabled = true
chartView.xAxis.granularityEnabled = true
chartView.xAxis.granularity = 1
chartView.xAxis.axisMinimum = 0.0
chartView.leftAxis.gridColor = grey
chartView.leftAxis.gridLineDashLengths = [4]
chartView.leftAxis.gridLineWidth = 1.5
chartView.xAxis.centerAxisLabelsEnabled = true
chartView.noDataText = "This person has not reviewed your business."

xValues = ["MAR 10"," MAR 15", "APR 7", "APR 8", "APR 15", "APR 30", "MAY 14", "MAY 21","MAY 31", "MAY 31"]
yLabels = ["0","1","2","3","4","5"]
yValues = [0,2,4,5,3,4,2,4,5,4,4]

let Xformatter = CustomLabelsAxisValueFormatter()
Xformatter.labels = xValues
let Yformatter = CustomYAxisLabelValueFormatter()
Yformatter.Ylabels = yLabels

chartView.xAxis.valueFormatter = Xformatter
chartView.leftAxis.valueFormatter = Yformatter



chartView.animate(yAxisDuration: 1)

setChart(dataPoints: xValues, values: yValues)


}



func setChart(dataPoints: [String], values: [Double]) {
chartView.noDataText = "You need to provide data for the chart."

var dataEntries: [ChartDataEntry] = []

for i in 0.. String {
let count = self.labels.count

guard let axis = axis, count > 0 else {

return ""
}

let factor = axis.axisMaximum / Double(count)

let index = Int((value / factor).rounded())

if index >= 0 && index < count {

return self.labels[index]
}

return ""
}


}

class CustomYAxisLabelValueFormatter : NSObject, IAxisValueFormatter {


var Ylabels: [String] = []

func stringForValue(_ value: Double, axis: AxisBase?) -> String {
let count = self.Ylabels.count

guard let axis = axis, count > 0 else {

return ""
}

let factor = axis.axisMaximum / Double(count)

let index = Int((value / factor).rounded())

if index >= 0 && index < count {

return self.Ylabels[index]
}

return ""
}


}`

Contributor guide

Open the contributing guide

Research direction

Start with the CustomYAxisLabelValueFormatter shown in the issue and its assignment to chartView.leftAxis.valueFormatter, then reproduce the chart using the provided yLabels, axisMaximum, and labelCount values. Done means the rendered Y axis displays all labels from 0 through 5 without skipping 3.

Written by the indexing model from the issue text.

Assessment

Tech stack
swift
Domain
data-visualization, mobile-dev
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.