sukh sukh - 5 months ago 16
Swift Question

ResearchKit - How to remove background on line chart

Good morning all

I'm using ResearchKit default charts to display some steps recorded within HealthKit. This all works awesomely where I'm now at the stage of styling the charts.

One thing I'm unable to do is getting rid of the lighter background thats being applied to each range point. I've attached screenshot of the demo ORKCatalog charts - see Line Graph cell (ignore the grey line - I know how to get rid of that :) )

Code wise (which is probably not that useful) I have the following where stepsChart is my ORKLineGraphChartView...

stepsChart.dataSource = stepChartDataSource
stepsChart.tintColor = UIColor(red: 134/255, green: 74/255, blue: 244/255, alpha: 1)
stepsChart.showsHorizontalReferenceLines = false
stepsChart.showsVerticalReferenceLines = false
stepsChart.axisColor = UIColor.whiteColor()
stepsChart.verticalAxisTitleColor = UIColor.whiteColor()

Any additional info please shout and I'll do my best to improve question / info :)

enter image description here


Removing ORKLineGraphChartView's fill is not currently supported, but there's an ongoing pull request which will allow you to specify any color, including [UIColor clearColor].

You can either:

  1. Checkout the branch from that pull request
  2. Modify this line and specify a transparent color there

Given that you are importing ResearchKit through Cocoapods, then perhaps your best option is 2. (look for the file in your Pods/ResearchKit folder). If your project has several developers, make sure the Pods folder is committed to your repo so others get your change.

And be aware that when you update the ResearchKit pod, this modification will be lost. But with luck, the new PR will be in by then.