Aravind Bhuvanendran
Aravind Bhuvanendran

Reputation: 656

iOS Line Chart highlight color

I'm using charts 3.2.2 iOS version. I a trying to plot a line chart. In the line chart whenever user taps on the value points a highlight line would show up. Is there any way I can hide or change this highlight line color. Another issue I'm facing is the bubble won't show up for the first entry. I found a lot of solutions online but nothing works for me. Any help will be appreciated.

    scoreLineChart.legend.form = .none
    scoreLineChart.rightAxis.enabled = false

    scoreLineChart.xAxis.labelPosition = .bottom

    scoreLineChart.xAxis.drawGridLinesEnabled = false
    scoreLineChart.dragEnabled = false
    scoreLineChart.doubleTapToZoomEnabled = false

    scoreLineChart.xAxis.granularityEnabled = true
    scoreLineChart.xAxis.granularity = 1.0

    scoreLineChart.leftAxis.axisMinimum = 0
    scoreLineChart.leftAxis.axisMaximum = 100.0
    scoreLineChart.leftAxis.setLabelCount(5, force: true)

    scoreLineChart.xAxis.valueFormatter = valueFormatter
    scoreLineChart.xAxis.avoidFirstLastClippingEnabled = true
    scoreLineChart.pinchZoomEnabled = false
    let marker = BalloonMarker(color: UIColor(hex: "#58595b"),
                               font: UIFont(name: "Avenir-Heavy", size: 14)!,
                               textColor: .white,
                               insets: UIEdgeInsets(top: 8, left: 8, bottom: 20, right: 8))

    marker.chartView = scoreLineChart
    marker.minimumSize = CGSize(width: 80, height: 40)
    scoreLineChart.marker = marker

After adding data entries

 let setOne = LineChartDataSet(values: lineChartEntry, label: "") //Here we convert lineChartEntry to a LineChartDataSet

    setOne.mode = .cubicBezier
    setOne.drawValuesEnabled = true

    setOne.lineWidth = 1
    setOne.circleRadius = 3
    setOne.drawCircleHoleEnabled = false
    setOne.valueFont = .systemFont(ofSize: 9)
    setOne.formLineWidth = 1
    setOne.formSize = 15

    setOne.setCircleColor(ChartColorTemplates.colorFromString("#ffcc1a29"))

    if !isSingelValue {
        setOne.setColor(ChartColorTemplates.colorFromString("#ffcc1a29"))
    }else {
        setOne.setColor(UIColor.clear)
    }

    let data = LineChartData(dataSet: setOne)

    data.addDataSet(setOne) //Adds the line to the dataSet
    scoreLineChart.xAxis.axisMinimum = 0
    scoreLineChart.data = data //finally - it adds the chart data to the chart and causes an update
    //        scoreLineChart.data?.setValueFormatter(valueFormatter)
    scoreLineChart.chartDescription?.text = "" // Here we set the description for the graph
    scoreLineChart.notifyDataSetChanged()

Upvotes: 2

Views: 3618

Answers (2)

paky
paky

Reputation: 685

Is there any way I can hide or change this highlight line color.

To show/hide or change the highlight line color, edit the properties of your ChartDateSet

let setOne = LineChartDataSet(values: lineChartEntry, label: "")
setOne.highlightColor = .red // color of the line
setOne.highlightWidht = 2.0 // width of the line
setOne.drawHorizontalHighlightIndicatorEnabled = false // hide horizontal line
setOne.drawVerticalHighlightIndicatorEnabled = false // hide vertical line

Another issue I'm facing is the bubble won't show up for the first entry.

And sadly I cannot reproduce this issue with the BallonMarker.swift from Charts github repository. And It is not clear which one is the first entry of your data from the image you provided.

I tried add a "first entry" to my chart but the BallonMarker works prefectly.

enter image description here

Upvotes: 1

Jack
Jack

Reputation: 14329

You just need to set drawHorizontalHighlightIndicatorEnabled drawVerticalHighlightIndicatorEnabled to false to hide grid lines.

    let set1 = ScatterChartDataSet(entries: values1, label: "DS 1")
    set1.drawHorizontalHighlightIndicatorEnabled = false
    set1.drawVerticalHighlightIndicatorEnabled = false

Upvotes: 4

Related Questions