How can I customize the highlighter in Line Charts? I want to cut the highlight to be drawn only up to the data point. I also want to customize the label on the x-axis where it's highlighted. Below is a reference picture on what I'm trying to achieve.
This is what I've done so far. What I've achieved so far
Below is the code for my Line Chart View Setup
let lineChartView: LineChartView = {
let chart = LineChartView(frame: .zero)
chart.chartDescription = nil
chart.dragEnabled = true
chart.scaleYEnabled = false
chart.scaleXEnabled = true
chart.pinchZoomEnabled = false
chart.drawGridBackgroundEnabled = true
chart.gridBackgroundColor = .clear
chart.legend.enabled = false
chart.zoom(scaleX: 2, scaleY: 1, x: 0, y: 0)
chart.setViewPortOffsets(left: 30, top: 30, right: 30, bottom: 30)
chart.rightAxis.enabled = false
let yAxis = chart.leftAxis
yAxis.enabled = true
yAxis.drawAxisLineEnabled = false
yAxis.drawLabelsEnabled = false
yAxis.gridColor = UIColor(rgba: "#414042")
yAxis.gridLineWidth = 1
yAxis.axisMaximum = 6000
chart.xAxis.enabled = true
chart.xAxis.drawGridLinesEnabled = false
chart.xAxis.drawLabelsEnabled = true
chart.xAxis.drawAxisLineEnabled = true
chart.xAxis.axisLineColor = .darkGray
chart.xAxis.axisLineWidth = 1
chart.xAxis.valueFormatter = IndexAxisValueFormatter(values: ["Jan", "Feb", "Mar", "April", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"])
chart.xAxis.labelPosition = .bottom
chart.xAxis.labelTextColor = .darkGray
chart.xAxis.labelFont = UIFont.sourceSansProLight(withSize: 15.5)
chart.xAxis.granularityEnabled = true
chart.xAxis.granularity = 1
chart.highlightPerTapEnabled = false
chart.backgroundColor = .clear
return chart
}()
And this is the code for adding random data points in the chart and the highlight.
var values: [ChartDataEntry] = []
var highlight: Highlight? = nil
for index in 0..<12 {
let randomValue = Double(arc4random_uniform(5000))
values.append(ChartDataEntry(x: Double(index), y: randomValue))
if index == 4 {
highlight = Highlight(x: Double(index), y: randomValue, dataSetIndex: 0)
}
}
let dataSet = LineChartDataSet(values: values, label: "")
dataSet.highlightEnabled = true
dataSet.drawHorizontalHighlightIndicatorEnabled = false
dataSet.highlightColor = UIColor(rgba: "#1899FF")
dataSet.highlightLineWidth = 1
dataSet.mode = .horizontalBezier
dataSet.circleColors = Array(repeating: UIColor(rgba: "#1899FF"), count: 12)
dataSet.fillColor = UIColor(rgba: "#1899FF")
dataSet.drawCircleHoleEnabled = false
dataSet.drawFilledEnabled = true
dataSet.lineWidth = 0.0
dataSet.drawValuesEnabled = true
dataSet.axisDependency = .left
dataSet.valueFormatter = self
let data = LineChartData(dataSet: dataSet)
data.setDrawValues(true)
data.setValueFont(UIFont.sourceSansProLight(withSize: 15.5))
data.setValueTextColor(UIColor(rgba: "#1899FF"))
lineChartView.data = data
lineChartView.highlightValue(highlight)