3

enter image description herehello I want to create line chart similar to healthkit. For example i have on X axis (Jul 14, 15, 16, 17), Y axis (0, 50, 100) and data set in (x,y) format is ((jul 15, 30),(jul 17, 80)) I try following libraries

https://github.com/Boris-Em/BEMSimpleLineGraph/tree/master/Sample%20Project/SimpleLineChart

https://github.com/core-plot/core-plot

but all populate x axis based on data set. i.e all library only take parameter for data set based on that x axis and y axis labels are populated. Can you please suggest any other library through which I can achieve similar as explain above line chart. Thanks in advance.

Sam Spencer
  • 8,492
  • 12
  • 76
  • 133
Bhushan Vaidya
  • 722
  • 1
  • 6
  • 17

3 Answers3

4

Finally i solved my problem using https://github.com/Boris-Em/BEMSimpleLineGraph/tree/master/Sample%20Project/SimpleLineChart when there is no value i put (jul 15, BEMNullGraphValue).

Bhushan Vaidya
  • 722
  • 1
  • 6
  • 17
1

Even this you could do it in your existing graph

Consider below example. - {[0,5],[1,5],[3,5],[4,5]}

See there is no value for 2, so line chart will draw 0-5 to 1-5 then gap then 3-5 to 4-5.

I hope now you could figure out.

Still if you wish then get below graph library.

Do it with https://github.com/danielgindi/Charts

There are many properties like clip, scale, min, max etc for line chart.

Using though properties you could achieve.

https://github.com/danielgindi/Charts/issues/533

Edited answer

After doing some work around, i found the way.

Download sample code

let months = ["July 14", "15", "16", "17", "18", "19", "20"]
let unitsSold = [0.0, 0.0, 0.0, 100.0, 25.0, 50.0, 75.0]

for i in 0..<dataPoints.count {
    if !values[i].isZero {
        let dataEntry = ChartDataEntry(value: Double(values[i]), xIndex: i)
            dataEntries.append(dataEntry)
    }
}

Refer attached screen shot

enter image description here

Hasya
  • 9,792
  • 4
  • 31
  • 46
1

In PNChart create one array of indexes which you want to skip the value. Put condition drawdot funtion on start of for loop of data array if array contain index value then continue.