Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to add more than 3 lines in chart #1314

Closed
rajeshm20 opened this issue Aug 11, 2016 · 14 comments
Closed

How to add more than 3 lines in chart #1314

rajeshm20 opened this issue Aug 11, 2016 · 14 comments

Comments

@rajeshm20
Copy link

how to add more than 3 lines in chart
screen shot 2016-08-11 at 6 23 03 pm

@pmairoldi
Copy link
Collaborator

Add a forth dataset.

@rajeshm20
Copy link
Author

I have but...Chart doesn't show the 4th line..but only legend only showing up
screen shot 2016-08-11 at 6 50 00 pm

@rajeshm20
Copy link
Author

is there any limit for number lines in Chart?

@pmairoldi
Copy link
Collaborator

Shouldn't be. What is the dataset for triglycerides?

@rajeshm20
Copy link
Author

tcTriGlyc: ["150", "170", "166", "180", "230"]
tcCholstrl: ["195", "178", "189", "170", "188"]

@rajeshm20
Copy link
Author

TriGlycerides: ["150", "170", "166", "180", "230"]
Cholesterol: ["195", "178", "189", "170", "188"]

@pmairoldi
Copy link
Collaborator

I would assume that you correctly created the data set but have not added the values correctly. I can't know without seeing the code.

@rajeshm20
Copy link
Author

` @IBOutlet var lineChartView: LineChartView!

var showDates:[String] = []
var showLdl:[String] = []
var showHdl:[String] = []
var showTriglyc:[String] = []
var showCholestrl:[String] = []

func fetchBP() {

    showDates = sharedInstance.getTCUptdDate()
    showLdl = sharedInstance.getTCLdl()
    showHdl = sharedInstance.getTCHdl()
    showTriglyc = sharedInstance.getTCTriGlyc()
    showCholestrl = sharedInstance.getTCCholestrol()
}

override func viewDidLoad() {
    super.viewDidLoad()


    fetchBP()


    let dates = showDates
    let ldl = showLdl.flatMap{Double($0)}
    let hdl = showHdl.flatMap{Double($0)}
    let triGlyc = showTriglyc.flatMap{Double($0)}
    let Cholestrl = showCholestrl.flatMap{Double($0)}


    lineChartView.legend.font = NSUIFont.italicSystemFontOfSize(12)


    var dataEntries: [ChartDataEntry] = []

    for i in 0..<dates.count {
        let dataEntry = ChartDataEntry(value: ldl[i], xIndex: i)
        dataEntries.append(dataEntry)
    }


    let lineChartDataSet = LineChartDataSet(yVals: dataEntries, label: "LDL")


    var dataEntries2: [ChartDataEntry] = []

    for i in 0..<dates.count {
        let dataEntry = ChartDataEntry(value: hdl[i], xIndex: i)
        dataEntries2.append(dataEntry)
    }


    let lineChartDataSet2 = LineChartDataSet(yVals: dataEntries2, label: "HDL")


    var dataEntries3: [ChartDataEntry] = []

    for i in 0..<dates.count {
        let dataEntry = ChartDataEntry(value: triGlyc[i], xIndex: i)
        dataEntries3.append(dataEntry)
    }


    let lineChartDataSet3 = LineChartDataSet(yVals: dataEntries3, label: "TriGlycerides")


    var dataEntries4: [ChartDataEntry] = []

    for i in 0..<dates.count {
        let dataEntry = ChartDataEntry(value: Cholestrl[i], xIndex: i)
        dataEntries4.append(dataEntry)
    }


    let lineChartDataSet4 = LineChartDataSet(yVals: dataEntries3, label: "Cholestrol")




    let lineChartData = LineChartData(xVals: dates, dataSets: [lineChartDataSet, lineChartDataSet2, lineChartDataSet3, lineChartDataSet4])

    lineChartView.data = lineChartData
    lineChartData.setValueFont(NSUIFont.boldSystemFontOfSize(9))

    lineChartView.animate(xAxisDuration: 2.0)

// lineChartView.animate(yAxisDuration: 2.5)

    lineChartDataSet.setCircleColor(UIColor.init(red: 255/255, green: 69/255, blue: 0/255, alpha: 1))

    lineChartDataSet.setColor(UIColor.init(red: 255/255, green: 69/255, blue: 0/255, alpha: 1))

    lineChartDataSet2.setCircleColor(UIColor.init(red: 255/255, green: 140/255, blue: 0/255, alpha: 1))

    lineChartDataSet2.setColor(UIColor.init(red: 255/255, green: 140/255, blue: 0/255, alpha: 1))

    lineChartDataSet3.setCircleColor(UIColor.init(red: 139/255, green: 0/255, blue: 139/255, alpha: 1))

    lineChartDataSet3.setColor(UIColor.init(red: 139/255, green: 0/255, blue: 139/255, alpha: 1))

    lineChartDataSet4.setCircleColor(UIColor.init(red: 123/255, green: 104/255, blue: 238/255, alpha: 1))

    lineChartDataSet4.setColor(UIColor.init(red: 123/255, green: 104/255, blue: 238/255, alpha: 1))

}

`

@danielgindi
Copy link
Collaborator

You have set entries3 to dataSet4

@rajeshm20
Copy link
Author

Oh...my...Thanks a lot Daniel...my carelessness...

@rajeshm20
Copy link
Author

It's working now....How is your daughter?...God Bless..
screen shot 2016-08-11 at 7 08 53 pm

@rajeshm20
Copy link
Author

Thanks @petester42 , @danielgindi !

@pmairoldi
Copy link
Collaborator

🎉

@danielgindi
Copy link
Collaborator

@rajeshm20 she is amazing and makes us happier every day, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants