Ivan Kozlov
Ivan Kozlov

Reputation: 561

iOS chart library

I need to implement line chart with 2 colours like this:

So positive values should be blue and negative red and this is very important. Could u suggest iOS library to do this? I've already seen Charts, PNChart but they can't draw 2 coloured lines.

Thanks for any help!

Upvotes: 1

Views: 407

Answers (2)

Karsten
Karsten

Reputation: 1907

That isnt a problem, when zu seperate each colored part in a own dataset and append it to the datasets arrays of the charts. This results in 4 blue and 4 red datasets which you must add in an array and set it to the chart data.

some example from my project

var dataSets = [LineChartDataSet]()
// create different datasets
let dataSet = createDataSet(with: entries)
dataSets.append(dataSet)

Result with example values: enter image description here

Upvotes: 0

daniel.gindi
daniel.gindi

Reputation: 3496

If you were to subclass the LineChartRenderer in Charts, you would be able to use a mask on the bottom half of the screen when rendering the lines.

Basically create a new transparent CGContext, call super to draw the lines on it, mask it with CoreGraphics, then copy it on the original CGContext.

Upvotes: 1

Related Questions